Você está na página 1de 16

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');

2. Unit step sequence:u(n) = { In MATLAB t he function ones (1, N) generates a row vector of N ones. It can be used to generate u(n) over a finite interval.

Program:% Digital Signal Processing Lab % Program to generate a unit step signal n=-20:20; u=[zeros(1,20),ones(1,21)]; stem(n,u); grid; title('A unit step signal '); xlabel('Sampel Number'); ylabel('Amplitude');

3. Real-valued exponential sequence:x(n) = ()n , In MATLAB an array operator " . ^ " is required to implement a real exponential sequence. For example, to generate z(n) = (0.9)n , 0 < n < 10, we will need the following MATLAB script: >> n=0:10; x=(0.9).^n;

Program:% Digital Signal Processing Lab % Program to generate a real valued exponential signal % x(n)=(0.9).^n n=0:40; x=(0.9).^n; stem(n,x); grid; title('A Real valued Exponential signal '); xlabel('Sampel Number'); ylabel('Amplitude');

4. Sinusoidal sequence:x(n) = cos (o n + ) where o = 2 /N where N is period of this discrete time sinusoid. Where is the phase in radians, a MATLAB function cos (or sin) is used to generate sinusoidal sequences.

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); stem(n,x); grid; title('A sinusoidal signal of period N=12'); xlabel('Sample Number'); ylabel('Amplitude');

2. Demonstration of shifting of discrete time signals. Aim:- To plot and demonstrate shifting of discrete time signals. Equipments:Operating System Windows XP Constructor - Simulator Software - 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- no) where no is amount of shift. To implement this using MATLAB we have to pad no numbers of zeros before starting the sequence x(n).

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; x=2*cos(2*(pi/12)*n); xd =[zeros(1,20), x(1:(N-20))]; subplot(2,1,1); stem(n,x); grid; title('A sinusoidal signal of period N=12'); xlabel('Sample Number'); ylabel('Amplitude'); subplot(2,1,2); stem(n,xd); grid; title('A delayed sinusoidal signal of period N=12 amount of delay =20'); xlabel('Sample Number'); ylabel('Amplitude'); % in this section we will generate a delayed unit impulse sequence % delayed by 20 samples m=-(N/2): ((N/2)-1); u=zeros(1,N); u((N/2)+1)=1; ud=[zeros(1,20),u(1:N-20)]; figure(2) subplot(1,2,1) stem(m,u);

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

3. Demonstration basic manipulation on discrete time signals.

Aim:- To plot and demonstrate addition, subtraction multiplication of discrete


time signals.

Equipments:Operating System Windows XP Constructor - Simulator Software - MATLAB 7

Theory:1. Signal addition: - This is a sample -by-sample addition given by x1(n) + x2(n) it is
implemented in MATLAB by the arithmetic operator +. However, the lengths of x1(n) and x2(n) must be the same. 2. Signal subtraction:- This is a sample -by-sample subtraction given by x1(n) - x2(n) It is implemented in MATLAB by the arithmetic operator -. However, the lengths of x1(n) and x2(n) must be the same. 3. Signal subtraction:- This is a sample -by-sample multiplication given by x1(n) *x2(n) It is implemented in MATLAB by the arithmetic operator *. However, the lengths of x1(n) and x2(n) must be the same. This operation is non linear operation whereas addition and subtraction are linear operations.

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; x1=cos(2*pi/15*n); x2=0.5*sin(2*pi/30*n); add=x1+x2; sub=x1-x2; mul=x1 .* x2; subplot(1,2,1); stem(n,x1); grid; title('A sinusoidal signal of N=15'); xlabel('Sample Number'); ylabel('Amplitude'); subplot(1,2,2); stem(n,x2);

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

10

4. Finding impulse response of a given discrete time system and

finding its stability. Aim:- To find the impulse response of a discrete time system described by
difference equation and also find its stability.

Equipments:Operating System Windows XP Constructor - Simulator Software - MATLAB 7

Theory:-

Impulse response of a given system described by a difference equation can be found by using MATLAB function impz(num,den,N) where num is a row vector of coefficient of input x(n) = (n) and its delayed forms, similarly den is a row vector of coefficients of out put y(n) and its delayed forms. And N is total number of samples for which we have to find response. 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.e. impulse response, 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.

Program:% Digital Signal Processing Lab % Program to find impulse response of a system % y(n)+ 1.5 y(n-1)+ 0.9 y(n-2)= x(n)- 0.8 x(n-1) clc; N=200; n=0:N; num = [1 -0.8]; den = [1 1.5 0.9]; h = impz(num,den,N+1); stem(n,h); xlabel('Time index n'); ylabel('Amplitude'); title('Impulse Response h(n)'); sum = 0; for K=1:N+1; sum = sum + abs(h(K)); if abs(h(K))< 10^-6;

11

break end end stem(n,h); xlabel('Time index n'); ylabel('Amplitude'); title('Impulse Response h(n)'); grid; disp('value = '); disp(abs(h(K))); disp('sum of h(n) from n = 0 to N = ') disp(sum);

Out Put:value = 1.6761e-0.05 sum of h(n) from n = 0 to N = 35.3591

12

5. M-Point Moving Average Filter

Aim:- Implement an M-Point moving average filter. Equipments:Operating System Windows XP Constructor - Simulator Software - MATLAB 7

Theory: - an M pint moving average filter can be described as below.


( ) ( )
This can be implemented using MATLAB function filter and the matlab script to implement this can be written as: >> y=filter(num,1,x); Where x(n) is input and num is a row vector of all the elements 1 and it is a 1xM matrix, and 1 is denominator co efficient.

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)+ ......+x(n-M)) close all; clear all; clc; clf; n= 0:56; s1=cos(2*pi*0.05*n); s2=cos(2*pi*0.5*n); s=s1+s2; subplot(2,2,1); plot(n,s1); grid; title('Orignal signal s1 ,N=20 '); xlabel('number of sampel'); ylabel('Amplitude'); subplot(2,2,2); plot(n,s2); grid; title('Additive Noise signal s2 ,N=2 '); xlabel('number of sampel'); ylabel('Amplitude');

13

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

14

6. Implementation of integrator and differentiator

Aim:- implementation of an integrator and differentiator. Equipments:Operating System Windows XP Constructor - Simulator Software - MATLAB 7

Theory: - In digital signal processing a differentiator and integrator can be synthesized using
difference equations, 1. Differentiator:- 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). 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.

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)- y(n-1)= x(n) % and differentiation can be implemented using y(n)= x(n)- x(n-1) % in this program we will use x(n)= u(n)i.e. unit step signal n=-50:50; u=[zeros(1,50) ones(1,51)]; axis([-50,50,0,1]); subplot(3,1,1); stem(n,u); grid; title('imput unit step signal'); xlabel('sampel number'); ylabel('Amplitude'); % implementing differentiation y(n)= x(n)- x(n-1) num1=[1,-1]; den1=[1]; yd=filter(num1,den1,u); subplot(3,1,2); stem(n,yd); grid; title('Differentiation of unit step signal is impulse signal'); xlabel('sampel number'); ylabel('Amplitude');

15

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

16

Você também pode gostar