Representing a set of data points as a Fourier Series

21 ビュー (過去 30 日間)
Samuel James
Samuel James 2021 年 2 月 13 日
コメント済み: Star Strider 2023 年 5 月 6 日
Hi, I wanted to represent a set of discrete data points as a fourier series. Since I don't have a function I was wondering how to get the fourier coefficients. I tried researching and I think I should use fft(), but I dont know how exactly and how I would go about getting the coefficents from there as I am new to the concept of Fourier Series and am having trouble understandin them. The data points are [x,y]
[1 13.38
2 15.33
3 18.11
4 21.15
5 25.74
6 27.89
7 29.18
8 29.74
9 29.32
10 26.01
11 19.79
12 17.24].
Any help would be greatly appreciated.

採用された回答

Star Strider
Star Strider 2021 年 2 月 13 日
Try this:
data = [1 13.38
2 15.33
3 18.11
4 21.15
5 25.74
6 27.89
7 29.18
8 29.74
9 29.32
10 26.01
11 19.79
12 17.24];
t = data(:,1);
s = data(:,2);
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(t); % Signal Length
smean = mean(s); % Mean Amplitude
FTs = fft(s - smean)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency')
ylabel('Amplitude')
The coefficients are ‘FTs’. Note that this calculates a two-sided Foiurier transform, however only a one-sided Fourier transform is plotted.
Subtracting the mean of the signal in the fft call makes the peaks other than the zero-frequency peak more easily visible. This signal has a mean value of 22.74, so the zero-frequency peak would hide the other peaks if the zero-frequency peak was included in the plot.
  6 件のコメント
omar ali
omar ali 2023 年 5 月 6 日
This code has been very useful to me. I would be grateful for how a plot of phase angle vs frequency could be plotted for this case?
Star Strider
Star Strider 2023 年 5 月 6 日
figure
subplot(2,1,1)
plot(Fv, abs(FTs(Iv))*2)
grid
ylabel('Amplitude')
subplot(2,1,2)
plot(Fv, rad2deg(angle(FTs(Iv))))
grid
xlabel('Frequency')
ylabel('Phase (°)')
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by