Professional Documents
Culture Documents
SNS Lab 10 19-Ee-0
SNS Lab 10 19-Ee-0
SUBMITED TO
Engr. Hammad Haider
SUBMITED BY
Muhammad Uzair Shafique
MATLAB CODE:
%uzair Shafique
%19-EE-18
clc;
clear all;
t= 0:0.01:10;
w0= 2*pi;
x= cos(w0*t);
subplot(3,2,1);
plot(t,x,'r','linewidth',3);
xlabel('time');
ylabel('cos(w0*t)');
title('Time domain representation');
grid;
w= -length(t)/2:length(t)/2-1;
y= fftshift(fft(x)/length(x));
subplot(3,2,2);
stem(w+1/2,abs(y),'linewidth',2);
grid;
axis([-10 10 0 1.5]);
xlabel('Frequency(Hz)');
ylabel('Magnitude Response');
title('Frequency Domain Representation');
Y= sin(w0*t);
subplot(3,2,3);
plot(t,Y,'r','linewidth',3);
xlabel('time');
ylabel('sin(w0*t)');
title('Time domain representation');
grid;
w= -length(t)/2:length(t)/2-1;
y= fftshift(fft(Y)/length(Y));
subplot(3,2,4);
stem(w+1/2,abs(y),'linewidth',2);
grid;
axis([-10 10 0 1.5]);
xlabel('Frequency(Hz)');
ylabel('Magnitude Response');
title('Frequency Domain Representation');
Z= sin(w0*t).*cos(w0*t);
subplot(3,2,5);
plot(t,Z,'r','linewidth',3);
xlabel('time');
ylabel('z(t)');
title('Time domain representation');
grid;
w= -length(t)/2:length(t)/2-1;
y= fftshift(fft(Z)/length(Z));
subplot(3,2,6);
stem(w+1/2,abs(y),'linewidth',2);
grid;
axis([-10 10 0 1.5]);
xlabel('Frequency(Hz)');
ylabel('Magnitude Response');
title('Frequency Domain Representation');
suptitle('19-EE-18');
OUTPUT:
19-EE-18
1
19-EE-18
Tasks 2:
Write the use of following commands?
• fftshift
• fft
• abs
• length
fftshift
fftshift rearranges a Fourier transform by shifting the zero-frequency component
to the center of the array.
Y = fftshift ( X ) If X is a vector, then fftshift swaps the left and right halves of X . If X
is a matrix, then fftshift swaps the first quadrant of X with the third, and the
second quadrant with the fourth.
Fft
It computes the Fourier transform (FT) of X using a fast Fourier transform (FFT)
algorithm.
Y = fft( X ) If X is a vector, then fft(X) returns the Fourier transform of the vector. If
X is a matrix, then fft(X) treats the columns of X as vectors and returns the Fourier
transform of each column.
Abs
Y = abs( X ) return the absolute value of each element in array X . If X is complex,
abs(X) return the complex magnitude.
Length
length (MATLAB Functions) The statement length(X) is equivalent to max(size(X))
for nonempty arrays and 0 for empty arrays. n = length(X) returns the size of the
longest dimension of X . If X is a vector, this is the same as its length.