0% found this document useful (0 votes)
56 views6 pages

In Lab Task #01:: All All

The document contains code from several MATLAB lab tasks and post-lab tasks involving signal processing operations like scaling, shifting, folding, addition, multiplication, and convolution on discrete-time signals. The code demonstrates how to implement these operations by manipulating the time indices and values of signals represented as vectors, and plotting the original and processed signals.

Uploaded by

Ibad Ali Khan
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)
56 views6 pages

In Lab Task #01:: All All

The document contains code from several MATLAB lab tasks and post-lab tasks involving signal processing operations like scaling, shifting, folding, addition, multiplication, and convolution on discrete-time signals. The code demonstrates how to implement these operations by manipulating the time indices and values of signals represented as vectors, and plotting the original and processed signals.

Uploaded by

Ibad Ali Khan
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
You are on page 1/ 6

In Lab Task #01:

clc
clear all
close all
n=0:2:10;
x=exp(n);
subplot(211)
stem(n,x)
xlabel('n')
ylabel('x[n]')
title('orignal signal')
n1=-2*n;
subplot(212)
stem(n1,x)
xlabel('n1')
ylabel('x[n/(-2)]')
title('After scaling')

In Lab Task #02:


n=0:3;
x=[1 2 3 4]; k=-2;
subplot(211)
stem(n,x)
xlabel('n')
ylabel('x[n]')
title('orignal signal')
[y,n]=sigshift(x,n,k)
subplot(212)
stem(n,y)
xlabel('n')
ylabel('y[n]')
title('shift signal')
function [ y,n ] = sigshift( x,n,k )
if k>0
n=n+k; y=x;
elseif k<0
n=n-k
y=x;
end
end
In Lab Task #03:
n=0:3;
x=[1 2 3 4];
subplot(211)
stem(n,x)
xlabel('n')
ylabel('x[n]')
title('orignal signal')
[y,n]=sigfold(x,n)
subplot(212)
stem(n,y)
xlabel('n')
ylabel('y[n]')
title('fold signal')
Post Lab Task #01:
n1=0:4;
x1=[1 1 1 1 1];
n2=3:7;
x2=[1 1 1 1 1];
[y,n]=sigadd(x1,n1,x2,n2)
subplot(311)
stem(n1,x1)
xlabel('n1')
ylabel('x1[n1]')
title('First signal')
subplot(312)
stem(n2,x2)
xlabel('n2')
ylabel('x2[n2]')
title('second signal signal')
subplot(313)
stem(n,y)
xlabel('n')
ylabel('x[n]')
title('After addtion signal')

Post Lab Task #02:


Part(a)
x=[1 2 3 4 5 6 7 6 5 4 3 2 1];
n=-2:10;
n1=n+5
x1=2*x;
n2=n-4
x2=3*x;
% To make the length equal
if n1(1)>n2(1)
z1=n1(1)-n2(1);
x1=[zeros(1,z1) x1]
elseif n1(1)<n2(1)
z1=n2(1)-n1(1);
x2=[zeros(1,z1) x2]
end
if n1(end)>n2(end)
z2=n1(end)-n2(end);
x2=[x2 zeros(1,z2)]
elseif n1(end)<n2(end)
z2=n2(end)-n1(end);
x1=[x1 zeros(1,z2)]
else
disp('equal')
end
y=x1-x2
%To find the length of final signal
if n1(1)<n2(1)
len=n1(1):n2(end);
elseif n1(1)>n2(1)
len=n2(1):n1(end);
end
stem(len,y)
title('2x(n-5)-3x(n+4)')

Part(b)
n=-2:10;
n1=-2:10;
x1=[1 2 3 4 5 6 7 6 5 4 3 2 1];
n2=n+2;
x2=[1 2 3 4 5 6 7 6 5 4 3 2 1];

if n1(1)>n2(1)
z1=n1(1)-n2(1);
x1=[zeros(1,z1) x1]
elseif n1(1)<n2(1)
z1=n2(1)-n1(1);
x2=[zeros(1,z1) x2]
end

if n1(end)>n2(end)
z2=n1(end)-n2(end);
x2=[x2 zeros(1,z2)]
elseif n1(end)<n2(end)
z2=n2(end)-n1(end);
x1=[x1 zeros(1,z2)]
else
disp('equal')
end

%for length
if n1(1)<n2(1)
n4=n1(1):n2(end)
elseif n1(1)>n2(1)
n4=n2(1):n1(end)
end

x4=x1.*x2
x3=[1 2 3 4 5 6 7 6 5 4 3 2 1];
n3=n-3
n3=(-1)*fliplr(n);

if n3(1)>n4(1)
z1=n3(1)-n4(1);
x3=[zeros(1,z1) 3]
elseif n3(1)<n4(1)
z1=n4(1)-n3(1);
x4=[zeros(1,z1) x4]
end

if n3(end)>n4(end)
z2=n3(end)-n4(end);
x4=[x4 zeros(1,z2)]
elseif n3(end)<n4(end)
z2=n4(end)-n3(end);
x3=[x3 zeros(1,z2)]
else
disp('equal')
end

%for length
if n3(1)<n4(1)
len=n3(1):n4(end)
elseif n3(1)>n4(1)
len=n4(1):n3(end)
end
x333=x3(1)
x444=x4(1)
y=x3+x4
stem(len,y)
title('x(3-n)+x(n)x(n-2)')

You might also like