Matrix convulsion in the x,y plane with intersections
1 次查看(过去 30 天)
显示 更早的评论
Hello all. I need help regarding the intersection point between a freqs plot and yline plotted on the same plot. How can I go about doing this? I'll leave a portion of the code below,
[b,a] = butter(8,[omegac1 omegac2],'bandpass','s');
figure; freqs(b,a) Gp=0.8881779763; yline(Gp,'Gp');
I need the intersection point (x,y) between yline(gp) and the freqs figure from above. I'd appreciate any help. Thanks in advance.
2 个评论
Star Strider
2021-10-29
@USER SEEF — Please do not eliminate the question, especially after someone has gone through the trouble of posting an Answer.
The question text had to do with determining the frequency at which a transfer function intersected a yline at 9.68. This is similar to Bode plot for Simulink presentation.
I will not delete my Answer.
回答(1 个)
Star Strider
2021-10-29
Again using the same example from the documentation —
a = [1 0.4 1];
b = [0.2 0.3 1];
w = logspace(-1,1.3);
h = freqs(b,a,w);
fp = 9.68;
hfp = freqs(b,a,[1;1]*fp)
mag = abs(h);
phase = angle(h);
phasedeg = phase*180/pi;
Gp=0.8881779763;
idx = find(diff(sign(mag-Gp))); % Approximate Indes
wint = interp1(mag([-1:1]+idx),w([-1:1]+idx), Gp) % Interpolated Frequency Value
magint = freqs(b,a,[1;1]*wint) % Interpolated MAgnitude Value
subplot(2,1,1)
loglog(w,mag)
hold on
plot(fp, abs(hfp(1)),'+r')
plot(wint,abs(magint(1)),'rs')
hold off
grid on
xlabel('Frequency (rad/s)')
ylabel('Magnitude')
yline(Gp,'-g','Gp');
text(wint,abs(magint(1)), sprintf(' \\leftarrow Intersection %.3f rad/s',wint), 'Horiz','left', 'Vert','middle', 'Rotation', -10)
subplot(2,1,2)
semilogx(w,phasedeg)
hold on
plot(fp, rad2deg(angle(hfp(1))),'+r')
plot(wint,rad2deg(angle(magint(1))),'rs')
hold off
grid on
xlabel('Frequency (rad/s)')
ylabel('Phase (degrees)')
text(wint,rad2deg(angle(magint(1))), sprintf(' \\leftarrow Intersection %.3f rad/s',wint), 'Horiz','left', 'Vert','middle', 'Rotation', 10)
Experiment to get different results.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!