필터 지우기
필터 지우기

Euler's Formula and FFT

조회 수: 8 (최근 30일)
Seweryn
Seweryn 2023년 11월 2일
댓글: Sulaymon Eshkabilov 2023년 11월 4일
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

채택된 답변

Sulaymon Eshkabilov
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)
Coeffs = 1×2
-0.0335 -0.0016
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
Seweryn
Seweryn 2023년 11월 4일
편집: Seweryn 2023년 11월 4일
I need the form of equations like you used above: (a(1)*sin(2*pi*f1*t)+a(2)*cos(2*pi*f1*t))+mean(y2);
Sulaymon Eshkabilov
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 CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by