MATLAB Answers

Low Pass filter not working

94 ビュー (過去 30 日間)
Yipp Chun Munn
Yipp Chun Munn 2019 年 10 月 16 日
編集済み: Star Strider 2019 年 10 月 20 日
I audioread() a signal and tried to apply low-pass filtering but it does not seem to have any change at all. The signal is a recording of lung sound and I wish to filter out the noise component.
[y,Fs] = audioread('mysound.wav')
Fs = 44100; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
Fco = 70; % Passband (Cutoff) Frequency
Fsb = 100; % Stopband Frequency
Rp = 1; % Passband Ripple (dB)
Rs = 10; % Stopband Ripple (dB)
[n,Wn] = buttord(Fco/Fn, Fsb/Fn, Rp, Rs); % Filter Order & Wco
[b,a] = butter(n,Wn); % Lowpass Is Default Design
[sos,g] = tf2sos(b,a);
filt_sig = filtfilt(sos,g,y)
Neither the plot(), FFT() or soundsc() shows anything different. I've tried cheby filters as well. Am I doing anything wrong? Thanks for the help.
  2 件のコメント
Yipp Chun Munn
Yipp Chun Munn 2019 年 10 月 16 日
Capture2.PNG
Capture1.PNG
The frequency domain and Time domain. No matter what filter I apply, the Far right frequency components does'nt go away.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2019 年 10 月 16 日
Your stopband attenuation is likely not sufficient to produce any difference.
Try this instead:
Rs = 60; % Stopband Ripple (dB)
Increase ‘Rs’ (to increase the stopband attenuation) as necessary to get the result you want.
Also, always use freqz (or similar functions) to see what your filter is doing:
figure
freqz(sos, 2^14, Fs)
  7 件のコメント
Star Strider
Star Strider 2019 年 10 月 20 日
The last image you posted appears to show your filter working as it should. No filter will completely eliminate the frequencies outside the passband and stopband limits, however they will be significantly attenuated. That is what you want.
A better and more efficient filter solution would likely be an elliptic filter.
Prototype code for that would be:
Fs = 2250;
Fn = Fs/2;
Wp = [59 61]/Fn; % Stopband Frequency (Normalised)
Ws = [58 62]/Fn; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 90; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^18, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',[0 100]) % Frequency Axis Limits
set(subplot(2,1,2), 'XLim',[0 100]) % Frequency Axis Limits
% signal_filt = filtfilt(sos, g, signal); % Filter Signal
Make appropriate changes for your sampling frequency, filter passbands and stopbands, and signal. Elliptic filters can handle very narrow transition regions, so:
Wp = [850 900]/Fn; % Stopband Frequency (Normalised)
Ws = [800 950]/Fn; % Passband Frequency (Normalised)
will produce a stable filter, likely with better charactersitics.
EDIT —
Corrected typographical error.

サインインしてコメントする。

その他の回答 (1 件)

Daniel M
Daniel M 2019 年 10 月 16 日
編集済み: Daniel M 2019 年 10 月 16 日
You show a figure that essentially looks like the following (also attached):
fs = 1000;
t = 0:1/fs:10;
x = sin(2*pi*10*t);
X = fft(x);
figure
plot(abs(X))
This is completely normal. It is the two sided amplitude spectrum.
You should read more about fftshift, and follow the example for the single sided amplitude spectrum on page for fft.
"No matter what filter I apply, the Far right frequency components does'nt go away."
That's because they're not supposed to.

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by