Calculating Fourier Series Coefficients

400 ビュー (過去 30 日間)
Jay Mayle
Jay Mayle 2013 年 3 月 6 日
コメント済み: Walter Roberson 2025 年 1 月 30 日 20:24
I am trying to compute the trigonometric fourier series coefficients of a periodic square wave time signal that has a value of 2 from time 0 to 3 and a value of -12 from time 3 to 6. It then repeats itself. I am trying to calculate in MATLAB the fourier series coefficients of this time signal and am having trouble on where to begin.
The equation is x(t) = a0 + sum(bk*cos(2*pi*f*k*t)+ck*sin(2*pi*f*k*t))
The sum is obviously from k=1 to k=infinity.
a0, bk, and ck are the coefficients I am trying to find. Thanks for the help.
  1 件のコメント
omar seraj
omar seraj 2021 年 11 月 1 日
How to plot in Fourier series given a time interval -1.5 to 2.5I need a step by step answer to this problem please

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

回答 (7 件)

Rick Rosson
Rick Rosson 2013 年 3 月 6 日
編集済み: Rick Rosson 2013 年 3 月 6 日

Youssef  Khmou
Youssef Khmou 2013 年 3 月 6 日
編集済み: Youssef Khmou 2013 年 3 月 6 日
hi Jay , computing a0 bk and ck is bout theory i think, anyway try :
You have first to construct the original signal "Square(t)" so as to compare it with Fourier approximation :
clear , close all;
Fs=60;
t=0:1/Fs:20-1/Fs;
y=square(t,50);
y(y>0)=2;
y(y<0)=-12;
figure, plot(t,y);
axis ([0 20 -20 10])
% Fourier Series
a0=0;
Fy=zeros(size(t));
N=10;
for n=1:2:N
Fy=Fy+(4/n*pi)*sin(2*pi*n*t/(2*pi));
end
hold on,
plot(t,Fy,'r')
legend(' Square ','Fourier Approx');
Try now to to compute an, and bn and increase the number of iterations N and conclude
You have also to adjust the amplitudes
  2 件のコメント
Suliman
Suliman 2025 年 1 月 30 日 18:18
hello youssef
do you know how to get the coefficients in the complex exponentials formula?
Torsten
Torsten 2025 年 1 月 30 日 20:00
編集済み: Torsten 2025 年 1 月 30 日 20:02
Once you have the coefficients in the real representation, use

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


Kamal Kaushal
Kamal Kaushal 2020 年 3 月 1 日
編集済み: Walter Roberson 2025 年 1 月 30 日 20:13
clear , close all;
Fs=60;
t=0:1/Fs:20-1/Fs;
y=square(t,50);
y(y>0)=2;
y(y<0)=-12;
figure, plot(t,y);
axis ([0 20 -20 10])
% Fourier Series
a0=0;
Fy=zeros(size(t));
N=10;
for n=1:2:N
Fy=Fy+(4/n*pi)*sin(2*pi*n*t/(2*pi));
end
hold on,
plot(t,Fy,'r')
legend(' Square ','Fourier Approx');

Hemang Mehta
Hemang Mehta 2020 年 10 月 23 日
編集済み: Walter Roberson 2025 年 1 月 30 日 20:13
clear , close all;
Fs=60;
t=0:1/Fs:20-1/Fs;
y=square(t,50);
y(y>0)=2;
y(y<0)=-12;
figure, plot(t,y);
axis ([0 20 -20 10])
% Fourier Series
a0=0;
Fy=zeros(size(t));
N=10;
for n=1:2:N
Fy=Fy+(4/n*pi)*sin(2*pi*n*t/(2*pi));
end
hold on,
plot(t,Fy,'r')
legend(' Square ','Fourier Approx');
  3 件のコメント
Rik
Rik 2022 年 3 月 31 日
Comment posted as flag by Hariharan Hariharan:
need the flowof code for case study
Walter Roberson
Walter Roberson 2025 年 1 月 30 日 20:14

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


Sikha ranjith kumar
Sikha ranjith kumar 2022 年 6 月 1 日
x(t)=cos(50t)
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 1 月 30 日 20:24
This is not valid MATLAB syntax. There is absolutely nowhere in MATLAB that supports implicit multiplication of a constant and a variable. The closest that MATLAB comes is that complex components can be indicated by using (for example) 50i or 50j
Also. in order for the above to work, t would have to be either a positive integer (indexing into x) or else a symbolic variable (or vector of symbolic variables.) If t is time, then time is typically fractional and beginning with 0 or negative, which would not be valid subscripts of the assignment to x(t)

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


Gabriele Bunkheila
Gabriele Bunkheila 2024 年 7 月 29 日
編集済み: Gabriele Bunkheila 2024 年 7 月 29 日
From a computational perspective, the Fourier Series is closely related to the Discrete Fourier Transform when talking about discrete signals (say sampled at a sampling rate fs, i.e. using a sampling period Ts = 1/fs). The Discrete Fourier Transform, in turn, is most often computed through the Fast Fourier Transform (or FFT, implemented by the fft function). That said, the Fourier Series only applies to periodic signals (say with period T).
Some of the key ideas to keep in mind when using the FFT to compute the Fourier Series include:
  • The time-domain signal segment provided as input to the fft function should include exactly an integer number of periods or the signal. The simplest case is when that's exactly 1 period made of N samples, or T = N*Ts
  • The coefficients returned by the FFT will be complex numbers. To obtain back the cosine and sine coefficients of the bk and ck coefficients, use cos and sin on the k-th complex coefficient returned by the FFT
  • The FFT will only provide a "finite" sequence of separate complex coefficients, from k=0 to k equal just below T/(2*Ts). That is N/2-1 for N even and (N-1)/2 for N odd. The actual number of complex values returned by the FFT will be up to double that number, but the second half of those can be ignored if the input time-domain sequence is real
If you need a review of the basics on this topic, I recommend taking a look at the following resources:

NIHAD
NIHAD 2024 年 11 月 18 日
編集済み: Walter Roberson 2025 年 1 月 30 日 20:16
we know that fourier series coefficients are given by and To find them just write these formulas in matlab.
your give example is 2 for t=0-3 and -12 for t=3-6. So the time period is T=6.
syms k t n T
assume(k>0)
assume (k,'integer') %assume k is a positive integer
a_0=(1/T)*(int(2,t,0,3)+int(-12,t,3,6))
a_0 = 
a_k=(2/T)*(int(2*cos(2*k*pi*t/T),t,0,3)+int(-12*cos(2*k*pi*t/T),t,3,6))
a_k = 
b_k=(2/T)*(int(2*sin(2*k*pi*t/T),t,0,3)+int(-12*sin(2*k*pi*t/T),t,3,6))
b_k = 

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by