How can I plot the magnitude spectrum for these three filters?

3 次查看(过去 30 天)
%Low-pass Filter
B_lp = designfilt('lowpassfir', 'FilterOrder', 64, 'CutoffFrequency', 3e3, 'SampleRate', fs);
[b, a] = tf(B_lp);
x_lp = filter(B_lp, x);
%band-pass Filter
B_bp = designfilt('bandpassfir', 'FilterOrder', 64, 'CutoffFrequency1', 2000,'CutoffFrequency2', 5000, 'SampleRate', fs);
[b, a] = tf(B_bp);
x_bp = filter(B_bp, x);
%Low-pass Filter
B_hp = designfilt('highpassfir', 'FilterOrder', 64, 'CutoffFrequency', 4e3, 'SampleRate', fs);
[b, a] = tf(B_hp);
x_hp = filter(B_hp, x);

回答(1 个)

Ganesh
Ganesh 2024-6-12
Hi Faisal,
To plot the magnitude spectrum for the low-pass, band-pass, and high-pass filters you've designed, you can use MATLAB's "freqz" function, which computes and plots the frequency response of a filter. You may use the following documentation to learn more on the "freqz" function:
The freqz function is used without specifying the number of points to use for the frequency response, which means the default setting is used for a detailed plot. The "fs" parameter is provided to scale the frequency axis according to your sampling frequency, allowing you to view the frequency response in Hz.
Note that this approach visualizes the filter characteristics themselves, not the spectrum of the filtered signal. If you're interested in the spectrum of the filtered signal (x_lp, x_bp, x_hp), you would need to use a different method, like performing a Fast Fourier Transform (FFT) on the filtered signals.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by