plot the fundamental harmonic wave
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello everyone. I have exported data to an Excel spreadsheet where the x-axis is represented by theta (in radians). How can I plot the fundamental harmonic wave from this wave data?
댓글 수: 6
채택된 답변
Mathieu NOE
2023년 11월 23일
hello again
so this is it, we do a single frequency DFT (aka order extraction) at the second harmonic (as we have two period of signal for theta ranging from 0 to 2*pi
result :
code :
%Load Excel file
data = readmatrix('Book1.xlsx'); % theta(Rad) Br(T)
%Extract theta and y columns
theta = data(:,1); % theta (0 - 2pi)
y = data(:,2); % y data
%%%%%%%%%%%%% main code %%%%%%%%%%%%%%%%%
% 2nd order extraction (DFT)
order = 2;
% model fit : X = A*cos(order*theta) + B*sin(order*theta) + C
C = mean(y);
y = y-C;
n = numel(theta);
A = 2/n*trapz(y.*cos(order*theta));
B = 2/n*trapz(y.*sin(order*theta));
yfit = A*cos(order*theta) + B*sin(order*theta) + C;
% plot
figure(1),
plot(theta, y, 'b',theta, yfit, 'r')
legend('data','model fit');
댓글 수: 1
Abdullah
2024년 4월 24일
Hello Mathieu,
i tried to use your code with my data, but it does not work, do you have an idea?
https://de.mathworks.com/matlabcentral/answers/2110271-how-to-plot-the-fundamental-harmonic-wave-from-given-data?s_tid=srchtitle
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!