temporal filter
时间: 2023-11-07 07:43:02 浏览: 133
A temporal filter is a type of filter that is used to process time-varying signals or data. It is a mathematical technique that smooths out the noise or fluctuations in a signal over time, allowing for better analysis of trends or patterns. Temporal filters can be used in a variety of applications, including image processing, audio processing, and signal analysis. They are commonly used in fields such as finance, neuroscience, and weather forecasting. Some common types of temporal filters include moving average filters, exponential filters, and Kalman filters.
相关问题
opts.addOptions() ("TemporalFilter", m_gopBasedTemporalFilterEnabled, false, "Enable GOP based temporal filter. Disabled per default") ("TemporalFilterPastRefs", m_gopBasedTemporalFilterPastRefs, TF_DEFAULT_REFS, "Number of past references for temporal prefilter") ("TemporalFilterFutureRefs", m_gopBasedTemporalFilterFutureRefs, TF_DEFAULT_REFS, "Number of future references for temporal prefilter") ("FirstValidFrame", m_firstValidFrame, 0, "First valid frame") ("LastValidFrame", m_lastValidFrame, MAX_INT, "Last valid frame") ("TemporalFilterStrengthFrame*", m_gopBasedTemporalFilterStrengths, std::map<int, double>(), "Strength for every * frame in GOP based temporal filter, where * is an integer." " E.g. --TemporalFilterStrengthFrame8 0.95 will enable GOP based temporal filter at every 8th frame with strength 0.95");
这段代码是用来设置一些选项的。其中包括:
- `TemporalFilter`:启用基于GOP的时域滤波器,默认禁用。
- `TemporalFilterPastRefs`:时域预过滤器使用的过去参考帧数量,默认为预设值。
- `TemporalFilterFutureRefs`:时域预过滤器使用的未来参考帧数量,默认为预设值。
- `FirstValidFrame`:第一个有效帧的索引,默认为0。
- `LastValidFrame`:最后一个有效帧的索引,默认为最大整数。
- `TemporalFilterStrengthFrame*`:每个GOP中某些帧的滤波强度。例如,`--TemporalFilterStrengthFrame8 0.95`将在每8帧中启用GOP基础的时域滤波器,并设置强度为0.95。
这些选项可以根据需要进行配置。
使用python编写一个提取wav音频的spectro-temporal modulation(STM)特征的程序,其中STM的过程为:原始音频信号、滤波器、求包络、二维傅里叶变换。其中滤波器使用ERB gammatone filterbank滤波器
首先需要安装一些必要的库:
```python
!pip install numpy scipy matplotlib soundfile
```
然后,我们可以编写代码来提取STM特征:
```python
import numpy as np
import scipy.signal as signal
import soundfile as sf
import matplotlib.pyplot as plt
# 载入音频文件
wav, sr = sf.read('example.wav')
# 定义一些参数
nfft = 512 # STFT的窗口大小
hop_size = 256 # STFT的步长
n_filters = 64 # 滤波器的数量
f_low = 80 # 滤波器组的最低频率
f_high = 8000 # 滤波器组的最高频率
# 计算ERB滤波器组的中心频率
erb_bands = np.linspace(0, 1, n_filters + 2)[1:-1]
erb_cfreqs = (f_high - f_low) * signal.gammatonefrequency(erb_bands) + f_low
# 计算ERB滤波器组
f_coef = signal.gammatonefir(erb_cfreqs, sr, 0.25, 1)
f_coef = f_coef[:, ::-1]
# 计算STFT
f, t, spec = signal.stft(wav, fs=sr, window='hann', nperseg=nfft, noverlap=nfft-hop_size, nfft=nfft)
# 对每个滤波器应用滤波器组
filtered_spec = np.zeros((n_filters, spec.shape[1]), dtype=np.complex)
for i in range(n_filters):
filtered_spec[i] = signal.fftconvolve(spec, f_coef[i, :], mode='same')
# 计算包络
env = np.abs(filtered_spec)
env = signal.savgol_filter(env, 51, 3, axis=1) # 平滑包络
# 计算2D傅里叶变换
stm = np.fft.fft2(env)
# 显示STM的频谱图
plt.imshow(np.abs(stm), origin='lower', aspect='auto', cmap='jet', extent=[t[0], t[-1], erb_cfreqs[0], erb_cfreqs[-1]])
plt.xlabel('Time (s)')
plt.ylabel('Frequency (Hz)')
plt.title('Spectro-temporal modulation (STM) feature')
plt.colorbar()
plt.show()
```
在此示例中,我们使用了一个示例音频文件`example.wav`,并使用ERB gammatone filterbank滤波器提取了STM特征。我们还使用STFT、包络和2D傅里叶变换来计算STM特征,并使用matplotlib库显示了它的频谱图。
阅读全文