Lab Report 2 Zaryab Rauf Fa17-Ece-046
Lab Report 2 Zaryab Rauf Fa17-Ece-046
Lab Report 2 Zaryab Rauf Fa17-Ece-046
150
100
50
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-100
-200
-300
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Task-2:
Write a Matlab function “sigshift” for producing a delay of ‘k’ in a given
sequence ‘x[n]’ defined by arrays “x” and “n” by using the pseudo code
given in In-Lab Work section. Your function should yield y[n] = x[n-k].
Function [y, n] =sigshift (x, n, k)
WITH K=3
WITH K=-3
Task-3:
Write a Matlab function “sigfold” for folding a given sequence ‘x[n]’
defined by arrays “x” and “n” by using the pseudo code given in In-Lab
Work section.
Function [y, n] =sigfold (x, n)
function [ y,n ] =SigFold(x,n)
n = -3:3;
n1 = -n;
subplot(2,1,1)
stem(n,x)
subplot(2,1,2)
stem(n1,x)
end
Command Window:
>> x = [1 2 3 4 5 6 7];
>> SigFold(x,n)
8
0
-3 -2 -1 0 1 2 3
0
-3 -2 -1 0 1 2 3
Task-4:
Write a Matlab function “sigadd” for adding two sequences x1[n] and
x2[n] by using the pseudo code given in In-Lab Work section.
Function [y, n] =sigadd (x1, n1, x2, n2)
Command window:
>> x1 = 0:5
>> x2 = 2:7
>> n1=0:5
>> n2=0:5
>> SigAdd(x1,n1,x2,n2)
12
10
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Task-5:
Let x(n) {1, 2,3, 4,5,6,7,6,5, 4,3, 2,1}
the following sequences
Determine and plot
a. x1 (n) 2 x (n 5) 3x (n 4)
b. x2 (n) x(3 n) x(n) x(n 2)
a)
clc
close all
clear all
x = [1 2 3 4 5 6 7 6 5 4 3 2 1];
l = length(x)
n = 1:1:l+5;
y = [0 0 0 0 0];
x1 = 2.*[y x];
x2 = 3.*[x y];
x3 = x1-x2;
stem(n-5,x3)
10
-5
-10
-15
-20
-4 -2 0 2 4 6 8 10 12 14
b)
clc
close all
clear all
x = [1 2 3 4 5 6 7 6 5 4 3 2 1];
l = length(x)
n = 1:1:l+3;
x1 = [0 0 0 x];
x2 = [0 0 x];
x3 = [x 0 0];
x4 = x2.*x3;
maxlength = max([length(x1),length(x4)])
x1(length(x1)+1:maxlength) = 0;
x4(length(x4)+1:maxlength) = 0;
x5 = x1+x4;
stem(n-3,x5)
45
40
35
30
25
20
15
10
0
-2 0 2 4 6 8 10 12 14
CRITICAL ANALYSIS:
In this lab the following was learned: