0% found this document useful (0 votes)
55 views10 pages

P2 Fourier Series

The document describes different types of Fourier series that can be used to represent periodic signals: 1. Trigonometric Fourier series expresses a periodic signal as a sum of sines and cosines, with coefficients that can be calculated using integrals. 2. Harmonic Fourier series expresses a periodic signal as a sum of harmonic terms with amplitudes and phases, which can be determined from the trigonometric Fourier series coefficients. 3. Complex Fourier series expresses a periodic signal as a sum of complex exponential terms, with coefficients that can also be related to the trigonometric Fourier series. Matlab code is provided to calculate the coefficients for different Fourier series representations of a sample switching function.

Uploaded by

Nutu Raluca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views10 pages

P2 Fourier Series

The document describes different types of Fourier series that can be used to represent periodic signals: 1. Trigonometric Fourier series expresses a periodic signal as a sum of sines and cosines, with coefficients that can be calculated using integrals. 2. Harmonic Fourier series expresses a periodic signal as a sum of harmonic terms with amplitudes and phases, which can be determined from the trigonometric Fourier series coefficients. 3. Complex Fourier series expresses a periodic signal as a sum of complex exponential terms, with coefficients that can also be related to the trigonometric Fourier series. Matlab code is provided to calculate the coefficients for different Fourier series representations of a sample switching function.

Uploaded by

Nutu Raluca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Fourier series

1. The trigonometric Fourier series

A periodic signal (with certain properties and restrictions – see the course notes)
f (t )  f (t  T ), t  , where T  2 / 0 is the period, can be expressed as a trigonometric Fourier
series as follows:

a0 
f (t)    ak cos(k0t )  bk sin(k0t ) (1.1)
2 k 1

Where the coefficients are expressed as:


a0 1
2 T T
 f (t )dt (1.2)

2
T T
ak  f (t ) cos(k0t )dt (1.3)

2
T T
bk  f (t )sin(k0t )dt (1.4)

In this lesson our objective is to develop a Matlab script that determines these coefficients for
a given periodic signal, by making use of the function integral() (see Matlab’s help). As an example
we will use the switching function, f c (t ) , but the code can be adapted for any periodic signal, given
that it’s function is previously designed.
We start by defining the fundamental frequency (thus determining the corresponding period)
and we continue expressing the time base for the function that will be decomposed into a
trigonometric Fourier series (file fourierSeries.m):
f0 = 50;

% The angular frequency omega0 in rad/s


omega0 = 2*pi*f0;

% The period for fc


T = 1/f0;

% We establish the time difference between consecutive values of the time


% base so that we have enough values in one period.
% In this case we chose 100 time values in one period.

step = T/100;

% We define the time base from -T to 2*T with the chosen step:
t=-T:step:2*T;

1
In order to determine the Fourier coefficients, first we must define the periodic signal as a
Matlab function. In our case we define f c (t ) as (file fc.m):
function result = fc(t,T)
% The function returns the amplitude values for the switching function
% defined as 1 from 0 la T/2 and -1 from T/2 la T)
% The input parameters are:
% t – the time base vector which contains the time values at which the
% function will be evaluated. The result will contain the amplitudes
% corresponding to the time base vector
% T – the period of the signal – should be a number, not a vector or matrix

result = zeros(1,length(t));

for index_t = 1:length(t)


% we use the modulus because any time value can be expressed as
% t = k*T+t0, where t0 = t mod T. We see that t0 will always be
% between 0 and T which means that we now can express the values on any
% period.
if mod(t(index_t),T)<T/2
result(index_t) = 1;
else
result(index_t) = -1;
end
end
An alternative solution for the switching function is:
function result = fc(t,T)
% The function returns the amplitude values for the switching function
% defined as 1 from 0 la T/2 and -1 from T/2 la T)

result = (-1)ones(size(t));
result( mod(t,T)<T/2 ) = 1;

end

Next, we determine the DC component using (1.2.) and Matlab’s integral() function :
a0over2 = 1/T * integral(@(t)fc(t,T),0,T);

The use of integral() is as follows:


integral(fun,xmin,xmax);

where fun is the function, in our case it will be @(t)fc(t,T),which means that we will integrate
fc(t) with respect to t. In order to define the interval on which the integration will be determined, we
will specify xmin and xmax as 0 and T.
Next we will determine the first N coefficients for the trigonometric Fourier series:
% We determine the first N coefficients for the trigonometric Fourier
% series
N = 10;
a=zeros(1,N);
b=zeros(1,N);
for k=1:N
a(k) = 2/T * integral(@(t)(fc(t,T).*cos(k*omega0*t)),0,T);
b(k) = 2/T * integral(@(t)(fc(t,T).*sin(k*omega0*t)),0,T);
2
end
a
b

After we run the script we will see that the values for a k are very small (less than 10-15), even
though in theory they should be 0. The same is true for bk values. In order to force these values to 0
we will establish a threshold under which all the values will be considered zero (in our case the
threshold will be 1010 ). This operation is necessary because in the following steps, based on the ratio
between a k and bk , we will need to compute another parameter. Thus, if both a k and bk are very
close to zero but not zero, than their ratio will be different from 0 and furthermore, it will be random
value, which will alter the parameters computed based on this ratio.
thr = 10^-10;
if abs(a0over2)<thr
a0over2 = 0;
end
if abs(a(k))<thr
a(k) = 0;
end
if abs(b(k))<thr
b(k) = 0;
end

2. The reconstruction of the periodic signal based on the trigonometric


Fourier series
At this point, we reverse the problem: we have the Fourier coefficients and we want to obtain the
original signal. For the reconstruction we use (1.1) in an iterative manner. First we add the DC
component and then we continue by adding one sine and cosine at a time, each sine/cosine weighted
with its corresponding Fourier coefficient. The Matlab code for this procedure is the following:
figure(111)
plot(t, fc)

sRec = a0over2*ones(1,length(t)); %first we add the DC component


figure(111)
hold on
plot(t, sRec)
hold off
for i = 1:length(a)
sRec = sRec + a(i)*cos(i*omega0*t)+b(i)*sin(i*omega0*t);
figure(111)
hold on
plot(t, sRec)
hold off
pause(0.01)
end
figure(112)
plot(t, fc), title('Step by step comparison between the original and the
reconstructed signal')
hold on
plot(t, sRec, 'r')
legend('original', 'reconstructed')
hold off

3
3. The harmonic Fourier series

For any periodic signal f (t )  f (t  T ), t  , with the period T , we can express the harmonic
Fourier series as follows:

f (t )  A0   Ak cos  k0t  k  (1.5)
k 1

The coefficients of the harmonic Fourier series can be determined by using the trigonometric
Fourier series coefficients:
a0
A0  (1.6)
2

Ak  ak2  bk2 , k  1 (1.7)

  bk 
  arctan   , ak  0
  ak 
k   (1.8)
 arctan  bk    , a  0
   k
  ak 

We will modify the previous program in order to determine the harmonic Fourier series
coefficients:
%% The harmonic Fourier series
N = 100;
a=zeros(1,N);
b=zeros(1,N);
A=zeros(1,N+1);

% The coefficient for the DC component a0/2


a0over2 = 1/T * integral(@(t)fc(t,T),0,T);
if a0over2<10^-10
a0over2 =0;
end

% We add the DC component and the phase in case it is negative


A(1)=abs(a0over2);
if a0over2 >=0
phi(1)=0;
else
phi(1)=-pi;
end

for k=1:N
% We first determine the trigonometric series coefficients
a(k) = 2/T * integral(@(t)(fc(t,T).*cos(k*omega0*t)),0,T);
b(k) = 2/T * integral(@(t)(fc(t,T).*sin(k*omega0*t)),0,T);
if abs(a(k))<10^-10
a(k) = 0;
end
if abs(b(k))<10^-10
b(k) = 0;
end

4
% We determine the amplitude of the k-th harmonic
A(k+1) = sqrt(a(k)^2+b(k)^2);
% We determine the phase of the k-th harmonic
if a(k)==0 && b(k)==0
% If both ak and bk are 0 then the phase will be 0
phi(k+1) = 0;
else
% We determine the phase according to ak’s sign
% The function atan() is arctangent expressed in radians, if we
% want to determine the angle in degrees we should use atand()
if a(k)>=0
phi(k+1) = -atan(b(k)/a(k));
else
phi(k+1) = -atan(b(k)/a(k))-pi;
end
end
end

% We display the amplitude and phase spectrum


figure(1);
subplot(2,1,1);
stem((0:N)*omega0,A);
xlabel('Frequency [rad/s]');
ylabel('Amplitudes A_k');
title('Amplitude spectrum');

subplot(2,1,2);
stem((0:N)*omega0,phi);
xlabel('Frequency [rad/s]');
ylabel('Phase \phi_k');
title('Phase spectrum');

4. The complex Fourier series

For any periodic signal f (t )  f (t  T ), t  , with the period, we can express the complex
Fourier series as follows:

f (t )   C  n   e
n 
0
jn0t
(1.9)

The coefficients can be determined by using the formula:


1
C  n0    f (t )  e jn0t dt (1.10)
TT

We can also determine the complex Fourier series coefficients from the trigonometric or
harmonic series as follows:
an b
C  n0    j n ,n 1 (1.11)
2 2
a0
C  0  (1.12)
2

5
An
C  n0   ,n 1 (1.13)
2

arg C  n0   n , n  1 (1.14)

For the negative frequencies, if f (t )  , we can use the theorem:

C  n0   C*  n0  (1.15)

Next we will determine the complex Fourier series by using the formula (1.10).
Useful Matlab functions and constants:
1j % the complex unit j = sqrt(-1)
real(x) % returns the real part of the complex number x
imag(x) % returns the imaginary part of the complex number x
abs(x) % returns the absolute value for the complex number x
angle(x) % returns the argument in radians for the complex number x

The code for determining the complex Fourier series is:


%% Determining the complex Fourier series
N = 100;
C = zeros(1,2*N+1);
% The vector C() will contain the complex Fourier series coefficients
% for frequencies from -N*omega0 to N*omega0, which means that the vector
% will have 2*N+1 values
for n=-N:N
% we determine the complex coefficients
C(n+N+1) = 1/T * integral(@(t)fc(t,T).*exp(-1j*n*omega0*t),0,T);
% This time we must check that the values for the real or imaginary
% are very small but not 0. Again we will apply a threshold
re = real(C(n+N+1));
im = imag(C(n+N+1));
if abs(re)<10^-10
re = 0;
end
if abs(im)<10^-10
im = 0;
end
% After we adjust the values that are very close to 0 we reconstruct the
% complex number from the real and imaginary part
C(n+N+1)=re+1j*im;
end

% We display the frequency amplitude and phase spectrum


figure(2);
subplot(2,1,1);
stem((-N:N)*omega0,abs(C));
xlabel('Frequency \omega [rad/s]');
ylabel('Amplitudes |C(n\omega_0)|');
title('Amplitude spectrum');

subplot(2,1,2);
stem((-N:N)*omega0,angle(C));
xlabel('Frequency \omega [rad/s]');
ylabel('Phases arg\{C(n\omega_0)\}');
title('Phase spectrum');

6
5. Power and bandwidth of periodic signals
The total power for a periodic signal can be determined with the formula:
1
f  t  dt
2
Pt 
TT (1.16)

If the signal is real, we can also determine the total power by using the trigonometri, harmonic
or complex Fourier series coefficients:
 

a2  ak2  bk2 A 2
k 
Pt  0   A02   C 2 0  2 C (n0 )
k 1 k 1 2
(1.17)
4 2 2 k 1

The bandwidth for a periodic signal is defined as the frequency range in which the coefficients
are different from zero. For most periodic signals the bandwidth is infinite, Bw   0,   , however in
practice one cannot work with infinity. For this reasons, the energetic bandwidth was introduced as
the frequency interval where 99% of the total power is concentrated.
In order to determine the energetic bandwidth first we have to determine the total power and
then compute P99  0.99 Pt . The last part is achived by considering as many components as necessary
so that we reach P99 :
N
Ak2
PN  A02   (1.18)
k 1 2

Therefore we must find the smallest value for N so that PN  P99 .

The Matlab code that determines the power and the energetic bandwidth for a periodic signal
is:
% Total power
Pt = 1/T*integral(@(t)fc(t,T).^2,0,T)
% 99% of the total power
P99 = 0.99*Pt
% We add the power of the DC component
PN = A(1)^2;
k = 1;
start = 0;

while PN<P99
% if in the beginning the power is 0 this means that the DC component is
% 0 so we must shift the starting point of the energetic bandwidth
% interval
if PN==0;
start = k;
end
PN = PN + A(k+1)^2/2;
k = k+1;
end
stop = k-1;

% The energetic bandwidth will be from start*omega0 to stop*omega0


% disp() is a function that prints a string in the command window, and
7
% num2str() converts a number to string. To concatenate a set of strings
% we use [str1 str2 … strN]
disp(['EB = [' num2str(start*omega0) ',' num2str(stop*omega0) '] (rad/s)']);
disp(['EB = [' num2str(start*omega0/(2*pi)) ',' num2str(stop*omega0/(2*pi)) ']
(Hz)']);

6. The effect of clipping on periodic signals


In most electronic circuits signals are amplified by using transistors and a common effect
appears when the amplification is high and the transistors enter the saturation zone, which translates
in a clipped (limited) signal.
We will further understand the effect of clipping on periodic signals by inspecting the amplitude
spectrum of the signals affected by clipping.
First we will create a function that returns a sine signal that has been clipped to a certain value:
function y = clipped_sine(t,T,clip)
% The function returns a clipped sine signal
% The parameters are:
% t - vector for the time base
% T - the period for the sine signal
% clip - the amplitude at which the signal is clipped
omega0 = 2*pi/T;
y = sin(omega0*t);
for i=1:length(y)
if abs(y(i))>clip
y(i)=clip * sign(y(i));
end
end

An alternative solution for the clipped sine function is:


function y = clipped_sine(t,T,clip)
% The function returns a clipped sine signal
omega0 = 2*pi/T;
y = sin(omega0*t);
y(y>clip) = clip;
y(y<-clip) = -clip;

end
Next we will see what is the effect of different clip values on the harmonic Fourier series. The
code for displaying the clipped sine and the spectrum is as follows:
Clip = 0.5;
figure(1);
subplot(3,1,1);
plot(t,clipped_sine(t,T,clip));
axis([min(t), max(t), -1, 1]);
xlabel('Time [s]');
ylabel('Amplitude');
title('The clipped signal');

subplot(3,1,2);
% AdB = 20*log10(A/0.001);
% AdB(find(AdB<0))=0;
stem((0:N)*omega0,A);
% axis([0, N*omega0, 0, 60]);

8
xlabel('Frequency \omega [rad/s]');
ylabel('Amplitudes A_k');
title('Amplitude spectrum');

subplot(3,1,3);
stem((0:N)*omega0,phi);
xlabel('Frecquency \omega [rad/s]');
ylabel('Phase \phi_k');
title('Phase spectrum');

We should obtain the following figures, for clip=0.5:

Figure 1. The harmonic Fourier series for a sine clipped at 0.5 of the amplitude

View the amplitude and phase spectrum for clip=1:-0.1:0.1. What happens when the signal is
further clipped?

7. Homework
A. Generate a periodic signal according to the index of the letters in the English alphabet of your
first name. As example, for the name ”VICTOR” we will have the following values for the
letter indexes:

Letter V I C T O R
Index 22 9 3 20 15 18

9
With the index values generate a periodic signal by dividing the period in equal intervals,
where the number of intervals corresponds to the number of letters in your name. Then for
each interval the amplitude will be equal to the index value of the corresponding letter. For
the previous example the signal described for one period is displayed in Figure 2.
a. Create a Matlab function which returns the periodic signal generated by your first name.
b. In another Matlab script display the periodic function on at least 3 periods and determine
the trigonometric, harmonic and complex Fourier series for at least 100 harmonics.
c. Display the amplitude and phase spectrum for the harmonic and complex Fourier series
d. Determine the total power and energetic bandwidth of the periodic signal
Note: point a. will consist of a Matlab function, points b., c. and d. can be solved in one Matlab
script. All matlab script files should be in the same folder.

Figure 2. One period of the signal generated by the name VICTOR

B. Let us consider the periodic signal xt   xt  T  , where T is the signal’s period. The signal
 t
is described over a period as xt   exp   , t  0, T .
 T
a. Design a Matlab function to generate x t 
b. In a separate script plot at least 3 periods of the signal (e.g. t   T , 2T ) and then
determine the trigonometric, harmonic and complex Fourier series for at least 100
harmonics.
c. Display the amplitude and phase spectrum for the complex Fourier series.
n 7
d. If we approximate x t  with xa t   Cn e o
 jn0t
, determine the approximation
n 7

error defined as e(t )  x(t )  xa (t ) and compute the power for the error
T
1
Pe  
2
e(t ) dt . (solve this task in the same script you designed for b. and c.)
T 0
e. Display the graphic of xa t 

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy