Plot function not working as expected - different graph to the one in cftool

3 views (last 30 days)
I have a set of 2x12 vectors that I would like to plot a graph for, after using cf tool with a matching function, I end up with a very nice graph which is what the final result is supposed to replicate, this one to be precise, after extracting the parameters from cftool, inputting them into the function that is seen in cftool and using the plot function, I end up with the following result, upon further investigation, I found a function called pchip that would 'smooth up' the graph into a much nicer one, however, I now have a problem in that the function doesn't represent the one in the cftool, it simply connected the dots instead of plotting a proper graph. How do I fix this?
Here's the relevant bit of the code:
amp_A=[0.02195; 0.02202;0.02208;0.02223;0.02237;0.0254;0.02305;0.02197;0.02198;0.0217;0.02205;0.02217];
omega_A=[4.453;7.316;8.348;10.36;11.95;13.19;14.53;3.762;2.07;0.4691;7.921;8.552];
amp_B=[0.01323;0.01841;0.008902;0.004209;0.00286;0.00233;0.00197;0.01015;0.007207;0.006447;0.01143;0.008031];
delta=amp_B./amp_A;
figure(1);
plot(omega_A,delta,'b.');
xlabel('ω[rad/sec]');
ylabel('Amp_B/Amp_A (ω)');
set(gcf,'color','w');
hold on
w0=6.306;
tau=2.186;
s1=11.9113;
p=omega_A./tau;
q=w0.^2-omega_A.^2;
f1=(s1)./sqrt((q).^2+(p).^2);
[omega_A, asc]=sort(omega_A);
f1=f1(asc);
Xi=0:0.01:15;
f2=pchip(omega_A,f1,Xi);
plot(omega_A,f1,Xi,f2,'g');

Accepted Answer

DGM
DGM on 29 Aug 2021
Edited: DGM on 29 Aug 2021
You weren't far off
amp_A=[0.02195; 0.02202;0.02208;0.02223;0.02237;0.0254;0.02305;0.02197;0.02198;0.0217;0.02205;0.02217];
omega_A=[4.453;7.316;8.348;10.36;11.95;13.19;14.53;3.762;2.07;0.4691;7.921;8.552];
amp_B=[0.01323;0.01841;0.008902;0.004209;0.00286;0.00233;0.00197;0.01015;0.007207;0.006447;0.01143;0.008031];
delta=amp_B./amp_A;
plot(omega_A,delta,'b.');
xlabel('ω[rad/sec]');
ylabel('Amp_B/Amp_A (ω)');
hold on
omega_A_fine = linspace(min(omega_A),max(omega_A),500);
w0=6.306;
tau=2.186;
s1=11.9113;
p=omega_A_fine./tau;
q=w0.^2-omega_A_fine.^2;
f1=(s1)./sqrt((q).^2+(p).^2);
plot(omega_A_fine,f1)
You were right to start with a finer x-vector, but instead of filling those intermediate points by interpolation, you need to just use the fit to evaluate the function at those points. Your constants and the fit were right, but you were only evaluating at the original locations.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!