Sunteți pe pagina 1din 6

Digital Signal Processing Laboratory Expt. No.

2
Aim: - Operation on discrete- time signals 1. Signal addition
This is sample by sample addition given by

{x1(n)} + {x2(n)} ={x1(n) + x2(n)}


In MATLAB it is implemented by the array operator +. However length of both the signals must be same. If the length is not same or if sample position are different for equal length sequences, then + operator can not be used. First x1(n) and x2(n) are to be augmented so that they have same position vector n. In particular logical operation &, relational operator like <= and = = and find function are required to make x1(n) and x2(n) of equal length. The following function demonstrates these operations. clc; close all; clear all; n1=input('Enter the range of the first sequence'); x1=input('Enter the first sequence'); n2=input('Enter the range of the second sequence'); x2=input('Enter the second sequence'); n=min(min(n1),min(n2)):max(max(n1),max(n2)); y1=zeros(1,length(n)); y2=y1; y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; y=y1+y2; subplot(2,2,1);stem(n1,x1) title('First seq. x1(n)'); xlabel('sample'); ylabel('amplitude'); subplot(2,2,2);stem(n2,x2) title('Second seq. x2(n)'); xlabel('sample'); ylabel('Amplitude'); subplot(2,1,2);stem(n,y) title('addition of signal') xlabel('sample'); ylabel('Amplitude');

Department of Electronics and Telecommunication

Digital Signal Processing Laboratory

function [y,n]=sigadd(x1,n1,x2,n2) n=min(min(n1),min(n2)):max(max(n1),max(n2)); y1=zeros(1,length(n));y2=y1; y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; y=y1+y2;

Department of Electronics and Telecommunication

Digital Signal Processing Laboratory


Exercise 1 Let x1 ( n ) {1, 2,3, 4, 5, 6, 7, 6,5, 4} and

x2 (n) {1, 2, 0, 4,5, 2, 7, 6,8, 4, 3}


Determine and plot the following sequences.

1. y (n) x1 ( n) x2 ( n)

Solution
x1=[1 2 3 4 5 6 7 6 5 4]; n1=-2:7; x2=[-1 2 0 4 5 -2 7 6 8 4 -3 4]; n2=-4:6; [y,n]=sigadd(x1,n1,x2,n2); subplot(2,2,1);stem(n1,x1) title('First seq. x1(n)'); xlabel('sample'); ylabel('amplitude'); subplot(2,2,2);stem(n2,x2) title('Second seq. x2(n)'); xlabel('sample'); ylabel('Amplitude'); subplot(2,1,2);stem(n,y) title('addition of signal') xlabel('sample'); ylabel('Amplitude');

Department of Electronics and Telecommunication

Digital Signal Processing Laboratory

2.

Signal Multiplication
This is sample by sample multiplication given by

{x1(n)}.{x2(n)}={x1(n)x2(n)}
In MATLAB it is implemented by the array operator .*. Write a function for the multiplication of two sequences x1(n) and x2(n).

function [y,n]=sigmul(x1,n1,x2,n2) n=min(min(n1),min(n2)):max(max(n1),max(n2)); y1=zeros(1,length(n));y2=y1; y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; y=y1.*y2;

Department of Electronics and Telecommunication

Digital Signal Processing Laboratory


3. Scaling

In this operation each sample is multiplied by a scalar

{x(n)}={ x(n)}
An arithmetic operator * is used to implement the scaling operation in MATLAB.

4.

Shifting

In this operation each sample of x(n) is shifted by an amount k to obtain a shifted sequence y(n).

y(n}={ x(n-k)
If we let m=n-k, then n=m+k and above operation is given by

y(m+k)={x(m)}
Write a MATLAB function to shift the given sequence by k amount. function [y,n]=sigshift(x,m,n0) n=m+n0; y=x;

5.

Folding

In this operation each sample of x(n) is flipped around its origin n=0 to obtained folded sequence y(n).

y(n)={x(-n)}
Hint: Use fliplr( ) function. function [y,n] =sigfold(x,n) y=flipr(x); n=-flipr(n);

Department of Electronics and Telecommunication

Digital Signal Processing Laboratory


Lab Exercise
Exercise 1 Let

x( n) {1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2,1}

Determine and plot the following sequences.

1. x1 ( n) x(3 n)

2. x2 (n) 2 x(n 5) 3x(n 4)


3. x3 (n) x( n) x(n 2)
Exercise 2 Generate the Complex- Valued signal

x(n) e ( 0.1 j 0.3) n , 10 n 10


And plot its magnitude, phase, the real part, and imaginary part in four separate subplot.

Department of Electronics and Telecommunication

S-ar putea să vă placă și