Why is there an offset in my butterworth and cheby filters when they have the same values?

6 views (last 30 days)
Below are the plots and the code for my filters. My assignment is to compare making a bandstop filter with a cheby filter and a butterworth filter, and i know the differences to expect and i don't think one of them is an offset in the x-axis, so what is happening?
clc, clear, close all;
Wn = [2000 2500];
[b,a] = butter(4,Wn,'stop','s');
h = freqs(b,a) ;
Wn = [2000 2500];
[d,e] = cheby1(4,3,Wn,'stop','s');
c = freqs(d,e) ;
mag = mag2db(abs(h));
phase1 = angle(h);
phasedeg1 = phase1*180/pi
subplot(2,1,1), semilogx(mag), grid on
xlabel 'Frequency (rad/s)', ylabel Magnitude
hold on
subplot(2,1,2), semilogx(phasedeg1), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'
hold on
bag = mag2db(abs(c))
phase2 = angle(c)
phasedeg2 = phase2*180/pi
subplot(2,1,1), semilogx(bag), grid on
xlabel 'Frequency (rad/s)', ylabel Magnitude
hold on
subplot(2,1,2), semilogx(phasedeg2), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'

Answers (1)

Star Strider
Star Strider on 20 May 2020
There is not really much difference. It is necessary to get the matching frequency vector (‘wh’ and ‘wc’ here) from the freqs function, then plot the magnitudes and phases as functions of them, respectively:
Wn = [2000 2500];
[b,a] = butter(4,Wn,'stop','s');
[h,wh] = freqs(b,a) ;
Wn = [2000 2500];
[d,e] = cheby1(4,3,Wn,'stop','s');
[c,wc] = freqs(d,e) ;
mag = mag2db(abs(h));
phase1 = angle(h);
phasedeg1 = phase1*180/pi;
subplot(2,1,1), semilogx(wh,mag), grid on
xlabel 'Frequency (rad/s)', ylabel Magnitude
xlim([2000 3000])
hold on
subplot(2,1,2), semilogx(wh,phasedeg1), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'
xlim([2000 3000])
hold on
bag = mag2db(abs(c));
phase2 = angle(c);
phasedeg2 = phase2*180/pi;
subplot(2,1,1), semilogx(wc,bag), grid on
xlabel 'Frequency (rad/s)', ylabel Magnitude
hold on
subplot(2,1,2), semilogx(wc,phasedeg2), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'
xlim([2000 3000])
They results are quite close, considering that the filters themselves are much different.

Community Treasure Hunt

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

Start Hunting!