How can I plot the magnitude spectrum for these three filters?
9 views (last 30 days)
Show older comments
%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);
0 Comments
Answers (1)
Ganesh
on 12 Jun 2024
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.
0 Comments
See Also
Categories
Find more on Digital Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!