How to use a Fir1 filter to make a lowpass filter
79 次查看(过去 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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Digital Filter Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!