MCPcopy Create free account
hub / github.com/PyTTaMaster/PyTTa / crop_IR

Function crop_IR

pytta/classes/analysis.py:1678–1716  ·  view source on GitHub ↗

Cut the impulse response at background noise level.

(SigObj, IREndManualCut)

Source from the content-addressed store, hash-verified

1676
1677
1678def crop_IR(SigObj, IREndManualCut):
1679 """Cut the impulse response at background noise level."""
1680 timeSignal = cp.copy(SigObj.timeSignal)
1681 timeVector = SigObj.timeVector
1682 samplingRate = SigObj.samplingRate
1683 numSamples = SigObj.numSamples
1684 # numChannels = SigObj.numChannels
1685 if SigObj.numChannels > 1:
1686 print('crop_IR: The provided impulsive response has more than one ' +
1687 'channel. Cropping based on channel 1.')
1688 numChannels = 1
1689 # Cut the end automatically or manual
1690 if IREndManualCut is None:
1691 winTimeLength = 0.1 # [s]
1692 meanSize = 5 # [blocks]
1693 dBtoReplica = 6 # [dB]
1694 blockSamples = int(winTimeLength * samplingRate)
1695 timeWinData, timeVecWin = _level_profile(timeSignal, samplingRate,
1696 numSamples, numChannels,
1697 blockSamples)
1698 endTimeCut = timeVector[-1]
1699 for blockIdx, blockAmplitude in enumerate(timeWinData):
1700 if blockIdx >= meanSize:
1701 anteriorMean = 10*np.log10( \
1702 np.sum(timeWinData[blockIdx-meanSize:blockIdx])/meanSize)
1703 if 10*np.log10(blockAmplitude) > anteriorMean+dBtoReplica:
1704 endTimeCut = timeVecWin[blockIdx-meanSize//2]
1705 break
1706 else:
1707 endTimeCut = IREndManualCut
1708 endTimeCutIdx = np.where(timeVector >= endTimeCut)[0][0]
1709 timeSignal = timeSignal[:endTimeCutIdx]
1710 # Cut the start automatically
1711 timeSignal, _ = _circular_time_shift(timeSignal)
1712 result = SignalObj(timeSignal,
1713 'time',
1714 samplingRate,
1715 signalType='energy')
1716 return result

Callers 2

analyseFunction · 0.90
__init__Method · 0.85

Calls 3

SignalObjClass · 0.90
_level_profileFunction · 0.85
_circular_time_shiftFunction · 0.85

Tested by

no test coverage detected