How to put an audio file through a filter made through matlab

조회 수: 75 (최근 30일)
Anthony Koning
Anthony Koning 2022년 10월 12일
댓글: Mathieu NOE 2022년 10월 12일
Hi, I'm wondering how I can place a sound file through a filter that I made through Matlab. The code works, I'm just wondering how to inject the audio file through the filter itself. I believe it should be some application of the fir1 command, though I'm not sure how to impliment it fully. The code is as follows:
Fl = 300
Fh = 3400
Samples = 44100
Wc = [Fl Fh]./Samples
bbp = fir1(256, Wc, 'band');
figure(1)
plot (1:length(bbp), bbp)
figure(2)
freqz(bbp,1)
outbp = filter(bbp,1,y);
audioread('song.wav');
info = audioinfo('song.wav')
filename = 'song.wav';
[y,Fs] = audioread('song.wav');
audiowrite(filename,y,Fs);
sound(y,Fs)
And I am looking to filter song.wav with the bandpass filter I made, rather than the default fir1 command one. Thanks for the help

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 10월 12일
편집: Mathieu NOE 2022년 10월 12일
hello
some corrections needed, but you were pretty close to the solution
[y,Fs] = audioread('song.wav');
Fl = 300;
Fh = 3400;
Wc = [Fl Fh]./Fs;
bbp = fir1(256, Wc, 'band');
figure(1)
plot (1:length(bbp), bbp)
figure(2)
freqz(bbp,1)
outbp = filter(bbp,1,y);
audiowrite('song_filtered.wav',outbp,Fs);
sound(outbp,Fs)
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2022년 10월 12일
ooops , I made one mistake ...
the filter cut off frequencies are normalized vs Nyquist frequency which is half of sampling rate Fs
so change that line
Wc = [Fl Fh]./Fs;
into
Wc = [Fl Fh].*(2/Fs);
also it's good practice to pass Fs argument to freqz function, to avoid such mistakes !
freqz(bbp,1,300,Fs)
all the best

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by