strange behavior of plot and freqz

4 Ansichten (letzte 30 Tage)
Konstantinos
Konstantinos am 4 Nov. 2023
Kommentiert: Star Strider am 4 Nov. 2023
Hello,
Does anyone knows why the freqz and the plot function display diffrent things?Shouldnt be the same?
For example in the first case everything seems fine but in the second the phase doesnt look the same.
This is my code:
close all;
clear all;
w = -pi:pi/128:pi;
z=tf('z');
G=(0.2*z/(z+0.2))*(1/(z-0.9));
[num,den]=tfdata(G,'v');
figure(1);
freqz(num,den,w);
[h, freq] = freqz(num, den, w);
phase = angle(h);
figure(2);
plot(freq, phase);
clear all;
w = -pi:pi/128:pi;
z=tf('z');
G=(0.2*z/(z+0.2))*(1/(z-0.9))*(1/(z-1));
[num,den]=tfdata(G,'v');
figure(3);
freqz(num,den,w);
[h, freq] = freqz(num, den, w);
phase = angle(h);
figure(4);
plot(freq, phase);

Akzeptierte Antwort

Star Strider
Star Strider am 4 Nov. 2023
Thje angle functon returns angles in radians. If you add a call to the rad2deg function, the results will be in degrees, and the plots should look similar. It might also be necessary to use the unwrap function first.
w = -pi:pi/128:pi;
z=tf('z');
G=(0.2*z/(z+0.2))*(1/(z-0.9));
[num,den]=tfdata(G,'v');
[h, freq] = freqz(num, den, w);
phase = angle(h);
figure(2);
plot(freq, rad2deg(unwrap(phase)))
w = -pi:pi/128:pi;
z=tf('z');
G=(0.2*z/(z+0.2))*(1/(z-0.9))*(1/(z-1));
[num,den]=tfdata(G,'v');
[h, freq] = freqz(num, den, w);
phase = angle(h);
figure(4);
plot(freq, rad2deg(unwrap(phase)))
The aspect ratios are different because freqz produces subplot plots.
.
  2 Kommentare
Konstantinos
Konstantinos am 4 Nov. 2023
I didnt expect that it would change so much the form of the graph.Thanks a lot for the clarification and your solution!
Star Strider
Star Strider am 4 Nov. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by