plot the fundamental harmonic wave

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
Mathieu NOE 2023 年 11 月 20 日
hello
you can work either in time / angular domain , by applying a band pass filter centered at your target frequency (fundamental)
or you can work in the frequency domain (fft your data, then keep only the frequency(ies) of interest and do ifft)
hamid k
hamid k 2023 年 11 月 20 日
Hello, my issue is that I can't execute an FFT on discrete points since Matlab recognizes either the time or frequency of a waveform, while my data is plotted against theta (degrees).
Mathieu NOE
Mathieu NOE 2023 年 11 月 21 日
well, show me your data (and code) and I will answer you
Star Strider
Star Strider 2023 年 11 月 21 日
The fft function only wants ‘theta’ to be sampled at a constant interval. It does not know or care what ‘theta’ actually is (seconds, years, metres, parsecs, radians, degrees, or anything else). The frequency unit will then be the inverse of that (cycles/second, cycles/metre, cycles/parsec, cycles/radian, cycles/degree).
hamid k
hamid k 2023 年 11 月 23 日
You can find the attached data and code files here.
Mathieu NOE
Mathieu NOE 2023 年 11 月 23 日
see my answer below

サインインしてコメントする。

 採用された回答

Mathieu NOE
Mathieu NOE 2023 年 11 月 23 日

0 投票

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
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 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 11 月 20 日

0 投票

Here are two MATLAB fcns (bandpass() and fft()) which can be applied to solve your exercise.

カテゴリ

ヘルプ センター および File ExchangeFourier Analysis and Filtering についてさらに検索

質問済み:

2023 年 11 月 19 日

コメント済み:

2024 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by