Main Content

补偿 IIR 滤波器引入的延迟

对信号进行滤波会引入延迟。这意味着相对于输入,输出信号在时间上有所偏移。

无限冲激响应滤波器对某些频率分量的延迟可能比其他频率分量更长。它们会使输入信号呈现明显失真。函数 filtfilt 可补偿此类滤波器引入的延迟,从而校正滤波器失真。这种“零相位滤波”是对信号进行前向和后向滤波的结果。

以 500 Hz 的频率对心电图读数采样,采样时间为 1 秒。添加随机噪声。

Fs = 500;
N = 500;

rng("default")
xn = ecg(N) + 0.2*randn([1 N]);
tn = (0:N-1)/Fs;

使用滤波器阻挡 75 Hz 以上的频率,以消除一部分噪声。指定一个 7 阶 IIR 滤波器,通带波纹为 1 dB,阻带衰减为 60 dB。

Nf = 7;
Fp = 75;
Ap = 1;
As = 60;

d = designfilt("lowpassiir",FilterOrder=Nf, ...
    PassbandFrequency=Fp,PassbandRipple=Ap,StopbandAttenuation=As, ...
    SampleRate=Fs);

对信号进行滤波。滤波后的信号比原始信号干净,但相对于原始信号存在滞后。由于滤波器的非线性相位,它也存在失真。放大峰值附近的区域。

xfilter = filter(d,xn);

plot(tn,xn,tn,xfilter)

title("Electrocardiogram'")
xlabel("Time (s)")
legend(["Original Signal" "Filtered Signal"])
axis([0.25 0.55 -1 1.5])

Figure contains an axes object. The axes object with title Electrocardiogram', xlabel Time (s) contains 2 objects of type line. These objects represent Original Signal, Filtered Signal.

通过观察滤波器引入的群延迟,可以看出延迟与频率有关。

grpdelay(d,N,Fs)

Figure contains an axes object. The axes object with title Group Delay, xlabel Frequency (Hz), ylabel Group delay (samples) contains an object of type line.

使用 filtfilt 对信号进行滤波。延迟和失真已被有效消除。当使信号的相位信息保持原样至关重要时,请使用 filtfilt

xfiltfilt = filtfilt(d,xn);

plot(tn,xn,tn,xfilter)
hold on
plot(tn,xfiltfilt,LineWidth=2)
hold off

title("Electrocardiogram")
xlabel("Time (s)")
legend(["Original Signal" "Filtered Signal" ...
       "Zero-phase filtered with filtfilt"])
axis([0.25 0.55 -1 1.5])

Figure contains an axes object. The axes object with title Electrocardiogram, xlabel Time (s) contains 3 objects of type line. These objects represent Original Signal, Filtered Signal, Zero-phase filtered with filtfilt.

另请参阅

| | |

相关主题