Professional Documents
Culture Documents
Student Id No:150050085
Remarks:
usefulness of such series is that any periodic function x(t ) with period T can be written
as a Fourier series as illustrated below.
Basic theory: The basic formulations for Fourier series is illustrated below.
1. Trigonometrical Fourier Series Representation:
The trigonometrical Fourier series is represented by
x(t ) a 0 a1 cos 0t a 2 cos 2 0t a 3 cos 3 0t . . . . .
b1 sin 0t b2 sin 2 0t b3 sin 3 0t . . . . .
a 0 a n cos n 0t bn sin n 0t
n 1
1
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
b
Phase spectrum n tan 1 a
n
n
2. Exponential Fourier Series:
The exponential Fourier series is represented by
x(t ) c n e jn 0t
n
The exponential Fourier series coefficients c n can be represented in terms of magnitude
conjugate.
figure(1);
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':b','LineWidth',3);
xlabel('time (seconds)');
ylabel('Amplitude');
title('Original square wave signal');
axis([-1 3 -1.2 1.2]);
%-----------------------------------------------------------------------
% Parameters
N = 11; % summation limit (use N odd)
2
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
figure(2);
subplot(2,2,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
N = 5;
x = c0*ones(size(t)); % initialize yt to c0
subplot(2,2,2)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'b','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
N = 11;
x = c0*ones(size(t)); % initialize yt to c0
subplot(2,2,3)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
3
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
N = 21;
x = c0*ones(size(t)); % initialize yt to c0
subplot(2,2,4)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'m','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
Original square wave signal
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
4
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
0.5 0.5
y(t)
y(t)
0 0
-0.5 -0.5
-1 -1
-2 0 2 -2 0 2
t (seconds) t (seconds)
Trig. Fourier Series with N = 11 Trig. Fourier Series with N = 21
1 1
0.5 0.5
y(t)
y(t)
0 0
-0.5 -0.5
-1 -1
-2 0 2 -2 0 2
t (seconds) t (seconds)
figure();
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,xr,':','LineWidth',3);
xlabel('time (seconds)');ylabel('Amplitude');
title('Original sawtooth signal');
axis([-1 2 -0.1 1.2]);
5
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
y = y + real(cn * exp(j*n*2*pi*t));
end;
figure();
subplot(2,2,1); % plot approximation
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(t,y,'r','LineWidth',2); hold on;
plot(tr,xr,':','LineWidth',1);
xlabel('time (seconds)');
ylabel('y(t) approximation');
title('Truncated FS, N = 1');
axis([-1 2 -0.1 1.2]);
6
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
end;
% compute y for positive n and add to y
for n = 1:N, % found using negative n
cn = exp(j*pi/2)/(2*pi*n);
y = y + real(cn * exp(j*n*2*pi*t));
end;
7
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
0.8
Amplitude
0.6
0.4
0.2
1 1
y(t) approximation
y(t) approximation
0.5 0.5
0 0
-1 0 1 2 -1 0 1 2
time (seconds) time (seconds)
Truncated FS, N = 3 Truncated FS, N = 10
1 1
y(t) approximation
y(t) approximation
0.5 0.5
0 0
-1 0 1 2 -1 0 1 2
time (seconds) time (seconds)
figure(1);
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':r','LineWidth',3);
xlabel('time (seconds)');
ylabel('Amplitude');
8
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
%-----------------------------------------------------------------------
% Parameters
N = 11; % summation limit (use N odd)
wo = pi; % fundamental frequency (rad/s)
c0 = 0; % dc bias
t = -3:0.01:3; % declare time values
subplot(2,1,1)
xlabel('w (rad/s)')
9
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
ylabel('|cn|')
ttle = ['Amplitude Spectrum with N = ',num2str(N)];
title(ttle); grid on
subplot(2,1,2)
stem(0,angle(c0)*180/pi,'k','fill','LineWidth',2); % plot angle of c0 at nwo = 0
hold on ;
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid;
10
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
0.8
0.6
0.4
0.2
y(t)
-0.2
-0.4
-0.6
-0.8
-1
-3 -2 -1 0 1 2 3
t (seconds)
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
11
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
0.6
|cn|
0.4
0.2
0
-40 -30 -20 -10 0 10 20 30 40
w (rad/s)
Phase Spectrum with N = 11
100
angle(cn) (degrees)
50
-50
-100
-40 -30 -20 -10 0 10 20 30 40
w (rad/s)
(a)Study and understand the basic theory required for this lab.
(b) Run the Matlab scripts given for examples and study the results.
(c)Perform the analytical solutions for the given laboratory exercises.
(d) Prepare the Matlab codes for the given laboratory exercises well before the
commencement of lab scheduled time. Discuss with your lab instructors.
Lab Exercise-7
Exercise 7.1: Consider a periodic square wave (odd signal) shown below.
Justify that the trigonometrical and exponential Fourier series are represented as below.
Trigonometrical Fourier Series Coefficients: The mathematical equations for given
signal can be written as
A, 0t T
2
x(t )
T
A, 2
t T
The given signal is odd signal and have rotational symmetry. That is x(t ) x(t ) and
x(t T2 ) x(t ) . Therefore the Fourier series coefficients consists only odd harmonics.
12
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
a 0 0, a n 0, bn 4 A , n odd
n
Then the Trigonometrical Fourier Series is represented by
4A 1 1 1
x(t ) sin 0t sin 3 0t sin 5 0t sin 7 0t . . . .
3 5 7
Similarly, the exponential Fourier coefficients are represented by
0, n even
cn j2 A
n , n odd
Then the Fourier synthesis is represented by
j2 A j2A j2A j2A
x(t ) 5 e j 5ω0t 3 e j 3ω0t e jω0t e jω0t
j2 A j2A
3 e j 3ω0t 5 e j 5ω0t
Let A 1 , T 1 . Develop Matlab code to determine and plot the magnitude and phase
%-----------------------------------------------------------------------
% Parameters
N = 1; % summation limit (use N odd)
wo = pi; % fundamental frequency (rad/s)
c0 = 0; % dc bias
t = -1:0.001:1; % declare time values
13
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
figure(2);
subplot(3,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-1.5 1.5 -2.5 2.5]);
N = 5;
x = c0*ones(size(t)); % initialize yt to c0
subplot(3,1,2)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'b','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-1.5 1.5 -1 1]);
N = 13;
x = c0*ones(size(t)); % initialize yt to c0
subplot(3,1,3)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'r','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-1.5 1.5 -1 1]);
% Draw the amplitude spectrum from exponential Fourier Series for n=1
subplot(2,1,1)
N=1;
stem(0,c0,'r','fill','LineWidth',2); hold on; % plot c0 at nwo = 0
14
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
xlabel('w (rad/s)')
ylabel('|cn|')
ttle = ['Amplitude Spectrum with N = ',num2str(N)];
title(ttle); grid on
subplot(2,1,2)
stem(0,angle(c0)*180/pi,'k','fill','LineWidth',2); % plot angle of c0 at nwo = 0
hold on ;
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid;
% Draw the amplitude spectrum from exponential Fourier Series for n=5
subplot(2,1,1)
N=5;
stem(0,c0,'r','fill','LineWidth',2); hold on; % plot c0 at nwo = 0
xlabel('w (rad/s)')
ylabel('|cn|')
ttle = ['Amplitude Spectrum with N = ',num2str(N)];
title(ttle); grid on
15
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
subplot(2,1,2)
stem(0,angle(c0)*180/pi,'k','fill','LineWidth',2); % plot angle of c0 at nwo = 0
hold on ;
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid;
% Draw the amplitude spectrum from exponential Fourier Series for n=13
subplot(2,1,1)
N=13;
stem(0,c0,'r','fill','LineWidth',2); hold on; % plot c0 at nwo = 0
xlabel('w (rad/s)')
ylabel('|cn|')
ttle = ['Amplitude Spectrum with N = ',num2str(N)];
title(ttle); grid on
subplot(2,1,2)
stem(0,angle(c0)*180/pi,'k','fill','LineWidth',2); % plot angle of c0 at nwo = 0
hold on ;
16
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid;
0.5
Amplitude
-0.5
-1
-1.5
-1 -0.5 0 0.5 1 1.5 2
time (seconds)
-2
-1.5 -1 -0.5 0 0.5 1 1.5
t (seconds)
Trig. Fourier Series with N = 5
1
y(t)
-1
-1.5 -1 -0.5 0 0.5 1 1.5
t (seconds)
Trig. Fourier Series with N = 13
1
y(t)
-1
-1.5 -1 -0.5 0 0.5 1 1.5
t (seconds)
17
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
0.5
|cn| 0
-0.5
-1
-4 -3 -2 -1 0 1 2 3 4
w (rad/s)
Phase Spectrum with N = 1
1
angle(cn) (degrees)
0.5
-0.5
-1
-4 -3 -2 -1 0 1 2 3 4
w (rad/s)
0.6
|cn|
0.4
0.2
0
-20 -15 -10 -5 0 5 10 15 20
w (rad/s)
Phase Spectrum with N = 5
200
angle(cn) (degrees)
150
100
50
0
-20 -15 -10 -5 0 5 10 15 20
w (rad/s)
18
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
0.6
|cn| 0.4
0.2
0
-50 -40 -30 -20 -10 0 10 20 30 40 50
w (rad/s)
Phase Spectrum with N = 13
200
angle(cn) (degrees)
150
100
50
0
-50 -40 -30 -20 -10 0 10 20 30 40 50
w (rad/s)
Exercise 7.2: Develop Matlab code to determine and plot the magnitude and phase
spectrum for the various number of coefficients, both in trigonometrical and exponential
Fourier series for the following continuous time periodic signals. Assume A 1 , T 1
figure(1);
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':b','LineWidth',3);
xlabel('time (seconds)');
ylabel('Amplitude');
title('Original square wave signal');
axis([-1 3 -1.2 1.2]);
%-----------------------------------------------------------------------
% Parameters
N = 11; % summation limit (use N odd)
wo = pi; % fundamental frequency (rad/s)
19
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
c0 = 0; % dc bias
t = -3:0.01:3; % declare time values
figure(2);
subplot(2,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
N = 5;
subplot(2,1,2)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'b','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
N = 11; % initialize yt to c0
for n = 1:2:N, % loop over series index n (odd)
cn = 2/(j*n*wo); % Fourier Series Coefficient
x = 2*abs(cn)*cos(n*wo*t+angle(cn)); % Fourier Series computation
end
figure(3)
subplot(2,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-2 2 -1 1]);
20
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
N = 21; % initialize yt to c0
for n = 1:2:N, % loop over series index n (odd)
cn = 2/(j*n*wo); % Fourier Series Coefficient
x = 2*abs(cn)*cos(n*wo*t+angle(cn)); % Fourier Series computation
end
subplot(2,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1 1]);
%-------------------------------------------exponential ft
N = 1; % define number of terms to use (n = -N..N)
c0 = 0.5; % define dc bias coefficient
t = -1:0.001:2; % define time values for y(t)
y = c0 * ones(size(t)); % let initial y = c0 (dc bias) for all times
figure(3);
subplot(2,1,1); % plot approximation
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(t,y,'r','LineWidth',2); hold on;
plot(tr,yr,':','LineWidth',1);
xlabel('time (seconds)');
ylabel('y(t) approximation');
title('Truncated FS, N = 1');
axis([-1 2 -1 1]);
N = 2; % define number of terms to use (n = -N..N)
c0 = 0.5; % define dc bias coefficient
t = -1:0.001:2; % define time values for y(t)
y = c0 * ones(size(t)); % let initial y = c0 (dc bias) for all times
21
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
subplot(2,1,1)
xlabel('w (rad/s)')
ylabel('|cn|')
ttle = ['Amplitude Spectrum with N = ',num2str(N)];
title(ttle); grid on
subplot(2,1,2)
stem(0,angle(c0)*180/pi,'k','fill','LineWidth',2); % plot angle of c0 at nwo = 0
hold on ;
22
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid on;
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0.5
y(t)
-0.5
-1
-3 -2 -1 0 1 2 3
t (seconds)
Trig. Fourier Series with N = 5
0.5
y(t)
-0.5
-1
-3 -2 -1 0 1 2 3
t (seconds)
23
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
Truncated FS, N = 1
1
y(t) approximation
0.5
-0.5
-1
-1 -0.5 0 0.5 1 1.5 2
time (seconds)
Truncated FS, N = 2
1
y(t) approximation
0.5
0
-1 -0.5 0 0.5 1 1.5 2
time (seconds)
0.6
|cn|
0.4
0.2
0
-8 -6 -4 -2 0 2 4 6 8
w (rad/s)
Phase Spectrum with N = 2
100
angle(cn) (degrees)
50
-50
-100
-8 -6 -4 -2 0 2 4 6 8
w (rad/s)
(b)
tr = [-3,-2.5,-2,-1.5,-1,-0.5,0, 0.5,1, 1.5,2, 2.5,3];
yr = [ 0,-1, 0, 1, 0,-1, 0, 1, 0, -1, 0, 1, 0];
figure(1);
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':b','LineWidth',3);
xlabel('time (seconds)');
ylabel('Amplitude');
title('Original square wave signal');
axis([-1 3 -1.2 1.2]);
24
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
%-----------------------------------------------------------------------
% Parameters
N = 11; % summation limit (use N odd)
wo = pi; % fundamental frequency (rad/s)
c0 = 0; % dc bias
t = -3:0.01:3; % declare time values
figure(2);
subplot(2,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
N = 5;
subplot(2,1,2)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'b','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1.2 1.2]);
N = 11; % initialize yt to c0
for n = 1:2:N, % loop over series index n (odd)
cn = 2/(j*n*wo); % Fourier Series Coefficient
x = 2*abs(cn)*cos(n*wo*t+angle(cn)); % Fourier Series computation
end
figure(3)
subplot(2,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
25
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-2 2 -1 1]);
N = 21; % initialize yt to c0
for n = 1:2:N, % loop over series index n (odd)
cn = 2/(j*n*wo); % Fourier Series Coefficient
x = 2*abs(cn)*cos(n*wo*t+angle(cn)); % Fourier Series computation
end
subplot(2,1,1)
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(tr,yr,':','LineWidth',2);hold on; % plot truncated trigonometric FS
plot(t,x,'k','LineWidth',2);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Trig. Fourier Series with N = ',num2str(N)];
title(ttle);axis([-3 3 -1 1]);
%-------------------------------------------exponential ft
N = 1; % define number of terms to use (n = -N..N)
c0 = 0.5; % define dc bias coefficient
t = -1:0.001:2; % define time values for y(t)
y = c0 * ones(size(t)); % let initial y = c0 (dc bias) for all times
figure(3);
subplot(2,1,1); % plot approximation
plot(tr,zeros(size(tr)),'k','LineWidth',1); hold on;
plot(zeros(size(tr)),tr,'k','LineWidth',1); hold on;
plot(t,y,'r','LineWidth',2); hold on;
plot(tr,yr,':','LineWidth',1);
xlabel('time (seconds)');
ylabel('y(t) approximation');
title('Truncated FS, N = 1');
axis([-1 2 -1 1]);
N = 2; % define number of terms to use (n = -N..N)
c0 = 0.5; % define dc bias coefficient
t = -1:0.001:2; % define time values for y(t)
y = c0 * ones(size(t)); % let initial y = c0 (dc bias) for all times
26
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
subplot(2,1,1)
xlabel('w (rad/s)')
ylabel('|cn|')
ttle = ['Amplitude Spectrum with N = ',num2str(N)];
title(ttle); grid on
subplot(2,1,2)
stem(0,angle(c0)*180/pi,'k','fill','LineWidth',2); % plot angle of c0 at nwo = 0
hold on ;
27
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid on;
Original square wave signal
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0.5
y(t)
-0.5
-1
-3 -2 -1 0 1 2 3
t (seconds)
Trig. Fourier Series with N = 5
1
0.5
y(t)
-0.5
-1
-3 -2 -1 0 1 2 3
t (seconds)
28
Signal Analysis Lab, Dept. of ECE, KL University, A.P., India. Student Id No:150050085
Truncated FS, N = 1
1
y(t) approximation
0.5
-0.5
-1
-1 -0.5 0 0.5 1 1.5 2
time (seconds)
Truncated FS, N = 2
1
y(t) approximation
0.5
0
-1 -0.5 0 0.5 1 1.5 2
time (seconds)
0.6
|cn|
0.4
0.2
0
-8 -6 -4 -2 0 2 4 6 8
w (rad/s)
Phase Spectrum with N = 2
100
angle(cn) (degrees)
50
-50
-100
-8 -6 -4 -2 0 2 4 6 8
w (rad/s)
29