Filter Object Not Filtering Data?
Mostrar comentarios más antiguos
I have been trying to low pass filter some data without any luck. Everytime i run the data through my filter object, I get a 1:1 output regardless of whether I am well above the cutoff frequency or not! I don't care exactly how it is done (I can make the filter using FIR, IIR, etc). I found the fdatool GUI and it outputs m-file code for various filter types, I can see the Bode plot, so I know it is correct (see filter (2) below)... I also tried a much simpler method using fdesign.lowpass (see filter (1) below)...
When I plot the sine wave, it comes out at the right frequency (10kHz) and with a magnitude of '1'. When I plot the filtered sine wave "y", it also comes out at 10kHz with a magnitude of '1'. There is no phase shift or magnitude difference at all. I have tried really large frequencies and really small frequencies to make sure I wasn't having issues with 'normalized filters' or anything like that... Please Help!!!
Here are different filters I have tried (1):
d=fdesign.lowpass('N,Fc',10,1000,100000); %Designs a low pass filter specification "d" with "Order, Frequency, Sampling Rate"
designmethods(d) %Returns the available filter methods for the designed filter (Window, Hamming, Hanning...)
Hd = design(d); %Uses the default design method returned from designmethods -- "Hd" is your filter object
fvtool(Hd);
Here are different filters I have tried (2):
%From the FDATool Filter Design For Butterworth
Fs = 48000; % Sampling Frequency
Fpass = 1000; % Passband Frequency
Fstop = 4000; % Stopband Frequency
Apass = 1; % Passband Ripple (dB)
Astop = 20; % Stopband Attenuation (dB)
%Calculate the order from the parameters using BUTTORD.
[N,Fc] = buttord(Fpass/(Fs/2), Fstop/(Fs/2), Apass, Astop);
%Calculate the zpk values using the BUTTER function.
[z,p,k] = butter(N, Fc);
%To avoid round-off errors, do not use the transfer function. Instead get the zpk representation and convert it to second-order sections.
[sos_var,g] = zp2sos(z, p, k);
Hd = dfilt.df2sos(sos_var, g);
fvtool(Hd);
Here is how i am applying the filter:
% generate a sine wave
frequencysine = 10000;
x = 0 : 1/frequencysine*10/1000000 : 1/frequencysine*10;
figure(2)
sine=sin(frequencysine*2*pi*x);
plot(x,sine)
figure(3)
y = filter(Hd,sine);
plot(x,y)
1 comentario
Stephen
el 26 de Jun. de 2012
Weird, I get the same thing when I try it. Don't know what is wrong though. HD looks fine so maybe it's in how you implement it.
Respuestas (1)
Wayne King
el 26 de Jun. de 2012
You are not designing a filter with the same sampling frequency as your input signal. The sampling rate of your sine wave is 1 gigahertz, but you design your filter for data sampled at 100,000 Hz. That is the problem
d = fdesign.lowpass('N,F3dB',10,1000,1e9);
Hd = design(d,'butter');
y = filter(Hd,sine);
2 comentarios
Jeff Alves
el 26 de Jun. de 2012
Wayne King
el 26 de Jun. de 2012
Did you try the example I gave you? it removes the 10,000 Hz component. You should design the filter with the sample frequency of the data.
Categorías
Más información sobre Filter Design en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!