Simple LowPass Filter and the explanation

Hi everyone, I just want to create a low pass filter with a cut-off frequency of 2.4 kHz and sampling frequency of 11 kHz.
Also, I do not really understand this part 'Fp,Fst,Ap,Ast'
This might be easy for most of you, but I am completely new to matlab, so thank you so much in advance.
p/s: is there a way to get the moving average/smoothing using matlab? note that I am quiet confused between the difference, if there is a way, can help me with that too?

 Accepted Answer

‘Also, I do not really understand this part 'Fp,Fst,Ap,Ast'’
You do not need to understand it. There are several ways to design filters in MATLAB.
I prefer designfilt (introduced in R2014a) to the older dfilt for more complex filters. For simpler filters, it is easy to design filters with individual function calls.
This works for your filter (the lowpass design is the default, so you do not need to specify it):
Fs = 1.1E+4; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = 2.40E+3/Fn; % Passband Frequencies (Normalized)
Ws = 2.41E+3/Fn; % Stopband Frequencies (Normalized)
Rp = 10; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[c,b,a] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(c,b,a); % Convert To Second-Order-Section For Stability
figure(1)
freqz(sosbp, 2^16, Fs) % Bode Plot Of Filter
The freqz call is not necessary for the code. It demonstrates how the filter works and that it does what you want it to.

4 Comments

Hi, thanks for replying and sorry for my later reply, had to send my laptop for repair for few days.
By the way, how do I pass my wav file into that filter? Is it y = filter (something?)
My pleasure.
You have my sympathies. My primary MATLAB Answers computer is getting a new fan. This is my backup laptop.
Use the filtfilt function to filter your signal.
your_signal_filtered = filtfilt(sosbp, gbp, your_original_signal);
The filtfilt function has a maximally-flat phase response, so there will be no phase distortion in the filtering process. For that reason, it is preferable to using filter.
Thanks, you are a kind person, that helps me lot in understanding matlab filter. Kudos to you!
My pleasure.
Thank you.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!