Representing a set of data points as a Fourier Series
21 views (last 30 days)
Show older comments
Samuel James
on 13 Feb 2021
Commented: Star Strider
on 6 May 2023
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.
0 Comments
Accepted Answer
Star Strider
on 13 Feb 2021
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 Comments
omar ali
on 6 May 2023
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
on 6 May 2023
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 (°)')
.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!