lowpass() not working

20 Ansichten (letzte 30 Tage)
J B
J B am 31 Jul. 2020
Kommentiert: Star Strider am 22 Aug. 2023
The title says it all. I have the following code:
Tend = 10e-3;
dt = 100e-9;
t = 0:dt:Tend-dt;
fsig = 500;
sig = 100*sin(2*pi*fsig*t) + 20*sin(2*pi*fsig*100*t);
[sig_filt filter] = lowpass(sig, 1000, 1/dt);
When I plot the signals sig and sig_filt the two curves are almost the same. I tried to reduce the corner frequency from 1000 as above to 10 to 1, it's always the same result. Doint an fft of the signals shows, that the filter only cuts away frequencies above ca. 500 kHz. Using
fvtool(filter)
gives my the same transfer function for the filter, independent of the corner frequency I chose.
This is a bug right? Or do I overlook something? I'm using matlab 2018b.

Antworten (1)

Star Strider
Star Strider am 6 Aug. 2020
Bearbeitet: Star Strider am 6 Aug. 2020
A low passband with a very high sampling frequency is asking a lot of any filter. I am somewhat surprised that lowpass used a FIR design in that instance, when a IIR design is more appropriate. (I could not get a FIR filter to work with those constraints, either.)
This one works:
Tend = 10e-3;
dt = 100e-9;
t = 0:dt:Tend-dt;
fsig = 500;
sig = 100*sin(2*pi*fsig*t) + 20*sin(2*pi*fsig*100*t);
% [sig_filt filter] = lowpass(sig, 1000, 1/dt);
Fs = 1/dt;
Fn = Fs/2;
Wp = 950/Fn;
Ws = 1050/Fn;
Rp = 1;
Rs = 60;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs);
[z,p,k] = ellip(n,Rp,Rs,Wp,'low');
[sos,g] = zp2sos(z,p,k);
sig_filt = filtfilt(sos,g,sig);
[h,f] = freqz(sos, 2^16, 1/dt);
Fs = 1/dt;
Fn = Fs/2;
L = numel(sig);
FTsig = fft(sig)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
loglog(Fv, abs(FTsig(Iv))*2)
hold on
plot(f, abs(h), 'LineWidth',1.5)
hold off
xlim([0 5E+6])
grid
legend('Signal','Filter Characteristic', 'Location','S')
EDIT — (6 Aug 2020 at 13:35)
Consider forcing an IIR design:
[sig_filt filter] = lowpass(sig, 1000, 1/dt, 'ImpulseResponse','iir');
When I tried this, I got much better results than with the default FIR design.
.
  2 Kommentare
PRABHAT PRADHAN
PRABHAT PRADHAN am 22 Aug. 2023
Thanks Star Strider. Nice, I also getting some error with default "lowpass()" filter with high sampling frequency, but that is resolved by using 'iir' Impulse response.
Star Strider
Star Strider am 22 Aug. 2023
My pleasure!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Digital and Analog Filters finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by