Why am I getting different frequency responses for the same filter using bode() and fvtool()?
Show older comments
Hello,
I am trying to design a low pass filter with a cutoff frequency of 100 Hz.
I have been given freedom to assume all other parameters accordingly.
Here is my code:
fs = 500; % Sampling frequency
Ts = 1/fs;
fc = 100; % Cutoff frequency
t = 0:(1/fs):0.5;
input = sin(2*pi*50*t) + sin(2*pi*150*t);
noise = randn(size(t));
noisy_input = input + noise;
% Original signal plot and spectrum
p1 = pspectrum(noisy_input, 'power');
N1 = length(p1);
frequencies1 = (0:N1-1)*(fs/N1);
plot((frequencies1/2), p1);
title('Power Spectrum of Original Signal');
xlabel('Frequency (Hz)');
ylabel('Power');
plot(t, noisy_input);
title('Original Signal');
xlabel('Time');
ylabel('Magnitude');
% Designing IIR filter
lpf_iir = designfilt('lowpassiir', 'FilterOrder', 10, 'stopbandFrequency', fc, 'SampleRate', fs, 'StopbandAttenuation', 80);
% Applying filter on noisy input
y5_filtered_iir = filter(lpf_iir, noisy_input);
% Plotting the filtered signal (IIR)
p3 = pspectrum(y5_filtered_iir, 'power');
N3 = length(p3);
frequencies3 = (0:N3-1)*(fs/N3);
plot((frequencies3/2), p3);
title('Power Spectrum of Filtered Signal using IIR Filter');
xlabel('Frequency (Hz)');
ylabel('Power');
plot(t, y5_filtered_iir);
title('Filtered Signal using IIR Filter');
xlabel('Time');
ylabel('Magnitude');
% Bode Plot of the IIR Filter
[num, den] = tf(lpf_iir);
figure;
bode(num, den);
fvtool(lpf_iir);
title('Bode Plot of IIR Filter');
Here is the freq plot using bode():

And here is the freq plot using fvtool():

Now, I do understand that fvtool is used only for digital filters. However I do not know:
- Why does the frequency using the bode() command drop at 1 rad/sec (ie., 6.28 Hz) while my cutoff frequency is 100 Hz?
- Why are frequency plots itself, both different?
- Why is there a spike after 1 rad/sec in the first plot and multiple spikes after 100 Hz in the second plot?
Please tell me if I'm doing or understanding something wrong?
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with DSP System Toolbox 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!



