DSP Lab Manual PDF

Title DSP Lab Manual
Author mukul manohar
Course DSP Lab
Institution Vemana Institute of Technology
Pages 66
File Size 3.2 MB
File Type PDF
Total Downloads 62
Total Views 146

Summary

DSP Lab manual...


Description

DSP Lab(18ECL57)

5th SEM

ECE, Vemana IT

VEMANA INSTITUTE OF TECHNOLOGY NO.1,MAHAYOGI VEMANA ROAD,3RB BLOCK KORAMANGALA,BANGALORE-560034

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Digital Signal Processing Lab Manual Sub Code: 18ECL57

Mr. Mukul Manohar.S

1|Page

DSP Lab(18ECL57)

5th SEM

Assistant Professor

2|Page

ECE, Vemana IT

DSP Lab(18ECL57)

Name: USN: Department: Name of Faculty

Signature of Faculty

3|Page

5th SEM

ECE, Vemana IT

DSP Lab(18ECL57)

5th SEM

Table of Contents Part-A Sl No. 1 2 3 4 5 6 7 8 9 10 11 12

1 2 3

4|Page

Title of Program Verification of Sampling theorem. Impulse response of a given system Linear convolution of two given sequences Circular convolution of two given sequences Autocorrelation of a given sequence and verification of its properties. Cross-correlation of given sequences and verification of its properties. Solving a given difference equation. Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum. Linear convolution of two sequences using DFT and IDFT. Circular convolution of two given sequences using DFT and IDFT Design and implementation of FIR filter to meet given specifications Design and implementation of IIR filter to meet given specifications. Part-B Linear convolution of two given sequences. Circular convolution of two given sequences Computation of N point DFT of a given sequence

ECE, Vemana IT

DSP Lab(18ECL57)

5th SEM

ECE, Vemana IT

PROGRAM 1 VERIFICATION OF SAMPLING THEOREM Aim: To write the MATLAB code for verifying Sampling Theorem. Generate a sinusoidal wave of 1kHz. Calculate the Nyquist frequency, and verify Sampling Theorem, showing output waveforms for under sampled, oversampled and right sampled cases. Theory: Sampling is the process of converting an continuous time signal into a discrete time signal. In sampling, the values of the continuous time signal is recorded at discrete intervals of time (usually equidistant). The number of samples taken during one second is called the sampling rate. Sampling is described by the relation: �(�) = ��(�� ) − ∞ < � < ∞ Where �(�) is the discrete-time signal obtained by sampling the analog signal every T seconds. �� = 1/� is known as the Sampling Frequency. The Sampling Theorem states that : “A bandlimited signal can be reconstructed exactly if it is sampled at a rate atleast twice the maximum frequency component in it." Assume a band-limited signal �(�) = � sin(� �) = � sin (2���) with maximum frequency component ′�′. The theorem says that, for a good reconstruction of the original continuous time signal, the sampling frequency must be at least 2 �. This frequency is known as the “Nyquist Rate” Whenever the Sampling frequency �� is greater than or equal to the Nyquist Frequency, the signal can be reconstructed faithfully, capturing all the essential properties of the original continuous-time signal. However, when �� < 2�, we encounter a problem called “Aliasing”, where distortion is caused by high frequencies overlapping low frequencies. A lot of data is lost in this process and the signal cannot be recovered. MATLAB CODE: % Experiment 1 : Sampling Theorem Verification clear all; close all; clc; % f T t

Signal Parameters = 1000; % Signal Frequency = 1kHz = 1/f; % Signal Period = 0:0.01*T:2*T; % Time index

5|Page

DSP Lab(18ECL57)

5th SEM

% Generate the original signal and plot it: x = cos(2*pi*t*f); % Signal : 2*pi*f*t subplot(2,2,1); plot(t,x); title('Continuous signal'); xlabel('t'); ylabel('x(t)');

%Oversampling Condition: fs1 = 10*f; % Oversampling (fs > 2f) n1 = 0:1/fs1:2*T; % Time scale x1 = cos(2*pi*f*n1); % Generating sampled signal subplot(2,2,2); stem(n1,x1); hold on; plot(n1,x1,'r'); hold off; title('Oversampling Condition : Fs = 10F'); xlabel('n'); ylabel('x(n)'); % Right Sampling Condition: fs2 = 2*f; % Nyquist Rate Sampling (fs = 2f) n2 = 0:1/fs2:2*T; x2 = cos(2*pi*f*n2); subplot(2,2,3); stem(n2,x2); hold on; plot(n2,x2,'r'); hold off; title('Sampling at Nyquist Frequency : Fs = 2F'); xlabel('n'); ylabel('x(n)'); % Under Sampling Condition: fs3 = 1.5*f; % Undersampling (fs < 2f) n3 = 0:1/fs3:2*T; x3 = cos(2*pi*f*n3); subplot(2,2,4); stem(n3,x3); hold on; plot(n3,x3,'r'); hold off; title('Undersampling Condition : Fs = 1.5 f'); xlabel('n'); ylabel('x(n)');

OUTPUT:

6|Page

ECE, Vemana IT

DSP Lab(18ECL57)

5th SEM

Observation and Obtained Output

7|Page

ECE, Vemana IT

5th SEM

DSP Lab(18ECL57)

ECE, Vemana IT

Signature PROGRAM 2 IMPULSE RESPONSE OF A GIVEN SYSTEM Aim: To write the MATLAB code to find the impulse response of a given second-order system whose difference equation representation is given. Assume a second-order system represented by the following difference equation: (() = 0 (() + 1 ((− 1) + 20 (( − 2) + 1 ((− 1) + 2 (− 2)

Theory: Impulse response of a system is defined as the output of a given system, when the input applied to the system, is in the form of an unit impulse, or a Dirac delta function. The impulse response completely characterizes the behaviour of any LTI system. The impulse response is often determined from knowledge of the system configuration and dynamics, or can be measured by applying and approximate impulse to the system input. Discrete-time LTI systems can also be described using Difference Equations. A linear constant-coefficient difference equation can be of the form: k=¿ n−k a k y ( n−k ) =∑ M bk x (¿) ¿

N

¿ ∑ k=0

Where the integer N is termed the order of the difference equation, and corresponds to the maximum memory involving the system output. The order generally represents the number of energy storage devices in a physical system. We can calculate the impulse response of the system using Z-transforms as shown in the following example:

8|Page

DSP Lab(18ECL57)

5th SEM

ECE, Vemana IT

Consider a difference equation: �(�) = �(�) + 0.2 �(� − 1) − 1.5 �(� − 2) − 3 �(� − 1) + 0.12 �(� − 2) Finding the Z-transform of the equation: �(� ) + 3 � -1 �(�) − 0.12 � -2�(�) = � (�) + 0.2 Z -1�(�) − 1.5 Z

-2

�( �)

�(�)[1 + 3 � -1 − 0.12 �-2] = �(�)[1 + 0.2 �-1 − 1.5 � -2] Transfer Function of the system can be obtained as :

By long division, we get : � (�) = 1 − 2.8 � -1 + 7.02 �

-2

− 21.4 �

-3

+ 65.03 �-4

By taking Inverse-Z transform, we can obtain the Impulse Response as: ℎ[�] = [1 − 2.8 7.02 21.4 65.03]

MATLAB CODE: %Experiment 2 : Impulse Response of a Given Second-Order System clear all; close all; clc; % b a N

Accept Input and Output signal Co-efficients: = input('Enter the coefficients of x(n) in 1-D Matrix Form: '); = input('Enter the coefficients of y(n) in 1-D Matrix Form: '); = input('Enter the number of samples of impulse response desired: ');

% Calculate Impulse Response using IMPZ function: % [H,T] = IMPZ(B,A,N) computes N samples of the impulse response, using % coefficients B and A from difference equation representation. [h,t] = impz(b,a,N); %Plot and Display impulse response co-efficients: stem(t,h); title('Impulse Response Plot'); ylabel('h(n)'); xlabel('n'); disp('Impulse Response Coefficients:'); disp(h);

OUTPUT: Enter the coefficients of x(n) in 1-D Matrix Form: [1 0.2 -1.5]

9|Page

DSP Lab(18ECL57)

5th SEM

Enter the coefficients of y(n) in 1-D Matrix Form: [1 3 -0.12] Enter the number of samples of impulse response desired: 5 Impulse Response Coefficients are : 1.0000 -2.8000 7.0200 -21.3960 65.0304

10 | P a g e

ECE, Vemana IT

DSP Lab(18ECL57)

5th SEM

Observation and Calculations

11 | P a g e

ECE, Vemana IT

DSP Lab(18ECL57)

5th SEM

Observation and Calculations

12 | P a g e

ECE, Vemana IT

5th SEM

DSP Lab(18ECL57)

ECE, Vemana IT

PROGRAM 3 LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES Aim: To write the MATLAB code to perform Linear Convolution upon two given discrete time signals. Theory: Convolution is the process used to find the response of a Linear Time Invariant system to a given input, assuming we already know the impulse response of that system. In case of continuous-time signals, we can find the system response using the Convolution Integral, while in case of discrete-time systems, the response can be calculated using the Convolution Sum. Let �1(�) and �2(�) be two discrete-time signals. The convolution sum of the two signals can be calculated using the formula: ∞

y ( n)=x 1 ( n)∗x 2=



x 1(k ) x 2 (n−k )

k=−∞

If �1(�) is a M- point sequence and �2(�) is an N – point sequence, then the convolved sequence, �(�) is a (M+N-1) – point sequence We can perform the convolution by different methods: 1. Using MATLAB’s “CONV” function : MATLAB has a built-in function called “conv” function, which basically performs a linear convolution of any two given sequences.

13 | P a g e

DSP Lab(18ECL57)

5th SEM

ECE, Vemana IT

2. Using the Linear Convolution Sum formula : Here, we use the convolution sum formula and substitute values of � and � in the expression, and calculate the values of the convolved signal. Alternatively, we can perform the signal inversion-time shift-superposition method, by which we can calculate the resultant signal values. Assume two discrete-time sequences �1 and �2 in a Linear Time Invariant System, given by: �1(�) = {1, 2, −1, 3} and �2(�) = {2,3, −2} We see that length of sequence �1 is (M = 4) and that of sequence �2 is (N = 3). Therefore, the length of the convolved sequence will be (M+N-1 = 6). Using any of the above given methods, we see that the resultant convolved sequence can be given by: �(�) = �1(�) ∗ �2(�) = { 2 7 2 − 1 11 − 6}

1. Using “conv” function: %% Linear Convolution using CONV command clear all; close all; clc; % Accept input signal sequences x1 = input('Enter Input Sequence for Signal x1(n): '); x2 = input('Enter Input Sequence for Signal x2(n): '); %Perform Linear Convolution using CONV command y=conv(x1,x2); %Plot Input and Convolved Signals subplot(3,1,1); stem(x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)');

14 | P a g e

DSP Lab(18ECL57)

5th SEM

% Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y);

2. Using Convolution Sum formula: %% Linear Convolution without using CONV command clear all; close all; clc; x1 = input('Enter Input Sequence for Signal x1(n): '); n1 = length(x1); x2 = input('Enter Input Sequence for Signal x2(n): '); n2=length(x2); N = n1+n2-1; %Length of Convolved Sequence T = 1:N; % Create Time Index %Zero padding to make sequences of length N x1=[x1 zeros(1,N-n1)]; x2=[x2 zeros(1,N-n2)]; %Initializing Output sequence of zeros. y = zeros(1,N); %Performing Linear Convolution: for n = 1:N for k = 1:n y(n)=y(n)+x1(k)*x2(n-k+1); end end % Plot Input and Output Sequences: subplot(3,1,1); stem(T,x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(T,x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(T,y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y);

15 | P a g e

ECE, Vemana IT

5th SEM

DSP Lab(18ECL57)

ECE, Vemana IT

OUTPUT:

Enter Input Sequence for Signal x1(n): [1 2 -1 3] Enter Input Sequence for Signal x2(n): [2 3 -2] Convolved sequence: 2 7 2

16 | P a g e

-1

11

-6

DSP Lab(18ECL57)

5th SEM

Observations and Calculations

17 | P a g e

ECE, Vemana IT

DSP Lab(18ECL57)

5th SEM

Observations and Calculations

18 | P a g e

ECE, Vemana IT

5th SEM

DSP Lab(18ECL57)

ECE, Vemana IT

PROGRAM 4 CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES Aim: To write the MATLAB code to perform Circular Convolution upon two given discrete time signals. Theory: The Circular convolution, also known as cyclic convolution, of two aperiodic functions occurs when one of them is convolved in the normal way with a periodic summation of the other function. Circular convolution is only defined for finite length functions (usually equal in length), continuous or discrete in time. In circular convolution, it is as if the finite length functions repeat in time, periodically. Because the input functions are now periodic, the convolved output is also periodic. Circular convolution sum can be calculated using the formula: N−1

y ( n)=x 1 ( n)∗x 2 (n) = ∑ x 1 ( n ) x 2 (( m−n ) )N n=0

For � = 0,1,…. , � − 1 Circular convolution can be performed in different ways : 1. Using the expression for linear convolution sum, but assuming the signal repeats periodically. This can be done by changing the negative indices of (n-k) to repetitions of the latter portions of the original aperiodic signal. 2. Convolution in time domain corresponds to multiplication in frequency domain. To make use of this property, we can calculate the DTFT of each of the aperiodic signals, multiply

19 | P a g e

5th SEM

DSP Lab(18ECL57)

ECE, Vemana IT

these in the frequency domain, and find the IDFT of the product, to get the periodic convolved signal in time domain Let us take the case of two discrete-time aperiodic signals given by: 1(�) ( = {2,1,2,1} and 2(�) ( = {1,2,3,4} Using the formula with N = 4. For m = 0:

For m = 1:

.

For m = 2:

For m = 3:.

So, we get the circular convolution sum as: () = {14,16,14,16} MATLAB CODE:

1. Using Convolution Sum Formula: %% Circular Convolution using Formula clear all; close all; clc; x1 = input('Enter Input Sequence for Signal x1(n): '); n1 = length(x1); x2 = input('Enter Input Sequence for Signal x2(n): '); n2=length(x2);

20 | P a g e

DSP Lab(18ECL57)

5th SEM

N = max(n1,n2); % Length of Convolved Sequence T = 1:N; % Create Time Index %Zero padding to make sequences of length N x1=[x1 zeros(1,N-n1)]; x2=[x2 zeros(1,N-n2)]; %Initializing Output sequence of zeros. y = zeros(1,N); %Performing Linear Convolution: for m=1:N for n=1:N i=m-n+1; %(m-n+1) since we're taking index from 1 if(i...


Similar Free PDFs