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 CenterFile Exchange에서 Discrete 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