 #1
 4
 0
Homework Statement:
 I want to determine by using matlab the Fourier Series Complex Coefficients of the signal x(t), based on the below formula and to plot the amplitude spectre. Also, I want to rebuild the initial signal using the determined Fourier Coefficients, and I want to plot on the same graph the initial signal and the rebuilt one so that I can compare them. Unfortunately, haven't got the expected results.
Relevant Equations:

x(t)=1/P*[Σ][/k][/∞]=∞[X][/k]*[e][/jkw0t] with w0=2π/P;
[X][/k]=[∫][/P] x(t)*[e][/jkw0t] dt for k coefficients;
[x][/^](t)=1/P*(X0+2*[Σ][/N][/k=1] [X][/k]*[e][/jkw0t] ); [X][/k]=[X][/k][/*]; for reconstruction of the signal.
Matlab:
%My code:
%Type of signal: square
T = 40; %Period of the signal [s]
F=1/T; % fr
D = 23; % length of signal(duration)
dt=(D/T)*100;
N = 50; %Number of coefficients
w0 = 2*pi/T; %signal pulse
t1= 0:0.002:T; % original signal sampling
x1 = square((2*pi*F)*(t1),dt);%initial square signal
t2= 0:0.002:D; %modified signal sampling
x2 = zeros(1,length(t2)); %initializing the modified signal with null values.
dif=TD;
x2(t1<=D)=x1(t1<=D);% modify the null values with values from the original signal.
x2(1,dif:D)=x1(1,dif:D); %modify for values of t1>=TD.
subplot(2,1,1)
plot(t2,x2),title('x(t)+ reconstructed signal)');
hold on
for k = N:N %k represents the variable after which the sum is achieved
x3 = x1; %x3 represents the signal obtained after the Fourier Series formula;
x3 = x3 .* exp(1i*k*w0*t1);
X(k+N+1) = 0; %initialise with null value
end
for i = 1:length(t1)1
X(k+N+1) = X(k+N+1) + (t1(i+1)t1(i)) * (x3(i)+x3(i+1))/2; %reconstruction using the coefficients
end
for i = 1:length(t1)
x_rec(i) = 0; %initialise with null value
% x_rec is the reconstructed signal using N Coefficients
end
for k=N:N
x_rec(i) = x_rec(i) + (1/T) * X(k+51) * exp(1i*k*w0*t1(i)); %reconstruction using the coefficients ( the integral being calculated as a sum)
end
plot( t1, x_rec, '')
subplot(2,1,2)
w=50*w0:w0:50*w0; %w is the vector which allows displaying the spectre of the function
stem(w/(2*pi),abs(X));
Last edited: