这个问题是我不知道的更一般问题的一部分 - 如何在频域中应用滤波器,然后将滤波后的信号转换回时域?好吧,我用谷歌搜索了我需要的答案
- 在 FFT 中转换信号
- 乘以过滤器
- 转换回时域
但我不完全确定我是否将这个想法正确地应用于大气吸收过滤(见下文)。
我也不确定我是否可以完全在时域中进行过滤(如卷积所建议的那样?)以某种方式减轻来回切换到频率域的需要。
输入:声波(枪声声压减去大气压力)和大气条件。输出:用大气吸收滤波器衰减的相同声波。
我用来查找Engineering Acoustics/Outdoor Sound Propagationpython-acoustics中描述的大气衰减系数。
我想出了以下代码:
def atmosphericAttenuation(signal, distance, Fs, **kwargs):
"""
Apply atmospheric absorption to the `signal` for all its FFT frequencies.
It does not account for the geometrical attenuation.
Parameters
----------
signal - a pressure waveform (time domain)
distance - the travelled distance, m
Fs - sampling frequency of the `signal`, Hz
kwargs - passed to `Atmosphere` class
Returns
-------
signal_attenuated - attenuated signal in the original time domain
"""
# pip install acoustics
from acoustics.atmosphere import Atmosphere
atm = Atmosphere(**kwargs)
signal_rfft = np.fft.rfft(signal)
freq = np.fft.rfftfreq(n=len(signal), d=1. / Fs)
# compute the attenuation coefficient for each frequency
a_coef = atm.attenuation_coefficient(freq)
# (option 2) signal_rfft *= 10 ** (-a_coef * distance / 20)
signal_rfft *= np.exp(-a_coef * distance)
signal_attenuated = np.fft.irfft(signal_rfft)
return signal_attenuated
我做对了吗?哪一个是正确的:
signal_rfft *= np.exp(-a_coef * distance)<-signal_rfft *= 10 ** (-a_coef * distance / 20)<-
如果两者都不是,请描述应该如何做。谢谢你。