Euler's Formula and FFT
조회 수: 8 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sulaymon Eshkabilov
2023년 11월 2일
편집: Sulaymon Eshkabilov
2023년 11월 2일
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
Sulaymon Eshkabilov
2023년 11월 4일
I posted my answer code for a shorter fit model with sine fcn only in your new post.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!