How to create low pass filter for audio file?

조회 수: 8 (최근 30일)
Daemian
Daemian 2015년 2월 24일
답변: Tengsim Momin 2016년 3월 28일
How do i create a low pass filter for an audio file?
I would like to keep 20 Hz and below Sampling rate 8000 Hz
Thanks

채택된 답변

Star Strider
Star Strider 2015년 2월 24일
You gave enough information for the Signal Processing Toolbox (with a bit of help from me) to be able to design your filter:
Fs = 8000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
Fco = 20; % Passband (Cutoff) Frequency
Fsb = 30; % 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); % Second-Order-Section For STability
figure(1)
freqz(sos, 2048, Fs) % Check Filter Performance
Then use the filtfilt function to filter your signal.
I chose a Butterworth design, but if you want a steeper cutoff, consider using a Chebychev design instead. You may want to experiment with the design to get the exact result you want with respect to your signal. See the relevant documentation for details.
  댓글 수: 4
Daemian
Daemian 2015년 2월 24일
Hi, after i filter if i want to convert it to ftt, do i do it this way?
Fs = 8000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
Fco = 20; % Passband (Cutoff) Frequency
Fsb = 30; % 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); % Second-Order-Section For STability
%figure(1) %freqz(sos, 2048, Fs) % Check Filter Performance yd = filtfilt(sos, g, myRecording); % Filter ‘xd’ To Get ‘y’
yd_len = length(yd); % Length Of ‘wav’ File Data
Ts = 1/Fs; % Sampling Time
Tv = linspace(0, yd_len-1, yd_len)*Ts; % Time Vector
y_fft = abs(fft(yd)); %Retain Magnitude
Nsamps = length(yd);
y_fft = y_fft(1:Nsamps/2); %Discard Half of Points
f = Fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot
plot(handles.normalfft,f, y_fft)
xlim(handles.normalfft,[8 12])
Star Strider
Star Strider 2015년 2월 24일
I’m not certain what you’re doing. The usual procedure is to divide the output of the fft function by the length of the vector to normalise the amplitudes. I also don’t understand your frequency vector ‘f’ calculation (it doesn’t look correct to me), but if it works for you, go for it!
I follow the amplitude and frequency vector calculations in the documentation for the fft function, rather than creating my own calculations. It’s easier, and it works. I suggest you do that.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tengsim Momin
Tengsim Momin 2016년 3월 28일
how to filter eeg signal with(0.1db-80db) low pass filter using fdatool

카테고리

Help CenterFile Exchange에서 Fixed-Point Filters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by