Euler's Formula and FFT
8 views (last 30 days)
Show older comments
Seweryn
on 2 Nov 2023
Commented: Sulaymon Eshkabilov
on 4 Nov 2023
Hi guys, from the .csv file, I performed an FFT analysis in Simulink and obtained the following equations (pdf file). Take this equation (screen 1) for example, can I expand it to this form (screen 2)? I know, I can use e^ix = cos(x) + isin(x) but i don't know how to do that. Thanks in advance!
Best regards,
Seweryn
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 2 Nov 2023
Edited: Sulaymon Eshkabilov
on 2 Nov 2023
If understood correctly, you are trying to find a non-linear fit of the large flacturations using sine and cosine functions. If so, here is how it can be attained:
% Data import
D = readmatrix('tek0005.csv');
D(1:15, :) = []; % Data cleaning
f1 = 2; % found using fft
Model = @(a, t)(a(1)*sin(2*pi*f1*t)+a(2)*cos(2*pi*f1*t));
t = D(:,1);
y1 = D(:,2); % Channel 1
a0 = [1 1]; % Initially estimated guess values for coeff a
Coeffs1 = nlinfit(t, y1, Model, a0);
a = Coeffs1; % Found fit model coeffs
y_fit = (a(1)*sin(2*pi*f1*t)+a(2)*cos(2*pi*f1*t));
figure(1)
plot(t, y1, 'r')
hold on
plot(t, y_fit, 'k--', 'LineWidth',2)
legend('Data: CH1', 'Fit Model')
ylabel('Channel 1')
xlabel('Time')
hold off
% Similarly, you can do for the other channel data
f1 = 2; % found from fft
t = D(:,1);
y2 = D(:,3);
% NB: mean of y2 is NOT "0". Thus, it should be removed from y2 or added to the fit model!
a0 = [1 1]; % Initially estimated guess values for coeff a
Coeffs = nlinfit(t, y2, Model, a0)
a = Coeffs;
y_fit = (a(1)*sin(2*pi*f1*t)+a(2)*cos(2*pi*f1*t))+mean(y2);
figure
plot(t, y2, 'b')
hold on
plot(t, y_fit, 'k--', 'LineWidth',2)
legend('Data: CH2', 'Fit Model')
ylabel('Channel 2')
xlabel('Time')
hold off
3 Comments
Sulaymon Eshkabilov
on 4 Nov 2023
I posted my answer code for a shorter fit model with sine fcn only in your new post.
More Answers (0)
See Also
Categories
Find more on Spectral Measurements 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!