How to use a Fir1 filter to make a lowpass filter

46 次查看(过去 30 天)
Hi, I'm currently trying to make a lowpass filter for a sound clip with the specs of being order 128 and having a curoff frequency of 3575 Hz. Using the tf function does produce a graph, but that graph comes up as blank for any order greater than 70. People are recommending using a fir1, which, while it does produce a graph, though I'm unsure if these are correct given how I'm also getting the following error messages:
"Error using fir1>chkWindow (line 286)
Window length must be the same as the filter length.
Error in fir1>eFir1 (line 161)
wind = chkWindow(L,varargin{windIndex});
Error in fir1 (line 92)
[b,a] = eFir1(varargin{:});
Error in Lowpass (line 25)
blo = fir1(128,0.48,chebwin(35,30));"
My code is as follows:
audioread('beep.wav');
info = audioinfo('beep.wav')
filename = 'beep.wav';
audiowrite(filename,y,Fs);
[y,Fs] = audioread('beep.wav');
sound(y,Fs)
t = 0:seconds(1/Fs):seconds(info.Duration);
t = t(1:end-1);
figure(1)
plot(t,y)
xlabel('Time')
ylabel('Audio Signal')
title 'Beep Signal'
filename = 'Beep.wav';
audiowrite(filename,y,Fs);
t = (0:length(y)-1)/Fs;
bhi = fir1(34,0.48,'low',chebwin(35,30));
freqz(bhi,1)
blo = fir1(128,0.48,chebwin(35,30));
outlo = filter(blo,1,y);
subplot(2,1,1)
plot(t,y)
title('Original Signal')
ys = ylim;
subplot(2,1,2)
plot(t,outlo)
title('Lowpass Filtered Signal')
xlabel('Time (s)')
ylim(ys)
Any help explaining what is going wrong with this code would be appreciated

采纳的回答

Star Strider
Star Strider 2022-10-10
The filter specification needs to be:
blo = fir1(128,0.48,chebwin(129,30));
because of the filter length.. That will work.
Note that this is correct:
bhi = fir1(34,0.48,'low',chebwin(35,30));
They should both create essentially the same filter, although with different properties since the lengths are different.
(The ‘beep.wav’ file apparently does not exist on the server, or in my offline MATLAB installation, so I cannot run the code.)
.
  2 个评论
Anthony Koning
Anthony Koning 2022-10-10
This sis allow the graph to work, thanks for that. But just out of curiosity, shouldn't a passed audio clip filter look less like this:
and more like this:
Star Strider
Star Strider 2022-10-10
No, it should not.
However if you take the Fourier transform (fft) of the filtered audio clip and divide it element-wise by the Fourier transform of the original, unfiltered audio clip, and the plot the one-sided result of that operation (from 0 Hz to the Nyquist frequency), it should resemble the transfer function in the freqz plot.
The ‘Lowpass Filtered Signal’ plot is in the time domain, and the freqz plot is in the frequency domain.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Digital Filter Design 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by