Contourf plot of magnitude of transferfunction along trajectory

1 vue (au cours des 30 derniers jours)
Jeppe Andersen
Jeppe Andersen le 22 Nov 2022
I wish to make a contour plot of the magnitude of bodeplots along a trajectory. It needs to look somewhat like the plot attached bellow.
The idea is to analyze the coupleing at frequenzies for each point along the trajectory, this is defined by each K (1x1600 double) .
However, i am not able to format the data in such a fashion that it works with the contour plot, as i don't understand fully how the contour plot works.
Or maybe i need a different approach to how the data is generated?
Thanks in advance!
magmat=cell(1,1600);
wfrec=logspace(-3,4,1000);
for i=1:1600
g11=(K14(i)*K25(i)*s-K15(i)*K24(i)*s+K15(i)*s^2+K13(i)*K25(i)-K15(i)*K23(i))/(K12(i)*K24(i)*s^2-K12(i)*s^3-K14(i)*K22(i)*s^2-K24(i)*s^3+s^4+K11(i)*K24(i)*s-K11(i)*s^2+K12(i)*K23(i)*s-K13(i)*K22(i)*s-K14(i)*K21(i)*s-K23(i)*s^2+K11(i)*K23(i)-K13(i)*K21(i));
g12=(K14(i)*K26(i)*s-K16(i)*K24(i)*s+K16(i)*s^2+K13(i)*K26(i)-K16(i)*K23(i))/(K12(i)*K24(i)*s^2-K12(i)*s^3-K14(i)*K22(i)*s^2-K24(i)*s^3+s^4+K11(i)*K24(i)*s-K11(i)*s^2+K12(i)*K23(i)*s-K13(i)*K22(i)*s-K14(i)*K21(i)*s-K23(i)*s^2+K11(i)*K23(i)-K13(i)*K21(i));
[mag,phase]=bode(g11/g12,wfrec);
magmat(i)=mat2cell(zeros(1000,1),1000,1);
magmat{i}(:,:,1)=mag;
end
n=ones(1600:1000);
distance = linspace(0,3*0.05*2*pi,1600);
for i=1:1600
n(:,i)=distance(i);
end
contour(wfrec,n,magmat{1,:})

Réponse acceptée

Star Strider
Star Strider le 22 Nov 2022
I do not have your data or a clear description of what you want to do, however I would do something like this —
s = tf('s');
sys = @(K) (s+1) / (s^2 + 50*s + K); % Anonymous Function
wfrec=logspace(-3,3,1000);
Kv = linspace(1, 100, 15);
for k = 1:numel(Kv)
[mag,phase] = bode(sys(Kv(k)), wfrec);
magm(:,k) = squeeze(mag);
phasem(:,k) = squeeze(phase);
end
figure
surfc(Kv, wfrec, mag2db(magm), 'EdgeColor','none')
colormap(turbo)
grid on
xlabel('Kv')
ylabel('Frequency (rad/sec)')
zlabel('Magnitude (dB)')
Ax = gca;
Ax.YScale = 'log';
view(45,35)
figure
contourf(Kv, wfrec, mag2db(magm), 50)
colormap(turbo)
grid on
xlabel('Kv')
ylabel('Frequency (rad/sec)')
zlabel('Magnitude (dB)')
colorbar
Ax = gca;
Ax.YScale = 'log';
Ax.XDir = 'reverse';
view(90,90)
figure
bode(sys(1), wfrec)
The bode function (and other such functions) require a system object as the argument. Rather than re-building it each time, this apporoach creates an anonymous function version of the system object, and then provides the arguments in each iteration of the loop. It stores the results in a matrx, and then plots them. (I added the surf plot so I could understand what the matrix looks like. This is helpful although not required.) The frequency axis is logarithmically scaled.
The:
view(90,90)
call rotates the contourf plot to place the ‘Frequency’ axis as the lower axis and the ‘Kv’ axis as the left axis. This results in the ‘Kv’ axis descending instead of ascending, and:
Ax.XDir = 'reverse';
reverses it so that it now ascends.
Make appropriate changes to get the result you want.
.
  2 commentaires
Jeppe Andersen
Jeppe Andersen le 22 Nov 2022
Thank you very much !
Star Strider
Star Strider le 22 Nov 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by