# Why does this Fourier series give lower amplitude for max value of signal?

I want to approximate below signal using Fourier series on Matlab.

My code is below

close all
clear all
clc
a_0 = 0
t=-10:0.001:10
x_t = 2/5
T = 10;
w0 = 2*pi/T
numOfTerms = 100
plot(t, x_t);

for k=1:numOfTerms-1
a_k = (1/(w0*i*k*T))*(  exp(-1*i*k*w0)-exp(-3*i*k*w0)+ exp(-7*i*k*w0)- exp(-9*i*k*w0))
x_t = x_t + a_k * exp(i*k*w0*t)
plot(t, x_t);
title(['Number Of Terms = ',num2str(k+1)]);
pause(0.1);
end


You see that min point of this signal above zero and max point below 1. How can I solve this problem? Why it gives such result?

The formula for the Fourier series is

$$x(t)=\sum_{k=-\infty}^{\infty}c_ke^{jk\omega_0 t}\tag{1}$$

You only use the non-negative indices $k$, but you must also use the negative ones. Since your signal $x(t)$ is real-valued, you can in fact compute everything using only the positive indices, but then you must take two times the real part:

$$x(t)=c_0+2\Re\left\{\sum_{k=1}^{\infty}c_ke^{jk\omega_0 t}\right\}\tag{2}$$

Note that you must add the DC term $c_0$ separately.

This is the corresponding Matlab code:

t=-10:0.001:10;
x_t = 0;
T = 10;
w0 = 2*pi/T;
numOfTerms = 100;

for k=1:numOfTerms-1
a_k = (1/(w0*i*k*T))*(  exp(-1*i*k*w0)-exp(-3*i*k*w0)+ exp(-7*i*k*w0)- exp(-9*i*k*w0));
x_t = x_t + a_k * exp(i*k*w0*t);
end

x_t = 2*real(x_t) + 2/5;

plot(t,x_t);



I have simulated on my computer, and I found that when I added the negative frequency terms, the result was correct.

• Please make one answer out of the two answers that you gave (and delete the other one). Furthermore, note that the coefficients $a_k$ are correct. May 3, 2015 at 9:58