find x or y at given point for f_cutoff, 0.1*f_cutoff and 10*f_cutoff

3 views (last 30 days)
% %Need to replace so it looks the same but with calculation of x at given y= -3.02 in magnitude plot
% and y at -45.01 deg, -84.28 deg, -5,7 deg
% cut-off frequency atbandwidth from datatip -3.02 dB
clc;
clear all; close all; %%matlab
np = tf(0.999, [9.99e-4, 1])
np = 0.999 -------------- 0.000999 s + 1 Continuous-time transfer function.
% [mag,phase,w] = bode(np,w);
%plotting av teoretisk vs eksperimentell data
figure (1)
subplot(2,1,1)
bodemag(np,'k-.'); hold on
grid on
% cutoff frekvensen at -3.02 dB found with datatip
yline(-3.02000000267966,'r-','-3.02 dB', 'LabelHorizontalAlignment','left', 'Linewidth', 1.5)
xline(1001.21694896018,'r-','\omega_c = 1001.22 rad/s ','LabelVerticalAlignment','middle', 'Linewidth', 1.5)
title('1. ordens frekvens amplitude respons')
legend ('Simulated 1. order')
subplot(2,1,2)
h = bodeplot(np, 'k-.');
setoptions(h,'MagVisible','off'); hold on, grid on
% %Need to replace so it looks the same but with calculation of x at given y= -3.02 in magnitude plot
% and y at -45.01 deg, -84.28 deg, -5,7 deg
% cut-off frequency atbandwidth from datatip -3.02 dB
%calculate f at mag equal -3.02 dB
xline(1001.21694896018,'r-','\omega_c ','LabelVerticalAlignment','top', 'Linewidth', 1.5)
yline( -45.0100,'r-','-45.01', 'LabelHorizontalAlignment','left','Linewidth', 1.5)
%data avlest fra datatip at 10_w_c [1.001216948960180e+04,-84.276493287076900]
xline(1001.21694896018*10,'b-','10*\omega_c ','LabelVerticalAlignment','t')
yline(-84.276493287076900,'b-','-84.28 deg', 'LabelHorizontalAlignment','left')
% data avlest fra datatip at 0.1_w_c [100.121694895791,-5.72603838444467]
xline(1001.21694896018*0.1,'m-','0.1*\omega_c','LabelVerticalAlignment','b')
yline(-5.72603838444467,'m-','-5.7 deg', 'LabelHorizontalAlignment','left')
% phase_shift[1001.21694882189,-45.0061545314931];
title('')
round(-84.276493287076900, 2)
ans = -84.2800
grid on

Accepted Answer

Star Strider
Star Strider on 19 Feb 2023
Use the interp1 funciton.
I wrote a short utility program that does exactly that —
% %Need to replace so it looks the same but with calculation of x at given y= -3.02 in magnitude plot
% and y at -45.01 deg, -84.28 deg, -5,7 deg
% cut-off frequency atbandwidth from datatip -3.02 dB
% clc;
% clear all; close all; %%matlab
np = tf(0.999, [9.99e-4, 1])
np = 0.999 -------------- 0.000999 s + 1 Continuous-time transfer function.
% [mag,phase,w] = bode(np,w);
%plotting av teoretisk vs eksperimentell data
[mag,phase,wout] = bode(np);
mags = squeeze(mag);
magsdB = mag2db(mags);
phases = squeeze(phase);
ydB = -3.02;
[wi,dBi] = intsx(wout,magsdB,ydB)
wi = 1.0012e+03
dBi = -3.0200
ydeg = [-45.01, -84.28, -5,-7];
for k = 1:numel(ydeg)
[wdegi,phdgi] = intsx(wout,phases,ydeg(k));
wdeg(k,:) = wdegi;
phdg(k,:) = phdgi;
end
wdeg
wdeg = 4×1
1.0e+03 * 1.0014 9.9941 0.0876 0.1229
phdg
phdg = 4×1
-45.0100 -84.2800 -5.0000 -7.0000
function [xi,yi] = intsx(x,y,c)
% ARGUMENTS: (x,y): Vectors, c: Constant
zci = find(diff(sign(y-c)));
for k = 1:numel(zci)
idxrng = max(1,zci(k)-1) : min(numel(x),zci(k)+1);
xi(k,:) = interp1(y(idxrng)-c,x(idxrng),0);
yi(k,:) = interp1(x(idxrng), y(idxrng), xi(k));
end
end
I use bode here because it calculates and returns the requisite results.
This finds the appropriate radian frequency values for the chosen dependent variable values. I am sure you can take it from here.
.
  6 Comments
Olga Rakvag
Olga Rakvag on 20 Feb 2023
I primarily want to calculate phase shifts at 0.1 of cutoff frequency and 10 of cut off frequency so I can then display them on bode phase shift plot. But never mind, it is already good :-)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!