1

Digital Signal processing Lab
1. Demonstration of basic discrete time signals. Aim:- To plot and demonstrate various types of discrete time signals. Equipments:Operating System – Windows XP Constructor - Simulator Software - MATLAB 7

Theory:-

We use several elementary sequences in digital signal processing for analysis purposes. Their definitions and MATLAB representations are given below.

1. Unit sample sequence:-

δ(n) = {

= {…..,0,0,0,1,0,0,0,…..

In MATLAB t he function zeros (1, N) generates a row vector of N zeros, which can be used to implement δ(n) over a finite interval. However, the implementing δ (n) can be done by taking n=0 sample equal to 1.

Program:% Digital Signal Processing Lab % Program to generate a unit impulse signal N=64; n=-(N/2): ((N/2)-1); x=zeros(1,N); x((N/2)+1)=1; stem(n,x); grid; title('A unit impulse signal '); xlabel('Sampel Number'); ylabel('Amplitude');

u).21)].20). Unit step sequence:u(n) = { In MATLAB t he function ones (1. . grid.ones(1. xlabel('Sampel Number'). It can be used to generate u(n) over a finite interval. u=[zeros(1.2 2. title('A unit step signal '). Program:% Digital Signal Processing Lab % Program to generate a unit step signal n=-20:20. ylabel('Amplitude'). stem(n. N) generates a row vector of N ones.

0 < n < 10. title('A Real valued Exponential signal '). Program:% Digital Signal Processing Lab % Program to generate a real valued exponential signal % x(n)=(0. For example.3 3.x). grid.9).9). Sinusoidal sequence:x(n) = cos (ωo n + θ) where ωo = 2 /N where N is period of this discrete time sinusoid. In MATLAB an array operator " . x=(0. we will need the following MATLAB script: >> n=0:10. 4. a MATLAB function cos (or sin) is used to generate sinusoidal sequences.^n. Where θ is the phase in radians. ^ " is required to implement a real exponential sequence.9). to generate z(n) = (0. Real-valued exponential sequence:x(n) = (α)n .9)n .^n n=0:40.^n. ylabel('Amplitude'). xlabel('Sampel Number'). x=(0. stem(n. .

title('A sinusoidal signal of period N=12'). . stem(n. grid. xlabel('Sample Number').4 Program:% Digital Signal Processing Lab % Program to generate a sinusoidal signal % x(n)=A*cos((2*pi/N)+ theta)in this example N=12 and theta is pi/3 n=0:40. x=2*cos((2*(pi/12)*n)+pi/3).x). ylabel('Amplitude').

ylabel('Amplitude').To plot and demonstrate shifting of discrete time signals.no) where no is amount of shift. title('A sinusoidal signal of period N=12'). x=2*cos(2*(pi/12)*n). stem(n. x(1:(N-20))].x).2. Demonstration of shifting of discrete time signals.5 2.u). subplot(2.20). subplot(2. .1). Program:% Digital Signal Processing Lab % Program to generate a sinusoidal signal and delay it by 10 samples % x(n)=A*cos((2*pi/N)+ theta)in this example N=12 and theta is 0 and % amount of delay is of 20 samples N=64 n=0:N-1.N).Simulator Software .u(1:N-20)]. To implement this using MATLAB we have to pad no numbers of zeros before starting the sequence x(n). u=zeros(1.xd). Aim:.2). stem(n. title('A delayed sinusoidal signal of period N=12 amount of delay =20'). grid.1) stem(m. grid. figure(2) subplot(1.1.MATLAB 7 Theory:- Shifting is any discrete time sequence can be seen as delaying or advancing the sequence in time or sample interval if x(n) is a discrete time signal than its delayed version can be expressed as x(n.20). xd =[zeros(1.1. ylabel('Amplitude'). u((N/2)+1)=1. xlabel('Sample Number'). xlabel('Sample Number'). ud=[zeros(1. % in this section we will generate a delayed unit impulse sequence % delayed by 20 samples m=-(N/2): ((N/2)-1). Equipments:Operating System – Windows XP Constructor .

6 grid. title('A unit impulse signal ').2. xlabel('Sample Number'). ylabel('Amplitude'). grid. .2) stem(m. subplot(1. ylabel('Amplitude'). xlabel('Sample Number').ud). title('A unit impulse signal delayed by 20 samples').

However. add=x1+x2.1). x2=0. stem(n. . the lengths of x1(n) and x2(n) must be the same. Demonstration basic manipulation on discrete time signals.MATLAB 7 Theory:1. Equipments:Operating System – Windows XP Constructor .2.x2(n) It is implemented in MATLAB by the arithmetic operator “-”.Simulator Software . sub=x1-x2. stem(n.x1). mul=x1 . x1=cos(2*pi/15*n). the lengths of x1(n) and x2(n) must be the same. subplot(1.This is a sample -by-sample addition given by x1(n) + x2(n) it is implemented in MATLAB by the arithmetic operator “+”.* x2.5*sin(2*pi/30*n).This is a sample -by-sample subtraction given by x1(n) . xlabel('Sample Number').This is a sample -by-sample multiplication given by x1(n) *x2(n) It is implemented in MATLAB by the arithmetic operator “*”.x2).2. title('A sinusoidal signal of N=15'). However. 3. the lengths of x1(n) and x2(n) must be the same. subtraction multiplication of discrete time signals.2). subplot(1. grid. Program :% Digital Signal Processing Lab % Program to demonstrate addition subtraction and multiplication % of two different sinusoids having periods N1=15 and N2=30 n=0:50. 2.7 3. This operation is non linear operation whereas addition and subtraction are linear operations. Signal addition: . Aim:.To plot and demonstrate addition. ylabel('Amplitude'). Signal subtraction:. However. Signal subtraction:.

title('A sinusoidal signal of N = 30'). stem(n.2). xlabel('Sample Number').1).8 grid. xlabel('Sample Number'). subplot(1.3. stem(n.3).sub).add). grid.3. title('A subtraction x1-x2'). subplot(1. ylabel('Amplitude'). stem(n. ylabel('Amplitude'). ylabel('Amplitude'). . ylabel('Amplitude'). grid.mul). xlabel('Sample Number'). grid. xlabel('Sample Number'). title('A addition x1+x2'). subplot(1. title('A multiplication x1*x2'). figure(2).3.

9 .

ylabel('Amplitude').8 x(n-1) clc.den.N) where num is a row vector of coefficient of input x(n) = δ(n) and it’s delayed forms. Program:% Digital Signal Processing Lab % Program to find impulse response of a system % y(n)+ 1.MATLAB 7 Theory:- Impulse response of a given system described by a difference equation can be found by using MATLAB function impz(num.To find the impulse response of a discrete time system described by difference equation and also find it’s stability. sum = sum + abs(h(K)). num = [1 -0. sum = 0.0.h).5 0. title('Impulse Response h(n)'). And N is total number of samples for which we have to find response.den.e.9]. N=200.N+1). Where as the test of stability of a system can be performed using the method “Sum of Absolute Test” in this method after finding impulse response of a system for N samples we test the absolute value of h(n) i. if abs(h(K))< 10^-6. for K=1:N+1.9 y(n-2)= x(n). .5 y(n-1)+ 0. h = impz(num. Finding impulse response of a given discrete time system and finding it’s stability.8]. stem(n. n=0:N. similarly den is a row vector of coefficients of out put y(n) and it’s delayed forms.Simulator Software .10 4. Equipments:Operating System – Windows XP Constructor . xlabel('Time index n'). Aim:. if the absolute value is decreasing as N is increasing and if the absolute value of h(n) becomes < 10-6 the system can be considered as stable system. den = [1 1. impulse response.

3591 . title('Impulse Response h(n)'). grid. disp(abs(h(K))).h). disp('sum of h(n) from n = 0 to N = ') disp(sum).11 break end end stem(n. xlabel('Time index n').05 sum of h(n) from n = 0 to N = 35. disp('value = '). Out Put:value = 1. ylabel('Amplitude').6761e-0.

s=s1+s2. clc. s2=cos(2*pi*0. grid.05*n).12 5. Where x(n) is input and num is a row vector of all the elements 1 and it is a 1xM matrix.2). subplot(2. subplot(2. Program:% Digital Signal Processing Lab % Program to impliment M point moving average filter % y(n)= 1/M(x(n)+ x(n-1)+x(n-2)+ x(n-3)+x(n-4)+ .MATLAB 7 Theory: .Implement an M-Point moving average filter. and 1 is denominator co efficient. ylabel('Amplitude').Simulator Software ..N=2 '). grid. s1=cos(2*pi*0.1. ( ) ∑ ( ) This can be implemented using MATLAB function “filter” and the matlab script to implement this can be written as: >> y=filter(num.s1).5*n). xlabel('number of sampel').x).+x(n-M)) close all. clf.. plot(n..1).2. n= 0:56.N=20 ').2. ylabel('Amplitude').. xlabel('number of sampel').an M pint moving average filter can be described as below. . title('Orignal signal s1 .s2). plot(n. Equipments:Operating System – Windows XP Constructor . title('Additive Noise signal s2 . M-Point Moving Average Filter Aim:. clear all..

ylabel('Amplitude'). grid. title('Noisy signal to be filtered = s1+s2 '). xlabel('number of sampel').1. plot(n. subplot(2. title(' Filtered signal '). Please enter the length of filter = 10 . num=ones(1.13 subplot(2. ylabel('Amplitude').3). M=input('Please enter the length of filter = ').M).s)/M. grid.s). plot(n. xlabel('number of sampel').2.2. y=filter(num.y).4).

subplot(3.0.50. stem(n.e. xlabel('sampel number'). Program:% Digital Signal Processing Lab % Program to find integration and differentiation of a given signal x(n) % the integrator can be implemented using y(n).x(n-1) num1=[1.1]).1.x(n-1) % in this program we will use x(n)= u(n)i. Differentiator:. u=[zeros(1. title('Differentiation of unit step signal is impulse signal').50) ones(1.In digital signal processing a differentiator and integrator can be synthesized using difference equations. ylabel('Amplitude'). unit step signal n=-50:50. xlabel('sampel number'). .den1.u). grid.1). 2. Integrator or Accumulator:.An integrator can be viewed as : y(n)=∑ ( ) and this can be converted in to difference equation as: y(n) – y(n-1) = x(n) which can easily be programmend. den1=[1]. axis([-50.1.-1].implementation of an integrator and differentiator. stem(n. ylabel('Amplitude').2).MATLAB 7 Theory: .y(n-1)= x(n) % and differentiation can be implemented using y(n)= x(n).yd).a differentiator can be implemented using finding the first difference of any given input signal x(n) and it is given as: y(n) = x(n)-x(n-1) this is called the first difference of input x(n). title('imput unit step signal'). grid.u). Implementation of integrator and differentiator Aim:. yd=filter(num1. subplot(3.Simulator Software . 1. Equipments:Operating System – Windows XP Constructor . % implementing differentiation y(n)= x(n).51)].14 6.

-1]. yi=filter(num2. ylabel('Amplitude'). xlabel('sampel number'). stem(n.den2.15 % implementing integration y(n). subplot(3.1.yi). title('Integration of unit step signal is unit ramp signal').y(n-1)= x(n) num2=[1].3). . den2=[1 . grid.u).

16 .

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.