- you can specify the frequency range of the curve, and as per your given plot range can be written as: “frequencies = logspace(-2, 3, 1000);”
- Then substitute these frequencies in the “orig” curve, which can be done by using: “origMagnitude = abs(freqresp(orig, frequencies));”
- This will return the respective magnitude of the curve and to convert the curve in dB, use “20*log10(origMagnitude)”.
- Similarly substitute the frequency value is the “linApprox” curve using: “linApproxMagnitude = subs(linApprox, x, frequencies);”
- Finally find deviation between the two curves using the following equation: “deviation = squeeze(20*log10(origMagnitude))'-squeeze(double(linApproxMagnitude));”
- To find the maximum value of all the deviations calculated, use the “max()” function.
How can I return the maximum value of a bodemag minus a linear approximation if I have both systems plotted?
52 views (last 30 days)
Show older comments
I have a transfer function and its linear approximation graphed, and I would like to return the frequency at which the bodemag graph and linear approximation are the most different from each other and also the dB difference.
I think that this can either be done by finding an equation for the transfer function that exactly describes how it behaves, and then just subtract the linear function and find it that way, or have a way to look at the points on the graph and find the x axis value where the y axis difference is the biggest on a chosen interval.
In my head it sounds like the latter would be easier, but I don't know how to execute it.
Attached below is an image describing what I would like to know and my graphing code.
orig = tf([2500],[1 20 2500]);
syms x;
linApprox = piecewise(x<50, 0, x>50, -40*log10(x/50));
fplot(linApprox,'r')
hold on
bodemag(orig,'b')
0 Comments
Accepted Answer
Ayush
on 5 Oct 2023
Hi Robert,
I understand that you are trying to determine the maximum deviation in magnitude (in dB) and the corresponding frequency at which the two curves, bodemag and linear approximation, exhibit the greatest difference.
To do so:
Final code snippet is given below:
orig = tf([2500],[1 20 2500]);
syms x;
linApprox = piecewise(x<50, 0, x>50, -40*log10(x/50));
fplot(linApprox,'r')
hold on
bodemag(orig,'b')
%%
frequencies = logspace(-2, 3, 1000); % Adjust the range and number of frequencies as needed
% Calculate the magnitude response of the transfer function
origMagnitude = abs(freqresp(orig, frequencies));
% Calculate the magnitude response of the piecewise function
linApproxMagnitude = subs(linApprox, x, frequencies);
% Calculate the deviation between the two magnitude responses
deviation = squeeze(20*log10(origMagnitude))' - squeeze(double(linApproxMagnitude));
% Find the maximum deviation and its corresponding frequency
[maxDeviation, maxDeviationIndex] = max(abs(deviation));
maxDeviationFrequency = frequencies(maxDeviationIndex);
% Display the results
disp("Maximum deviation in magnitude frequency response:");
disp("Deviation: " + maxDeviation);
disp("Frequency: " + maxDeviationFrequency);
Hope this helps!
0 Comments
More Answers (0)
See Also
Categories
Find more on Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!