0% found this document useful (0 votes)
31 views9 pages

MATLAB Lab Report on Signal Processing

The document discusses a lab report on digital signal processing. It includes tasks on decomposing a signal into even and odd components using Matlab code. It also discusses creating a custom convolution function to allow for signals with negative time indices. Critical analysis covers properties of signal decomposition and convolution.

Uploaded by

HAMZA ALI
Copyright
© © All Rights Reserved
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)
31 views9 pages

MATLAB Lab Report on Signal Processing

The document discusses a lab report on digital signal processing. It includes tasks on decomposing a signal into even and odd components using Matlab code. It also discusses creating a custom convolution function to allow for signals with negative time indices. Critical analysis covers properties of signal decomposition and convolution.

Uploaded by

HAMZA ALI
Copyright
© © All Rights Reserved
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

LAB REPORT # 3

DIGITAL SIGNALS PROCESSING


INSTRUCTOR: SIR MUBEEN SABIR
DATED: 25/10/2020

SUBMITTED BY: ZARYAB RAUF


CIIT/FA17-ECE-046/ISB | EEE-5B
TASK 1:
Write a Matlab code to decompose a sequence into its even and odd
components. Take help from Pre-Lab work.
clc
clear all;
close all;
n = -10:2:10;
x = @(n) n.*(n>=0);
xe = ( x(n)+x(-n) )/2;
xo = ( x(n)-x(-n) )/2;
subplot(3,1,1);
stem(n,x(n));
title('Original Signal')
subplot(3,1,2);
stem(n,xe);
title('Even Part')
subplot(3,1,3);
stem(n,xo)
title('Odd Part')

OUTPUT:
TASK 2:
You should have noticed that ‗conv‘ command calculates convolution
assuming both input sequences are starting from origin (i-e no values on –ve t-
axis). This is not always the case, we do have sequences which have values for
t<0. Write a code conv_m that would remove this limitation in the code conv.
function[y,x] = conv_m(x,h,n1,n2)
n= n1(1)+n2(1) : n1(end)+n2(end)
y=conv(x,h) ;
stem(n,y)
end

OUTPUT:
120

100

80

60

40

20

0
0 1 2 3 4 5 6 7 8

TASK 3:
Convolve following sequences using MATLAB Function ―conv‖ and
―conv_m‖ and plot the input, impulse response and output in one figure
using ―subplot‖:
A) X[N] = [1 2 1], N=[0 1 2] H[N] = [1 1 1], N= [0 1
2]
B) X[N] = [-1 4 -3 -2 1 0 2], N=[-2:4] H[N] = [1 1 1], N= [-1 0 1]

A)
%conv command
clc
close all
clear all
n =0:2;
x=[1 2 1]
h=[1 1 1]
a=conv(x,h)
stem(a)
OUTPUT:
4

3.5

2.5

1.5

0.5

0
1 1.5 2 2.5 3 3.5 4 4.5 5

USING conv_m function

function[y,x] = conv_m(x,h,n)
n= 0:2;
y=conv(x,h) ;
stem(y)
end
command window:
>>x = [1 2 1];
>>h = [1 1 1];
a =

-1 3 0 -1 -4 -1 3 2 2

OUTPUT:
4

3.5

2.5

1.5

0.5

0
1 1.5 2 2.5 3 3.5 4 4.5 5
B)

clc
clear all
close all
x=[-1 4 -3 -2 1 0 2];
n1=[-2:4];
h=[1 1 1];
n2=[-1 0 1];
a=conv(x,h)
stem(a)

OUTPUT:
3

-1

-2

-3

-4
1 2 3 4 5 6 7 8 9

USING FUNCTION CONV_M:


function[y,x] = conv_m(x,h,n1,n2)
n1 = -2:4;
n2 = -1:1;
y=conv(x,h) ;
stem(y)
end
COMMAND WINDOW:
>> X = [-1 4 -3 -2 1 0 2];

>> H = [1 1 1];

>> CONV_M(X,H,N1,N2)
ANS =

-1 3 0 -1 -4 -1 3 2 2

>> CONV_M(X,H,N1,N2)

OUTPUT:
3

-1

-2

-3

-4
1 2 3 4 5 6 7 8 9

TASK 4:
Write a function convolution in MATLAB that performs 1D linear
convolution by the steps mentioned above. You can use any method.
close all
clear all
x=input('Enter x: ')
h=input('Enter h: ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y
stem(Y);
ylabel('Y[n]');
xlabel('n');
title('Convolution of Two Signals');

OUTPUT:

Convolution of Two Signals


4

3.5

2.5

2
Y[n]

1.5

0.5

-0.5

-1
1 1.5 2 2.5 3 3.5 4 4.5 5
n
CRITICAL ANALYSIS:
In this lab the following things were learned:

1. Decomposing a signal to its even and odd parts using the basic properties. It is given by the
following equation:

x(n)=xe(n)+xo(n)

2. Using the properties of addition, multiplication, scaling and shifting some operations were
performed on the signals. The following relations give a better idea.

1
xe ( n) = [ x ( n ) + x (−n ) ]
2
1
x o (n)= [x (n)− x(−n)]
2
3. Since the conv command can’t provide results for negative length, so for that a function was
created in order to get results for negative values which basically multiplies the number with -1
with the numbers and also gives results for all of the values, the function created was named as
conv_m. The function gave same values as seen in task 3 for different value of x(n) and h(n).
4. 1D linear convolution was performed in task 4.

You might also like