Using the trigonometric Fourier series to develop MATLAB code to confirm correctness

57 views (last 30 days)
fs = 2/5 + sum(2/(n*pi)*sin(2*pi/5*n)*cos(2*pi/5*n*t)) x(t) = sum(rect((t-5*n)/2))
I really don't know how to plot two function. Please help me.
  3 Comments
wenyuan zhu
wenyuan zhu on 13 Jan 2014
There are two problems related together. Firstly,find the trigonometric Fourier series of the following periodic functions
I do the math and find out that the trig fourier series is fs = 2/5 + equation under below
Secondly, using the trigonometric Fourier series(fs) derived in Problem 1, develop a MATLAB code to confirm the correctness of the series. Basically, I am stuck on the second problem. Sorry for the confusion.
Mummana Sai Varun
Mummana Sai Varun on 14 May 2022
Compute the trigonometric Fourier series expansion of a continuous time exponentially rising signal using Matlab Simulation Software.

Sign in to comment.

Answers (1)

Patrik Ek
Patrik Ek on 13 Jan 2014
Edited: Patrik Ek on 22 Jan 2014
The solution is quite direct, it is more a matter of understanding. You have the fourier series given as a function of t. What you actually have calculated here is the complete fourier series, so to say the equation above should be exact a square wave. The function describes a set of discrete frequencies with
w = n*t/5 and amplitued An = 2*sin(2*pi*n/5)/(n*pi), n = 1,2,...,
Due to ortogonality of the trigonometric functions it is possible to superpositioning all the different frequencies, why it is a sum in the function. Matlab does however work with discrete time samples as well. The sampling frequency need to be much higher than the frequency of the highest order, if the plot are going to look good. So to say, if nMax = 10, you may want the time between the samples to be 0.05 or so (to get a smooth line, maybe I did not need to say that). The code required is something like,
tMax = 20; % 4 periods
t = 0:0.05:tMax;
nMax = 10; % order of the fourier series.
y = 2/5; %signal offset
for n = 1:nMax
y = y+2*sin(2*pi*n/5)*cos(2*pi*n*t/5)/n/pi; % sum all contributions
end
figure;
plot(t,y,'r');
hold on;
%Rectangular wave by looking at the function.
t0 = [0,0.999,1]; % first half wave
x0 = [1,1,0];
nPeriods = 4
t1 = [4,4.001,5.999,6];
t = [t0,t1];
x1 = [0 1 1 0];
x = [x0,x1];
for periodI = 3:nPeriods % first two periods by hand
t = [t,t1+5*(nPeriods-2)];
x = [x,x1];
end
plot(t,x,'k');
This will plot both lines in the same graph. and with variable accuracy parameters.
Sorry for the late answer BR/Patrik
  4 Comments
Mummana Sai Varun
Mummana Sai Varun on 14 May 2022
Compute the trigonometric Fourier series expansion of a continuous time exponentially rising signal using Matlab Simulation Software.
Ebenezer Arthur
Ebenezer Arthur on 17 Dec 2022
Hello i am trying to do the same with this code but i dont seem to get the period when t should be 0 or mirrored. can you take a look at my code.
T = 10;
V = 2;
x= 0:0.05:20 ; % x also known as t
w = 2*pi/T;
a0= V;
a1= 2*V./T* sin(T/2);
b1= 2*V./T *(1-cos(T/2));
a2= V/T *sin(T);
b2= V/T *(1-cos(T));
a3= 2*V/(3*T) * sin(3/2*T);
b3= 2*V/(3*T) *(1-cos(3/2*T));
%sq=square
f2= a0/2+ a1*cos(w*x) + b1*sin(w*x) ;
f3= a0/2+ a1*cos(w*x) + b1*sin(w*x) + a2*cos(2*w*x) + b2*sin(2*w*x);
f4= a0/2+ a1*cos(w*x) + b1*sin(w*x) + a2*cos(2*w*x) + b2*sin(2*w*x) + a3*cos(3*w*x) + b3*sin(3*w*x);
plot(x,f2,"g")
hold on
plot(x,f3,'b')
hold on
plot(x,f4,'r')

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!