0% found this document useful (0 votes)
59 views

Mindanao State University

This document contains the prelab assignments for Experiment 1 of the ECE 130 course at Mindanao State University in 2010. The prelab assignments cover topics related to the Fourier transform, including generating time sequences and signals, taking the Fourier transform of various signals using MATLAB, and analyzing the frequency spectra obtained from the Fourier transforms. Code snippets are provided for generating signals, applying the Fourier transform, and plotting the resulting magnitude and phase spectra. The document includes descriptions and figures for signals such as impulses, square waves with varying duty cycles, and signals with added noise. It also explores the effects of varying the number of data points and sampling frequency on the Fourier transform results.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Mindanao State University

This document contains the prelab assignments for Experiment 1 of the ECE 130 course at Mindanao State University in 2010. The prelab assignments cover topics related to the Fourier transform, including generating time sequences and signals, taking the Fourier transform of various signals using MATLAB, and analyzing the frequency spectra obtained from the Fourier transforms. Code snippets are provided for generating signals, applying the Fourier transform, and plotting the resulting magnitude and phase spectra. The document includes descriptions and figures for signals such as impulses, square waves with varying duty cycles, and signals with added noise. It also explores the effects of varying the number of data points and sampling frequency on the Fourier transform results.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

ECE 130

EXPERIMENT 1:
THE FOURIER TRANSFORM

2010

MINDANAO STATE UNIVERSITY

PRELAB 1.1
1.

2.
-As she use the linspace command in
generating time
Sequence same plot is obtained.
- The value of the last element for the
time sequence is 7.0711V

PRELAB 1.2
1.) number of data points(DS) = time period / sampling time.

a.)Using the command


plot (Y) the commands
b.)Using
plot ( abs ( Y ) )

To define the x- and y-axis in order


to see the plot in detail:

Using command:
plot ( abs ( fftshift ( Y ) ) )

Using commands:
>> L = length ( Y ) ;
>> x = 100 * ( ( 0 : L-1 ) / L - .5 ) ;
>> plot ( x, fftshift ( abs ( Y ) ) )

Instead of using fftshift, we must define the xaxis


in the following way:
>> f = 100 * ( ( 0 : L/2-1 ) / L ) ;
>> Y = fft ( y, 512 ) ;
>> plot ( f, abs ( Y ( 1 : L/2 ) ))

Using commands
plot ( f, 20 * log10 ( abs ( Y ( 1 : L/2 ) ) ) )

2) Generate the following signal and plot its frequency spectrum.


Determine the appropriate sampling rate and find the significant signal frequency of the
waveform from the FFT.
y(t) = 1.5sin(2p*50*t) + 5cos(2p*100*t) + 3sin(2p*200*t) ,
0 t 0.1 sec
Using the matlab codes below:
t=0:.00001:.1;
y = 1.5.*sin(2*pi*50*t) + 5.*cos(2*pi*100*t) + 3.*sin(2*pi*200*t);
Y = fft (y, 512);
plot (Y);%refer figure1_2(2_1)
plot ( abs ( Y ) );%refer figure 1_2(2_2)
%plot the
%magnitude of the FFT by using MatLab's abs function:
axis ( [ 0 20 0 1300 ] )%%refer figure 1_2(2_3)
%To define the x- and y-axis in order
%to see the plot in detail:
%Plot the magnitude using the fftshift function to move the dc component to
the center of the
%display:
plot ( abs ( fftshift ( Y ) ) )%%refer figure 1_2(2_4)
%Create a separate vector that
%contains frequencies (in units of KHz) for the x-axis as follows:
L = length ( Y ) ;
x = 100 * ( ( 0 : L-1 ) / L - .5 ) ;
%instead of using fftshift, you must define the x-axis
%in the following way:
plot ( x, fftshift ( abs ( Y ) ) )%refer figure 1_2(2_5)
f = 100 * ( ( 0 : L/2-1 ) / L ) ;
Y = fft ( y, 512 ) ;
plot ( f, abs ( Y ( 1 : L/2 ) ))%refer figure 1_2(2_6)
plot ( f, 20 * log10 ( abs ( Y ( 1 : L/2 ) ) ) )%refer figure 1_2(2_7)
%To see the
%magnified data of magnitude:

Figures:
figure1_2(2_1)

figure1_2(2_12)

figure1_2(2_3)

figure1_2(2_4)

figure1_2(2_5)

figure1_2(2_6)

figure1_2(2_7)

Prelab 1.3: The Frequency Spectrum of an Impulse


Unit impulse signal: x = [1 0 0 0 0 0 0 0] corresponds to mathematical definition:
1) Using the Matlab built-in function fft to see DFTs, plot the magnitude of a DFT.
The steps below illustrate how to plot the magnitude. Start by creating a vector x with N = 8
points. You do not need to take the frequency range for the x-axis into consideration when
you plot the FFT of the impulse for this procedure.
x = [1 0 0 0 0 0 0 0]
plot ( x )%referto figure1_3(1_1)
X = fft ( x )
X = fftshift ( X )
%Use the Matlab function stem to display discrete data. If you just use the command plot,
then
%the impulse looks like triangular pulse.
plot ( abs ( X ) )%refer to figure1_3(1_2)
stem ( abs ( X ) )%refer to figure1_3(1_3)
%2) You can use the Matlab function ifft to reconstruct the time domain signal.
%The usage of ifft is similar to that of fft:
X = fft ( x )
xi = ifft ( X )
stem ( real ( xi ) )%refer to figure1_3(2_1)
%3)Repeat steps 1) and 2) for input signals which are
%a) all ones: x = [ 1 1 1 1 1 1 1 1 ] ;
%b) shifted impulse: x = [ 0 0 0 1 0 0 0 0 ] ;
%c) three point boxcar: x = [ 1 1 1 0 0 0 0 0 ] ;
%d) symmetric boxcar: x = [ 1 1 0 0 0 0 1 1 ] ;
x = [ 1 1 1 1 1 1 1 1 ]
plot ( x )%refer to figure1_3(3_1)
X = fft ( x )
X = fftshift ( X )
plot ( abs ( X ) )%refer to figure1_3(3_2)
stem ( abs ( X ) )%refer to figure1_3(3_3)
X = fft ( x )
xi = ifft ( X )
stem ( real ( xi ))%refer to figure1_3(3_4)
subplot ( 211 )
stem ( x )
subplot ( 212 )
stem (abs ( X ) )%refer to figure1_3(3_5)

FIGURES
figure1_3(1_1)

figure1_3(1_2)

figure1_3(2_1)
figure1_3(1_3)

figure1_3(3_1)

figure1_3(3_2)

figure1_3(3_3)

figure1_3(3_4)

figure1_3(3_5)

Pre-Lab 1.4
ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) + 0.2 * randn (1, length (t)) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) + 0.2 * randn (1, length (t)) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))
axis ([ 0 20 0 1300 ])
plot (abs ( fftshift (Y)))
L = length (Y);
x = 100 * ((0:L-1)/L-.5);
plot (x, fftshift (abs(Y)))
f = 100 * ((0 : L/2-1)/L);
Y = fft (yt,512);
plot (f, abs (Y (1:L/2)))
plot (f, 20 * log10(abs(Y(1:L/2))))

Pre-Lab 1.4 2
ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;

fo = 1000;
duty = 20;
yt = 5 * square ( 2 * pi * fo * t , duty)+ 0.2 * randn (1, length (t))
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
duty = 20;
yt = 5 * square ( 2 * pi * fo * t, duty ) + 0.2 * randn (1, length (t)) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))
axis ([ 0 20 0 1300 ])
plot (abs ( fftshift (Y)))
L = length (Y);
x = 100 * ((0:L-1)/L-.5);
plot (x, fftshift (abs(Y)))
f = 100 * ((0 : L/2-1)/L);
Y = fft (yt,512);
plot (f, abs (Y (1:L/2)))
plot (f, 20 * log10(abs(Y(1:L/2))))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
duty = 35;
yt = 5 * square ( 2 * pi * fo * t , duty)+ 0.2 * randn (1, length (t))
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
duty = 35;
yt = 5 * square ( 2 * pi * fo * t, duty ) + 0.2 * randn (1, length (t)) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))
axis ([ 0 20 0 1300 ])
plot (abs ( fftshift (Y)))
L = length (Y);
x = 100 * ((0:L-1)/L-.5);
plot (x, fftshift (abs(Y)))
f = 100 * ((0 : L/2-1)/L);
Y = fft (yt,512);
plot (f, abs (Y (1:L/2)))
plot (f, 20 * log10(abs(Y(1:L/2))))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
duty = 75;
yt = 5 * square ( 2 * pi * fo * t , duty)+ 0.2 * randn (1, length (t))
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 100) ;
fo = 1000;
duty = 75;
yt = 5 * square ( 2 * pi * fo * t, duty ) + 0.2 * randn (1, length (t)) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))
axis ([ 0 20 0 1300 ])
plot (abs ( fftshift (Y)))
L = length (Y);
x = 100 * ((0:L-1)/L-.5);
plot (x, fftshift (abs(Y)))
f = 100 * ((0 : L/2-1)/L);
Y = fft (yt,512);
plot (f, abs (Y (1:L/2)))
plot (f, 20 * log10(abs(Y(1:L/2))))

Pre-Lab 1.4 3
ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 512) ;
fo = 1000;
duty = 75;
yt = 5 * square ( 2 * pi * fo * t, duty ) + 0.2 * randn (1, length (t)) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave with AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))
axis ([ 0 20 0 1300 ])
plot (abs ( fftshift (Y)))
L = length (Y);
x = 100 * ((0:L-1)/L-.5);
plot (x, fftshift (abs(Y)))
f = 100 * ((0 : L/2-1)/L);
Y = fft (yt,512);
plot (f, abs (Y (1:L/2)))

plot (f, 20 * log10(abs(Y(1:L/2))))


xi = ifft (Y);
plot (t, real (xi))

Pre-Lab 1.4 4
ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 64) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 64) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 32) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 32) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 16) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 16) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 8) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 8) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt, 512);
plot (Y)
plot (abs (Y))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 64) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt);
xi = ifft (Y);
stem (t, real (xi))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 32) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt);
xi = ifft (Y);
stem (t, real (xi))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 16) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt);
xi = ifft (Y);
stem (t, real (xi))

ts = 0.0000001;
fs = 1 / ts;
t = linspace (0, 0.002, 8) ;
fo = 1000;
yt = 5 * square ( 2 * pi * fo * t ) ;
plot (t, yt)
axis ([0 0.002 -6 6])
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Square Wave without AWGN')
Y = fft (yt);
xi = ifft (Y);
stem (t, real (xi))

Pre-Lab 1.4 5
ts = 0.0000001;
fs = 1 / ts;
t = (0:0.000015625:0.002);%64-points for the first sequence
fo = 1000;
yt = 5 * sin ( 2 * pi * fo * t ) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Sine Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = (0:0.00003125:0.002);%32-points for the first sequence
fo = 1000;
yt = 5 * sin ( 2 * pi * fo * t ) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Sine Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = (0:0.0000625:0.002);%16-points for the first sequence
fo = 1000;
yt = 5 * sin ( 2 * pi * fo * t ) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Sine Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = (0:0.000125:0.002);%8-points for the first sequence
fo = 1000;
yt = 5 * sin ( 2 * pi * fo * t ) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Sine Wave without AWGN')

ts = 0.0000001;
fs = 1 / ts;
t = (0:0.00025:0.002);%4-points for the first sequence
fo = 1000;
yt = 5 * sin ( 2 * pi * fo * t ) ;
plot (t, yt)
xlabel ('time [sec]')
ylabel ('amplitude [volt]')
title ('1000 Hz Sine Wave without AWGN')

You might also like