来自滤波器和分析工具箱的FIR的零相位滤波

时间:2019-03-24 12:23:13

标签: matlab filter

如何在matlab过滤器分析工具箱创建的以下过滤器中使用filtfilt函数。我的matlab是2012年。 下面是语法,但是我不知道括号内的变量y = filtfilt(b,a,x)y = filtfilt(sos,g,x)y = filtfilt(d,x)

% MATLAB Code
% Generated by MATLAB(R) 8.2 and the Signal Processing Toolbox 6.20.
% Generated on: 18-Mar-2019 12:11:31
% Equiripple Lowpass filter designed using the FIRPM function.
% All frequency values are in Hz.
data = xlsread('Smoothendata2.xlsx',1);% read csv content
d1 = data(:,1);                                                    % Original Time Vector
d2 = data(:,2);                                                    % Original Data Vector
L = length(d1);
tv = linspace(min(d1), max(d1), L);                             % Time Vector For Interpolation
dv = interp1(d1, d2, tv, 'linear');                             % Interpolated Data Vector
Ts = mean(diff(tv));                                            % Sampling Time Interval
t_stats = [Ts  std(tv)];
Fs = 1/Ts;                                                      % Sampling Frequency
Fn = Fs/2;                                                      % Nyquist Frequency
FTD = fft(dv)/L;                                                % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn;                             % Frequency Vector
Iv = 1:length(Fv);                                              % Index Vector
figure(1)
semilogy(Fv, abs(FTD(Iv))*2)                                    % Plot Fourier Transform
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
% 
Fpass = 50;             % Passband Frequency
Fstop = 60;             % Stopband Frequency
Dpass = 0.17099735734;  % Passband Ripple
Dstop = 1;              % Stopband Attenuation
dens  = 20;             % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs/2), [1 0], [Dpass, Dstop]);
% Calculate the coefficients using the FIRPM function.
b  = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);

1 个答案:

答案 0 :(得分:0)

filtfilt命令不仅适用于FIR,而且适用于IIR滤波器。 由于FIR没有反馈,因此与IIR滤波器相反,它仅取决于b定义的前馈滤波器系数。 (反馈系数由a表示)

您有兴趣将其应用于FIR滤波器时,可以设置a=1;

所以您的问题的答案是:

b  = firpm(N, Fo, Ao, W, {dens});
a=1;    
y = filtfilt(b,a,x)