I wrote a code to design a lowpass filter and to filter an input signal with this filter; but Matlab gave an error. I could not understand my error. How can I correct this error?
Ältere Kommentare anzeigen
function [srf]=lowpass(sr,fcut)
Hf=fdesign.lowpass('n,fc',20, fcut);
Hd = design(Hf);
srf = conv(sr,Hd);
end
Antworten (1)
Wayne King
am 2 Dez. 2013
Bearbeitet: Wayne King
am 2 Dez. 2013
It's always best to show the error that you get: "MATLAB gave an error" is not helpful.
Assuming that sr is your signal, the problem is that conv() is not overloaded for dfilt objects.
You do not want to use conv() to filter your signal. You want to use filter()
Change this line:
srf = conv(sr,Hd)
to
srf = filter(Hd,sr);
Also, why not add the sampling frequency as an input to your function. You can then supply that as the final input to fdesign.lowpass() and design your filter in cycles/unit time.
For example:
function [srf]=lowpass(sr,fcut,Fs)
Hf=fdesign.lowpass('n,fc',20, fcut,Fs);
Hd = design(Hf);
srf = filter(Hd,sr);
end
Kategorien
Mehr zu Digital Filter Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!