You are on page 1of 4

Name:

ID No:

Group:

Date:

WHERE
LAB 2
KNOWLEDGE

CONTINOUS TIME FOURIER


IS APPLIED

SERIES and FOURIER


TRANSFORM
Plotting the CTFS and CTFT of
Signal using SCILAB
OBJECTIVES:

Student should be able to;

1. Able to understand the meaning of Continous Time Fourier Series and


Fourier Transform signals.

2. Able to develop simple command using Scilab.

3. Know how to plot CTFS and CTFT signals using Scilab.

INSTRUMENTS REQUIRED:

Scilab Software version 5.5.2

Notes:

 Scilab can be downloaded here: http://www.scilab.org/download/latest


 Or install from the attached file.

0
Experiment 1:

Use SCILAB to plot the Continuous Time Fourier Series Coefficient of a periodic signal
x(t) = sin (πt).

Source Code

//To represent a function in exponential Fourier series


//Continuous Time Fourier Series Coefficient of a periodic signal x(t) = sin (πt)

clc
close
clear
V=1
t0 =1,T=1, w0 =2*3.14/T,P=1
t =0:0.01:3
f=V*abs( sin ( %pi *t)) //The Exponential Fourier series coefficient
disp ( 'The Exponential Fourier series coefficient are for n = -5 to 5' )
a=1
for n= -5:5
fr=f.* cos ( %pi *n*t/T)
Fr(a)= inttrap (t,fr)
fi=f.* sin ( %pi *n*t/T)
Fi(a)= inttrap (t,fi)

mag (a)=abs(Fr(a)+%i*Fi(a))

disp (Fr(a) -(%i*Fi(a)))


x(1 ,size (t ,2))=0
x=x+(( Fr(a))-%i*Fi(a)) .*( cos( %pi *n*t/T)+%i* sin (%pi *n*t/T))
a=a+1
end
n= -5:5
subplot (2 ,1 ,1) , plot2d (t,f, style =5) // Rectified sine function Plot
xlabel (" t " , "fontsize" , 2);
ylabel (" sin (πt) " , " fontsize " , 3, "color" , "blue");
title ( 'NAME and ID Number' )
subplot (2 ,1 ,2) ,plot2d3 (n,mag ,12 , rect =[ -11 ,0 ,11 ,1] , style =4)
//Plot of the magnitude of the Fourier coefficient
xlabel ("w" , "fontsize" , 2);
ylabel ("Fn" , "fontsize" , 3, " color " , " red ");
legends ([ "Sin (πt) ";"Exponential Fourier Coefficient" ] ,[5 ,4] , withbox =%f , opt ="ur" )

1
Experiment 2

Use SCILAB to plot the Fourier transform of a signal x(t) = cos (4πt).

Source Code

// Continuous Time Fourier Transforms


// Sinusoidal waveforms cos(4πt)
clear ;
clc ;
close ;
V=1
t0 =1,T=0.5, w0 =2*3.14/T,P=1
t =-1:0.01:1
f1=V*( cos (4* %pi *t))

T1 = 0.5;
T = 4* T1;
Wo = 2* %pi /T1;
W = [-Wo ,0, Wo ];
ak = (2* %pi *Wo*T1/ %pi )/ sqrt ( -1);
XW = [-ak ,0, ak ];
ak1 = (2* %pi*Wo*T1/%pi);
XW1 =[ ak1 ,0, ak1 ];

clf ();
a = gca();
a.y_location ="origin";
a.x_location ="origin";

function set_my_line_styles(style, thickness)


e = gce ();
e.children.line_style = style;
e.children.thickness = thickness;
endfunction

subplot (211);
plot2d (t, f1,5);
set_my_line_styles(1,3);
xlabel ("t" , "fontsize" , 3);
title ("Cos(4πt) " , " fontsize " , 7, "color" , "red")

//**********************************************************************
subplot(212);
plot2d3 ('gnn',W,XW1,2,style =6) ;
set_my_line_styles(1,3);
xlabel ( 'W in rad/sec' );
ylabel ("X(w) " , " fontsize " , 3, "color" , "blue");
title ( 'NAME and ID Number'," fontsize " , 7, "color" , "green" )
legends ( "CTFT of cos(4πt)" ,[2 ,6] , withbox =%f , opt ="ur" )

2
Write a comment and conclusion from the results of experiment 1 and 2

You might also like