Manual implementation of filter function without using inbuilt filter function

25 次查看(过去 30 天)
Hello,
I read that the FIR filter is basically a convolution of impulse response of system with input signal.
Or simply it is multiplication of time shifted impulse response and input signal.
I want to implement the filter using the multiplication instead using the inbuilt filter fucntion.
Can somone please explain how the mutlitiplication of the filter coefficients and an input signal can produce the result same as using the filtfilt filter function as shown below
d = fdesign.lowpass('Fp,Fst,Ap,Ast',5,12,1,20,100);
Hd1 = design(d);
data1 = filtfilt(Hd1.Numerator,1,data1);
thanks.

回答(1 个)

Wayne King
Wayne King 2014-1-30
Hi Stefan, filtfilt() is not as simple as convolving the input signal with the filter impulse response.
filftilt() implements zero-phase filtering by convolving the data with the filter, reversing it and repeating the process.
In the Fourier domain this is equivalent to multiplying the Fourier transform of the data by the magnitude-squared Fourier transform of the filter.
So you can implement something close to filtfilt() like this:
Fs = 100;
t = 0:1/1/Fs:1-1/Fs;
x = cos(2*pi*2*t)+randn(size(t));
d = fdesign.lowpass('Fp,Fst,Ap,Ast',5,12,1,20,100);
Hd1 = design(d);
data1 = filtfilt(Hd1.Numerator,1,x);
%%now compare
filtdft = fft(Hd1.Numerator,100);
filtdft = abs(filtdft).^2;
xdft = fft(x);
ydft = xdft.*filtdft;
data2 = ifft(ydft,'symmetric');
plot(data1); hold on;
plot(data2,'r');
legend('filtfilt','Fourier domain filtering')

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by