How to get nonlinear function using bode plots data (gain vs. freq and phase vs. freq)
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm learning to work with Matlab. Sorry if my question is very basic.
I have 5 set of 19 data points for "gain vs. frequency" and "phase (degrees) vs. frequency". I need to find the nonlinear expression that describes the behavior of this system.
Using system identification, I could get the linear transfer function, zeros and poles. But now I need the nonlinear expression based on this format:
Should I use ifft to transform my bode plots data to time domain? if so, what will be the next step?
Thanks in advance.
0 个评论
回答(1 个)
Ayush
2024-5-2
Hi,
In order to find the non-linear expression that describes the behaviour of the given system, I have made use of curve fitting. I will explain an example for "gain vs. frequency" in a similar manner you can try for "phase vs. frequency". To define the non-linear model, I have used "fittype" function, which specifies the model structure, including the names of the independent "x" and dependent "y" variables and the coefficients "a1", "a2", "a3" to be estimated. Then, I used the "fit" function with the frequency data to get the fitted curve "fitresults" and goodness-of-fit statistics "gofs" for each set. This way, you will be able to get the coefficients for the non-linear system that best fits your data. In a similar way, you can implement the above steps for "phase vs frequency". Refer to the example code below for better understanding:
% Example synthetic data
frequency = linspace(1, 10, 19); % Common frequency data for all sets
gain_sets = rand(5, 19); % Each row represents a different set of gain data
modelType = fittype('a1*x + a2*x^2 + a3*x^3', ...
'independent', 'x', ...
'dependent', 'y', ...
'coefficients', {'a1', 'a2', 'a3'}, ...
'options', fitoptions('Method', 'NonlinearLeastSquares', ...
'StartPoint', [0.5, 0.5, 0.5])); % Example start points
fitresults = cell(1, 5); % To store fit results for each set
gofs = cell(1, 5); % To store goodness-of-fit for each set
for i = 1:5
[fitresults{i}, gofs{i}] = fit(frequency(:), gain_sets(i, :)', modelType);
end
% Display the fit result for the first dataset
disp(fitresults{1});
figure;
for i = 1:5
V0_pred = feval(fitresults{i}, frequency);
subplot(5, 1, i);
plot(frequency, gain_sets(i, :), 'ro', 'MarkerFaceColor', 'r'); hold on;
plot(frequency, V0_pred, 'b-', 'LineWidth', 2);
xlabel('Frequency');
ylabel(sprintf('Gain Set %d', i));
legend('Original Data', 'Fitted Model');
title(sprintf('Nonlinear Model Fit for Set %d', i));
grid on;
end
Refer to the below documentation for more information on the "fittype" and "fit" functions:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!