+ All Categories
Home > Documents > DSP LAB -15ECL57 - Nipani

DSP LAB -15ECL57 - Nipani

Date post: 04-Dec-2021
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
68
DSP LAB -17ECL57 1 Dept Of ECE,VSMSRKIT VSM’s Somashekhar R Kothiwale Institute of Technology, Nipani-591237 Department of Electronics & Communication Engg DSP LAB 18ECL57 BY Prof.GOVIND M R
Transcript
Page 1: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

1 Dept Of ECE,VSMSRKIT

VSM’s

Somashekhar R Kothiwale Institute of

Technology, Nipani-591237

Department of Electronics &

Communication Engg

DSP LAB

18ECL57

BY

Prof.GOVIND M R

Page 2: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

2 Dept Of ECE,VSMSRKIT

INTRODUCTION TO MATLAB

MATLAB is a software package for high performance numerical computation

and visualization provides an interactive environment with hundreds of built in

functions for technical computation, graphics and animation. The MATLAB

name stands for MATrixLABoratory.

The diagram shows the main features and capabilities of MATLAB.

MATLAB

Graphics

2-D graphics.

3-D graphics.

Animation.

External interface

Interface with C and

FORTRAN Programs

Toolbox

Signal Processing

Image Processing

Statistics

Control system

Neutral networks

Communications

and many more….

Computations

Linear Algebra.

Signal processing.

Polynomials

&interpolation.

Quadrature

solution of ODES.

Page 3: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

3 Dept Of ECE,VSMSRKIT

At its core, MATLAB is essentially a set (a ―toolbox‖) of routines (called ―m files‘

or ―mex files‖) that sit on your computer and a window that allows you to

create new variables with names (e.g. voltage and time) and process those

variables with any of those routines (e.g. plot voltage against time, find the

largest voltage, etc.)

MATLAB® is a high-level language and interactive environment that enables

you to perform computationally intensive tasks faster than with traditional

programming languages such as C, C++, and Fortran.

Key Features:

High-level language for technical computing.

Development environment for managing code, files, and data.

Interactive tools for iterative exploration, design, and problem solving.

Mathematical functions for linear algebra, statistics, Fourier analysis,

Filtering, optimization, and numerical integration.

2-D and 3-D graphics functions for visualizing data.

Tools for building custom graphical user interfaces.

Functions for integrating MATLAB based algorithms with external

applications and languages, such as C, C++, Fortran, Java, COM, and

Microsoft® Excel®.

MATLAB Windows:

MATLAB works with through three basic windows

Command Window: This is the main window .It is characterized by

MATLAB command prompt(>>) when you launch the application program

MATLAB puts you in this window all commands including those for user-

written programs ,are typed in this window at the MATLAB prompt.

Graphics window: The output of all graphics commands typed in the

command window are flushed to the graphics or figure window, a separate

gray window with white background color the user can create as many

windows as the system memory will allow.

Edit window: This is where you write edit, create and save your own

programs in files called M files.

Page 4: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

4 Dept Of ECE,VSMSRKIT

Input-output:

MATLAB supports interactive computation taking the input from the screen

and flushing the output to the screen. In addition it can read input files and

write output files.

Data Type: The fundamental data-type in MATLAB is the array. It

encompasses several distinct data objects- integers, real numbers, matrices.

Character strings, structures and cells. There is no need to declare variables as

real or complex, MATLAB automatically sets the variable to be real.

Dimensioning: Dimensioning is automatic in MATLAB. No dimension

statements are required for vectors or arrays. We can find the dimensions of an

existing matrix or a vector with the size and length commands.

Basic Instructions in Matlab

1) T = 0:1:10

This instruction indicates a vector T which as initial value 0 and final value

10 with an increment of 1.

Therefore,

T = 0 1 2 3 4 5 6 7 8 9 10

2) T= Zeros (2, 3)

The above instruction creates a vector of two rows and three columns whose

values are zero.

T =

0 0 0 0 0 0

3) T=Ones (3,2)

The above instruction creates a vector of three rows and two columns whose

values are one

T =

1 1

1 1

1 1

Page 5: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

5 Dept Of ECE,VSMSRKIT

4) a = [1 2 3] b = [4 5 6]

a.*b= [41018], which is the result of individual elements.

5) Matrix and Array Operations

MATLAB allows you to process all of the values in a matrix using a single

arithmetic operator or function.

To create a matrix that has multiple rows, separate the rows with semicolons.

a = [1 2 3; 4 5 6; 7 8 10]

a =

1 2 3

4 5 6

7 8 10

a + 10

ans =

11 12 13

14 15 16

17 18 20

sin(a)

ans =

0.8415 0.9093 0.1411

-0.7568 -0.9589 -0.2794

0.6570 0.9894 -0.5440

To transpose a matrix, use a single quote ('):

a'

ans =

1 4 7

2 5 8

3 6 10

Page 6: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

6 Dept Of ECE,VSMSRKIT

You can perform standard matrix multiplication, which computes the inner

products between rows and columns, using the * operator. For example,

confirm that a matrix times its inverse returns the identity matrix:

p = a*inv(a)

p =

1.0000 0 -0.0000

0 1.0000 0

0 0 1.0000

Notice that p is not a matrix of integer values. MATLAB stores numbersas

floating-point values, and arithmetic operations are sensitive to small

differences between the actual value and its floating-point representation. You

can display more decimal digits using the format command:

Format long:

p = a*inv(a)

p =

1.000000000000000 0 -0.000000000000000

0 1.000000000000000 0

0 0 0.999999999999998

Reset the display to the shorter format using format short format affects only

the display of numbers, not the way MATLAB computes or saves them. To

perform element-wise multiplication rather than matrix multiplication, use

the.* operator:

p = a.*a

p =

1 4 9

16 25 36

49 64 100

The matrix operators for multiplication, division, and power each have a

corresponding array operator that operates element-wise. For example, raise

each element of a to the third power:

Page 7: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

7 Dept Of ECE,VSMSRKIT

a.^3

ans =

1 8 27

64 125 216

343 512 1000

Concatenation:

Concatenation is the process of joining arrays to make larger ones. In fact, you

made your first array by concatenating its individual elements. The pair of

square brackets [] is the concatenation operator.

A = [a,a]

A =

1 2 3 1 2 3

4 5 6 4 5 6

7 8 10 7 8 10

Concatenating arrays next to one another using commas is called horizontal

concatenation. Each array must have the same number of rows. Similarly,

when the arrays have the same number of columns, you can concatenate

vertically using semicolons.

A = [a; a] A =

1 2 3

4 5 6

7 8 10

1 2 3

4 5 6

7 8 10

Page 8: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

8 Dept Of ECE,VSMSRKIT

Complex Numbers:

Complex numbers have both real and imaginary parts, where the imaginary

unit is the square root of –1.

sqrt(-1)

ans = 0 + 1.0000i

To represent the imaginary part of complex numbers, use either i or j.

c = [3+4i, 4+3j, -i, 10j]

c = 3.0000 + 4.0000i 4.0000 + 3.0000i 0 - 1.0000i 0

+10.0000i

Array Indexing:

Every variable in MATLAB is an array that can hold many numbers. When you

want to access selected elements of an array, use indexing.

For example, consider the 4-by-4 magic square A:

A = magic(4)

A =

16 2 3 13

5 11 10 8

9 7 6 12

4 14 15 1

There are two ways to refer to a particular element in an array. The most

common way is to specify row and column subscripts, such as

A(4,2)

ans = 14

Less common, but sometimes useful, is to use a single subscript that

traverses down each column in order:

A(8)

ans = 14

Page 9: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

9 Dept Of ECE,VSMSRKIT

Using a single subscript to refer to a particular element in an array is called

linear indexing.

If you try to refer to elements outside an array on the right side of an

assignment statement, MATLAB throws an error.

test = A(4,5)

Attempted to access A(4,5); index out of bounds because size(A)=[4,4].

However, on the left side of an assignment statement, you can specify

elements outside the current dimensions. The size of the array increases to

accommodate the newcomers.

A(4,5) = 17

Example:

A =

16 2 3 13 0

5 11 10 8 0

9 7 6 12 0

4 14 15 1 17

To refer to multiple elements of an array, use the colon operator, which allows

you to specify a range of the form start:end. For example, list the elements in

the first three rows and the second column of A:

A(1:3,2)

ans =2

11

7

The colon alone, without start or end values, specifies all of the elements in

that dimension. For example, select all the columns in the third row of A:

A(3,:)

ans = 9 7 6 12 0

The colon operator also allows you to create an equally spaced vector of

values using the more general form start:step:end.

Page 10: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

10 Dept Of ECE,VSMSRKIT

6) Plot (t, m)

If m= [6 7 8 9]

t= [1 2 3 4]

This instruction will display a figure window which indicates the plot of

m versus t.

7) Stem (t,m)

This Instruction will display a figure window as shown below,

8) Subplot: This function divides the figure window into rows and

Columns.

Example: subplot(3,1,2)-----3-rows, 1-column, 2-location.

Page 11: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

11 Dept Of ECE,VSMSRKIT

WARM UP CYCLE: GENERATION OF SIGNALS

Aim: Generation of impulse signal.

clc;

clear all;

close all;

t=-5:1:5;

y=[zeros(1 ,5),ones(1,1),zeros(1,5)];

stem(t,y);

xlabel('Time');

ylabel('Amplitude');

title('Discrete time impulse function');

Aim: Generation of unit step signal.

clc;

clear all;

close all;

n=input('Enter the n value:');

t=0:1:n-1;

stem(t,y);

xlabel('Time');

ylabel('Amplitude');

title('Discrete time unit step function');

Aim: Generation of ramp signal.

clc;

clear all;

close all;

n=input('Enter the n value:' );

t=0:n;

stem(t,t,'r');

hold on;

plot(t,t,'k');

xlabel('Time');

ylabel('Amplitude');

title('Ramp function');

legend('Discrete','continuous');

Page 12: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

12 Dept Of ECE,VSMSRKIT

Aim:Generation of exponential signal.

clc;

clear all;

close all;

n=input('enter the N value:');

t=0:0.1:n;

a=input('enter the A value:');

y=exp(a*t);

stem(t,y,'y');

hold on;

plot(t,y,'r');

xlabel('Time');

ylabel('Amplitude');

title('Exponential function');

legend('Discrete','continuous');

Aim: Generation of sine wave y(n)=sin(2πfn).

clc;

clear all;

close all;

t=0:0.001:5;

f=1;

y=sin(2*pi*f*t);

plot(t,y,'g');

xlabel('Frequency');

ylabel('amplitude');

title('sine wave');

Aim: Generation of cosine wave y(n)=cos (2πfn).

clc;

clear all;

close all;

t=0:0.001:5;

f=1;

y=cos(2*pi*f*t);

plot(t,y,'g');

xlabel('Frequency');

ylabel('amplitude');

title('cosine wave');

Page 13: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

13 Dept Of ECE,VSMSRKIT

1. SAMPLING THEOREM

Aim: To verify sampling theorem for the following cases:

i) Under sampling ii) Right sampling iii) Over sampling

Program: clc; % clears the command window

clear all;

close all;% clears the variables declared

k=input ('Enter the no of cycles = ');

a=input ('Enter the input signal amplitude= ');

fm=input ('Enter the input frequency = ');

t=0:1/(fm*fm):k/fm;

y=a*cos(2*pi*fm*t)

figure;

subplot(2,2,1)

plot(t,y)

grid on;

xlabel('------t');ylabel('amplitude');

title('The input signal');

fnq=2*fm

% under sampling

fs=3/4*fnq;

tx=0:1/fs:k/fm;

ys=a*cos(2*fm*pi*tx)

subplot(2,2,2);

stem(tx,ys);

hold on

plot(tx,ys,'r');xlabel('------tx');ylabel('amplitude');

title('The under sampling case');

Page 14: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

14 Dept Of ECE,VSMSRKIT

% Nyquist sampling

fs=fnq;

tx=0:1/fs:k/fm;

ys=a*cos(2*pi*fm*tx)

subplot(2,2,3);

stem(tx,ys);

hold on;

plot(tx,ys,'g');xlabel('------tx');ylabel('amplitude');

title('The RIGHT SAMPLING case');

% over sampling

fs=10*fnq;

tx=0:1/fs:k/fm;

ys=a*cos(2*pi*fm*tx)

subplot(2,2,4);

stem(tx,ys);

hold on;

plot(tx,ys,'r');xlabel('------tx');ylabel('amplitude');

title('The OVER SAMPLING case');

Page 15: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

15 Dept Of ECE,VSMSRKIT

2. Convolution and its properties

2a Aim: To find the Linear Convolution of given two sequences

Program:

clc;

clear all;

close all;

x=input('Enter the first input sequence x[n]= ');

xsi=input('Enter the starting index of x[n]= ')

h=input('Enter the first input sequence h[n]= ');

hsi=input('Enter the starting index of h[n]= ')

%To calculate the convolution of x[n] and h[n]%

y = conv(x,h)

%To generate the index arrays%

n1 = xsi:1:length(x)+xsi-1

n2 = hsi:1:length(h)+hsi-1

n3 = xsi+hsi:1:length(x)+length(h)+xsi+hsi-2

%To sketch the result%

subplot(311),stem(n1,x);

xlabel('n1----->'),ylabel('Input Sequence----->')

title ('Input Sequence x(n)')

subplot(312),stem(n2,h);

xlabel('n2----->'),ylabel('Impulse Response----->')

title ('Input Sequence h(n)')

subplot(313),stem(n3,y);

xlabel('n3----->'),ylabel('Output Sequence----->')

title ('Convolution of two sequences')

Result:

Page 16: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

16 Dept Of ECE,VSMSRKIT

2bAim:To find the Circular Convolution of given two

sequences

Program:

clc;

clear all;

close all;

x=input('Enter the first sequence x[n]= ');

h=input('Enter the second sequence h[n]=');

N = max(length(x),length(h));

Y=cconv(x,h,N) %y=xN h%

stem(Y);

xlabel('N----->'),ylabel('Amplitude----->')

title('Plot of circularly convoluted sequence');

Result:

Page 17: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

17 Dept Of ECE,VSMSRKIT

2c.Aim: To prove the commutative ,distributive and associative

property of convolution

1. Commutative property= aN b=bN a

2. Associative property= aN (bN c) = (aN b) N c 3. Distributive property= aN (b+c) = (aN b)+(aN c)

Program: clc;

clear all;

close all;

a1=input('enter the a1 sequence a1=')

b1=input('enter the b1 sequence b1=')

c1=input('enter the c1 sequence c1=')

N1=max(length(a1),length(b1))

N=max(N1,length(c1))

a=[a1,zeros(1,N-length(a1))]

b=[b1,zeros(1,N-length(b1))]

c=[c1,zeros(1,N-length(c1))]

x=cconv(a,b,N1)

y=cconv(b,a,N1) %commutative property aN b=bN a

if x==y

disp('commutative property is proved')

else

disp('commutative property is not proved')

end

t=cconv(b,c,N)

y1=cconv(a,t,N) %associative property aN (bN c)=(aN b) N c

y2=cconv(x,c,N)

if y1==y2

disp('associative property is proved')

else

disp('associative property is not proved')

end

Page 18: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

18 Dept Of ECE,VSMSRKIT

t1= b + c

y3=cconv(a,t1,N)

t2=cconv(a,c,N) % distributive property aN (b+c)=(aN b)+(aN c)

y4= x + t2

if y3==y4

disp('distributive property is proved')

else

disp('distributive property is not proved')

end

Page 19: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

19 Dept Of ECE,VSMSRKIT

3. Auto correlation and its properties.

Aim:To find the Auto correlation of a given sequence and to verify

its properties.

Properties of Auto-correlation:

Property 1:Rxx(l) = Rxx(-l) (Symmetry property).

Property 2: |rxx(l)| ≤rxx(0) = Ex (Energy property).

Program:

clc;

clear all;

close all;

x=input('Enter the sequence x[n]= ');

xsi=input('enter the starting index=');

Rxx=xcorr(x,x)

energy=sum(x.^2)

c_i=ceil(length(Rxx)/2)

Rxx_0=Rxx(c_i)

if Rxx_0==energy

disp('Eneregy property proved.');

else

disp('EnergyProperty not proved');

end

Rxxf=fliplr(Rxx)

if Rxx==Rxxf

disp('It is even.');

else

disp('It is not even.');

end

n1= xsi:length(x)+xsi-1;

n2= -(length(x)-1):(length(x)-1);

subplot(3,1,1),stem(n1,x),xlabel('n1'),ylabel('amplitude');

subplot(3,1,2),stem(n2,Rxx),xlabel('n2'),ylabel('amplitude');

subplot(3,1,3),stem(n2,Rxxf),xlabel('n2'),ylabel('amplitude');

Page 20: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

20 Dept Of ECE,VSMSRKIT

4. Cross correlation and its properties.

Aim:To find the Cross-correlation of two given sequences and to

verify its properties.

Properties of Cross-correlation:

Property 1: Rxy(l) = Ryx(-l) (Symmetry property).

Property 2: |Rxy(l)| ≤ sqrt[Ex.Ey] (Energy property).

Program: clc;

clear all;

close all;

x=input('Enter the first sequence=');

xsi=input('enter the starting index of x=');

xei=input('enter the ending index of x=');

y=input('Enter the second sequence= ');

ysi=input('enter the starting index of y=');

yei=input('enter the ending index of y=');

Ex=sum(x.^2);

Ey=sum(y.^2);

energy=sqrt(Ex*Ey);

Rxy=xcorr(x,y)

Ryx=xcorr(y,x)

Ryxf=fliplr(Ryx);

if Rxy==Ryxf

disp('Symmetry Property is proved');

else

disp('Symmetry property not proved');

end

n1=xsi:length(x)+xsi-1;

n2=ysi:length(y)+ysi-1;

n3=(xsi-yei):(xei-ysi)

subplot(1,4,1),stem(n1,x),xlabel('lag'),ylabel('amplitude');

subplot(1,4,2),stem(n2,y),xlabel('lag'),ylabel('amplitude');

subplot(1,4,3),stem(n3,Rxy),xlabel('lag'),ylabel('amplitude');

subplot(1,4,4),stem(n3,Ryxf),xlabel('lag'),ylabel('amplitude');

Page 21: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

21 Dept Of ECE,VSMSRKIT

5. Solution to Difference Equation

Aim:To solve the given difference equation (DE) with initial

conditions.

Program:

clc;

clear all;

close all;

a=input('Enter the coefficient of y')

b=input('Enter the coefficient of x')

xi=input('Enter the initial values x[-1],x[-2],..= ')

yi=input('Enter the initial values y[-1],y[-2],....= ')

x=input ('Enter the input sequence x= ');

zi=filtic(b,a,yi,xi);

disp('The response of the given system is,');

y = filter(b,a,x,zi)

n= 0:1:length(y)-1;

stem(n,y);

xlabel('n----->'),ylabel('amplitude----->');

title ('solution to a given differential equation with initial

conditions')

Page 22: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

22 Dept Of ECE,VSMSRKIT

6. Discrete Fourier Transformation

Aim: To compute N point DFT of a given sequence x[n] and to plot

magnitude and phase spectrum.

Program:

clc;

clear all;

close all;

x = input('enter the input seq=')

N = length(x);

X = zeros(N,1)

for k = 0:N-1

for n = 0:N-1

X(k+1) = X(k+1) + x(n+1)*exp(-j*pi*2*n*k/N)

end

end

mag=abs(X)

phase=angle(X)*180/pi

t = 0:N-1

subplot(311)

stem(t,x);

xlabel('Time (s)');ylabel('Amplitude');

title('Time domain - Input sequence')

subplot(312)

stem(t,mag)

xlabel('Frequency');ylabel('|X(k)|');

title('Frequency domain - Magnitude response')

subplot(313)

stem(t,phase)

xlabel('Frequency');ylabel('phase(X(k))');

title('Frequency domain - phase response')

Page 23: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

23 Dept Of ECE,VSMSRKIT

with inbuilt function

clc;

clear all;

close all;

x=input('enter the first sequence=')

N=length(x);

X=fft(x,N)

mag=abs(X)

phase=angle(X)*180/pi

t = 0:N-1

subplot(311)

stem(t,x);

xlabel('Time (s)');

ylabel('Amplitude');

title('Time domain - Input sequence');

subplot(312)

stem(t,X)

xlabel('Frequency');

ylabel('|X(k)|');

title('Frequency domain - Magnitude response');

subplot(313)

stem(t,angle(X))

ylabel('phase(X(k))');

title('Frequency domain - phase response');

Page 24: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

24 Dept Of ECE,VSMSRKIT

7. Discrete Fourier Transformation properties

7a.Aim: To verify the properties of DFT like parseval’s theorem and

circular convolution etc.

Linearity property: {a.x(n)+b.y(n)} a.X(K )+ b.Y(K)

Parseval‘s theorem:

Time shift property : x(n-m) WN-(m*k) X(K)

% Program To prove the Linearity property

clear all;

close all;

N=input('enter the value for N= ')

x1=input('enter the x1 input x1=')

x2=input('enter the x2 input x2=')

a=input('enter the x2 input a=')

b=input('enter the x2 input b=')

y1=a.*x1+b.*x1

Y1=fft(y1,N)

X1=fft(x1,N)

X2=fft(x2,N)

Y2=a.*X1+b.*X2

MagY1=abs(Y1)

MagY2=abs(Y2)

phaseY1=angle(Y1)*180/pi

phaseY2=angle(Y2)*180/pi

figure

k=0:1:(N-1)

subplot(2,2,1);stem(k,MagY1)

xlabel('N-point');ylabel('Magnitude of Y1')

subplot(2,2,3);stem(k,MagY2)

xlabel('N-point');ylabel('Magnitude of Y2')

Page 25: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

25 Dept Of ECE,VSMSRKIT

subplot(2,2,2);stem(k,phaseY1)

xlabel('N-point');ylabel('phase of Y2')

subplot(2,2,4);stem(k,phaseY2)

xlabel('N-point');ylabel('phase of Y2')

if Y1==Y2

disp('Linearity property satisfied for the given sequence')

else

disp('Linearity property not satisfied for the given

sequence')

end

% Program To prove the time shifting property of DFT

clc;

clear all;

close all;

x = input('enter the input sequence=')

N = length(x); %data length

W = exp(-j*pi*2/N)

X = fft(x);

subplot(1,2,1)

stem(x);xlabel('---------->N');

ylabel('amplitude');title('plot of input signal x(n)')

k = 0:N-1; % frequency index

m = 2; % number of shift

Y= W.^(-m*k) .* X;

y= ifft(Y)

mag=abs(y)

subplot(1,2,2)

stem(mag);xlabel('---------->N');

ylabel('amplitude');title('plot of input shifted signal x(n-

m)')

Page 26: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

26 Dept Of ECE,VSMSRKIT

% Program To prove the parsevals theorem

clc;

clear all;

close all;

x1=input('enter the 1st input seq=')

x2=input('enter the 2nd input seq=')

N=4;

X1=fft(x1,N)

X2=fft(x2,N)

y1=sum(x1.*conj(x2))

y2=sum(X1.*conj(X2))./N

if y1==y2

disp('parsvals theorem proved');

else

disp('parsevals theorem not proved')

end

Page 27: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

27 Dept Of ECE,VSMSRKIT

7b.Aim: DFT computation of square pulse and Sinc function etc.

a) DFT Computation of square pulse without built in function

clc;

clear all;

close all;

x=[zeros(1,32),ones(1,64),zeros(1,32)]

X=fft(x)

X1=fftshift(X)

subplot(2,1,1)

plot(x)

xlabel('time')

ylabel('amplitude')

title('time domain squer pulse')

subplot(2,1,2)

plot(abs(X1))

xlabel('frequency')

ylabel('magnitude')

title('forrier transform of sequence')

Output:

Page 28: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

28 Dept Of ECE,VSMSRKIT

B) DFT Computation of square pulse with built in function

clc;

clear all;

close all;

A=input('Enter the amplitude of signal pulse=')

f=input('enter the amplitude of squre pulse wave=')

dc=input('enter the duty cycle of squere wave=')

t=0:0.001:1

x=A*square(2*pi*f*t,dc)

X=fft(x)

X1=fftshift(X)

subplot(2,1,1)

plot(x)

xlabel('time')

ylabel('amplitude')

title('time domain squer pulse')

subplot(2,1,2)

plot(abs(X1))

xlabel('frequency')

ylabel('magnitude')

title('forrier transform of sequence'

Page 29: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

29 Dept Of ECE,VSMSRKIT

C) DFT Computation of sinc function

clc;

clear all;

close all;

n=-pi:0.005:pi

x=sinc(n)

X=fft(x)

X1=fftshift(X)

subplot(2,1,1)

plot(x)

xlabel('time')

ylabel('amplitude')

title('time domain sinc function')

subplot(2,1,2)

plot(abs(X1))

xlabel('frequency')

Page 30: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

30 Dept Of ECE,VSMSRKIT

ylabel('magnitude')

title('sinc transform of sequence')

Page 31: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

31 Dept Of ECE,VSMSRKIT

8. FIR Filter design using windowing technique

Aim:To Design a digital FIR low pass filter with following specifications.

a) Pass band cut-off frequency : ωP=__________rad

b) Stop band cut-off frequency : ωS=__________rad

c) Stop band attenuation : kS=__________dB

Choose an appropriate window function and determine impulse response and

provide a plot of frequency response of the designed filter.

Design steps:

1. Choose an appropriate window function from the stop band attenuation

using the following table.

Sl. No. Window function

w[n]

Stop band

attenuation K

1 Rectangular(Boxcar)

window 21 dB 2

2 Triangular (Bartlett)

window 27 dB 4

3 Hanning window 44 dB 4

4 Hamming window 53 dB 4

5 Blackman window 75 dB 6

2. Determine the order of the FIR filter (number of coefficients) using the

relation;

N ≥ sp

k2

Note: Choose N as odd. If N is even select next odd integer.

3. Choose the cut-off frequency of the filter as ωC=ωP+2

Page 32: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

32 Dept Of ECE,VSMSRKIT

4. Choose α =

2

1Nso that linear phase is ensured.

5. The impulse response of the filter is given by

h(n) =

n

ncsin*w(n); for 0<n<N-1 & n ≠ α

c*w(n) ; for n = α

where w(n) is window function.

H(ω) =

2

1Nj

e

*

2

3

0 2

1cos2

2

1

N

n

Nnnh

Nh

Design example:

Design a digital FIR low pass filter with following specifications.

a) Pass band cut-off frequency : 0.3π rad

b) Stop band cut-off frequency : 0.45π rad

c) Stop band attenuation : 50 dB

I step: Choose an appropriate window function from the stop band attenuation

specification.

As Ks = 50 dB select Hamming window.

(Note: Though Blackman window can be used it results in higher transition

bandwidth)

II step:Compute the order of the FIR filter (number of coefficients) using the

relation,

N≥ sp

k2 [K=4 for Hamming window]

N≥ 53.5 (choose N=55)

Page 33: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

33 Dept Of ECE,VSMSRKIT

III step:Choose the cut-off frequency of the filter as ωC= ωP+2

rad.

IV step: Choose α =

2

1Nso that linear phase is ensured.

V step: The impulse response of the filter is given by,

h(n) =

n

ncsin *w(n) ; for0<n<N-1 & n ≠ α.

where w(n) is window function.

h(n) =

1

2cos46.054.0*

27

273.0sin

N

n

n

n

;0<n<N-1 & n ≠ α

For ex : The impulse response coefficients are,

h(0)=0.00029114 = h(54)

h(1)= -5.9806*(10-4) = h(53)……..

Note: when n=α

i.e.h(27) =

c*w(27) =0.3*1=0.3

VI step: Frequency response can be obtained using equation,

H(ω) =

2

1Nj

e

*

2

3

0 2

1cos2

2

1

N

n

Nnnh

Nh

To calculate the Phase, θ(ω) of the FIR filter:

For any N,

0;2

1

2

3

0;2

1

2

HN

HN

Page 34: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

34 Dept Of ECE,VSMSRKIT

Program:

clc;

clear all;

close all;

wp= input('Enter the pass band edge (rad)= ');

ws= input('Enter the stop band edge (rad)= ');

ks= input('Enter the stop band attenuation (dB)= ');

%If 43<Ks<54 choose hamming window.

%To select N,order of filter.

N= (2*pi*4)./(ws-wp); % k=4 for Hamming window.

N= ceil(N); %To round-off N to the next integer.

r = rem(N,2); %Choose odd N.

if(r==0)

N=N+1;

end

wc=(wp+(ws-wp)/2)./pi

% To obtain h(n)

h= fir1(N-1,wc,hamming(N))

% Frequency response

freqz(h,1); % 1 is the normalized frequency

title('Frequency response of the lowpass digital FIR filter')

figure(2), stem(h);

title('Impulse response of the lowpass digital FIR filter')

Page 35: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

35 Dept Of ECE,VSMSRKIT

9. IIR low pass filter

BUTTERWORTH FILTER:

Program:

clc; clear all; close all;

rp=input('enter passband ripple'); % enter rp<3

rs=input('enter stop band ripple'); % enter rs > 20

fp=input('enter passband frequency');

fs=input('enter stopband frequency'); %fs > fp

f=input('enter the sampling frequency'); % f>>>2fp

w1= 2*fp/fs; %Compute normalized frequencies

w2=2*fs/f;

%%%%%LOW PASS FILTER

[n,wn]=buttord(w1,w2,rp,rs,'s'); % Compute

order and cutoff frequency

[b,a]=butter(n,wn,'s'); % Compute poles and

zeros of frequency response w=0:0.001:pi;

[h,om]=freqs(b,a,w);

M=20*log10(abs(h));

subplot(4,1,1);

plot(om/pi,M);

xlabel('Normalized frequency');

ylabel('Gain in dB');

title('Low pass filter');

Page 36: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

36 Dept Of ECE,VSMSRKIT

%%%%%HIGH PASS FILTER

[b,a]=butter(n,wn,'high','s');

w=0:0.001:pi;

[h,om]=freqs(b,a,w);

M=20*log10(abs(h));

subplot(4,1,2);

plot(om/pi,M);

xlabel('Normalized frequency');

ylabel('Gain in dB');

title('High pass filter');

%%%%%BAND PASS FILTER

[n,wn]=buttord(w1,w2,rp,rs,'s');

wn=[w1,w2];

[b,a]=butter(n,wn,'bandpass','s');

w=0:0.001:pi;

[h,om]=freqs(b,a,w);

M=20*log10(abs(h));

subplot(4,1,3);

plot(om/pi,M);

xlabel('Normalized frequency');

ylabel('Gain in dB');

Page 37: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

37 Dept Of ECE,VSMSRKIT

title('Band pass filter');

%%%%%BAND STOP FILTER

[n,wn]=buttord(w1,w2,rp,rs,'s');

wn=[w1,w2];

[b,a]=butter(n,wn,'stop','s');

w=0:0.001:pi;

[h,om]=freqs(b,a,w);

M=20*log10(abs(h));

subplot(4,1,4);

plot(om/pi,M);

xlabel('Normalized frequency');

ylabel('Gain in dB');

title(„Band stop pass filter');

Page 38: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

38 Dept Of ECE,VSMSRKIT

Features of TMS320C6713 DSK Kit

The C6713 DSK is a low-cost standalone development platform that enables

users to evaluate and develop applications for the TI C67xx DSP family. The

DSK also serves as a hardware reference design for the TMS320C6713 DSP.

Key features:

A Texas Instruments TMS320C6713 DSP operates at 225 MHz and

delivers up to 1800 million instructions per second (MIPs).

4 user accessible LEDs and DIP switches.

Software board configuration through registers implemented in CPLD.

Single voltage power supply (+5V).

Embedded JTAG support via USB.

High-quality 24-bit stereo codec.

Four 3.5mm audio jacks for microphone, line in, speaker and line out.

512K words of Flash and 16 MB SDRAM.

Expansion port connector for plug-in modules.

On-board standard IEEE JTAG interface.

A complete Integrated Development Environment (IDE), an efficient

optimizing C/C++ compiler assembler, linker, debugger, an a advanced

editor with Code Maestro™ technology for faster code creation, data

visualization, a profiler and a flexible project manager.

DSP/BIOS™ real-time kernel.

Target error recovery software.

DSK diagnostic tool.

"Plug-in" ability for third-party software for additional functionality.

Fig.1 Block Diagram of TMS320C6713 DSK

Page 39: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

39 Dept Of ECE,VSMSRKIT

DSP PROCESSOR ARCHITECTURE AND APPLICATION

Memory architecture designed for streaming data, using DMA extensively.

Separate program and data memories (Harvard architecture).

Special SIMD (single instruction, multiple data) operations.

Special arithmetic operations, such as fast multiply-accumulates (MACs).

Many fundamental DSP algorithms, such as FIR filters or the Fast Fourier

transform (FFT) depend heavily on multiply-accumulate performance.

Bit-reversed addressing, a special addressing mode useful only for

calculating FFTs.

Deliberate exclusion of a memory management unit. DSPs frequently use

multitasking operating systems, but have no support for virtual memory or

memory protection. Operating systems that use virtual memory require

more time for context switching among processes, which increases latency.

Applications

The main applications of DSP are audio signal processing, audio compression,

digital image processing, video compression, speech processing, speech

recognition and digital communications. Specific examples are speech

compression and transmission in digital mobile phones, equalisation of sound

in Hi-Fi equipment, weather forecasting, economic forecasting, seismic data

processing, analysis and control of industrial processes, computer-generated

animations in movies, medical imaging such as CAT scans and MRI, image

manipulation, and audio effects for use with electric guitar amplifiers. A

further application is very low frequency (VLF) reception with a PC soundcard.

Difference between Microcontroller and DSP Processor

General purpose microprocessor and microcontrollers follow Von Neumann

architecture (or CISC architecture) where Data Memory and Program Memory

have common data and address bus. Instruction execution cycles may be

different for different instructions (depending on the type of operation).

Recent high speed microcontrollers have RISC architecture where most

instructions take a single cycle for execution.

Page 40: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

40 Dept Of ECE,VSMSRKIT

Digital Signal Processors follow Harvard architecture where Data memory and

Program Memory have separate data and address buses. Multiply and

accumulate, Program memory fetch and data memory write are all executed in

a single cycle.

Microcontrollers are primarily used in control-oriented applications that are

interrupt driven sensing and controlling external events. DSPs, meanwhile, are

traditionally found in systems that require the precision processing of analog

signals. As today‘s systems gain in complexity, Microcontrollers are being given

some signal processing capabilities while more DSPs are capable of executing

real-time event-driven functions.

Procedure for execution in TMS3206713 Simulator:

Open CCS Studio Setup3.1

Page 41: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

41 Dept Of ECE,VSMSRKIT

Select 67xx Family

Select Simulator Platform

Page 42: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

42 Dept Of ECE,VSMSRKIT

Select 6713 Device cycle accurate simulator

Now click on “<<Add” Button and then click on Save & Quit button.

Next Click on “Yes” Button to open CCS studio.

Page 43: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

43 Dept Of ECE,VSMSRKIT

Project→New→ProjectName→Location(C:\CCStudio_v3.1\MyProjects\)→Pr

ojecttype (.out Executable) →Target (TMS320C67xx).

Click on File→New→Source File.

Write the code in a new source file. Save it in the project folder with .c

Page 44: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

44 Dept Of ECE,VSMSRKIT

file format.

Add this to the project. Project will be having .pjt extension. Right click

on.pjt file created, add the .c file that you have written.

Two other files are to be added to project. One is library file (*.lib) and

other is Linker command file (*.cmd).

Add rts6713.lib

C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib

Add hello.cmd

C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd

Compile the program using the „Project-compile‟ pull down menu or by

clicking the shortcut icon.

Build the program using the „Project-Build‟ pull down menu or by

clicking the shortcut icon.

Load the .out file (which will be in the debug folder where the project

is stored)using the „File-load program‟ pull down menu.

Run the program using „Debug - Run‟ pull down menu or by clicking

the shortcut icon.

Procedure for execution in TMS320DSK6713 kit:

CCS Studio Setup v3.1 →Family (67xx)→Platform

(dsk)→Endianness→Little endian→Add it to panel. Click on

6713dsk,save and quit.

Connect the power card to the DSP kit.

Connect the data cable → USB from PC

After getting the project window, DEBUG→ CONNECT.

Rest of the procedure is same as compared to simulator running.

Page 45: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

45 Dept Of ECE,VSMSRKIT

1. LINEAR CONVOLUTION

Aim: To compute Linear Convolution of the two given sequences:

Program:

#include<stdio.h>

int y[20];

main()

{

int x[]={ };

int h[]={ };

int l= ,n,k;

for(n=0;n<l;n++)

{

y[n]=0;

for(k=0;k<=n;k++)

y[n]+=x[k]*h[n-k];

}

Printf(“\n Linear convolution output is\n”);

For(n=0;n<l;n++)

Printf(“y[%d]=%d”,n,y[n]);

}

Page 46: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

46 Dept Of ECE,VSMSRKIT

2. CIRCULAR CONVOLUTION

Aim: C-program to compute theCircular Convolution for two given

sequences of length four:

Program: #include<stdio.h>

int y[20];

main()

{

int x[]={ };

int h[]={};

int l=4,n,k;

int a[20],b[20],c[20],d[20];

y[0]=0;

a[0]=h[0];

for(k=1;k<l;k++) /*Folding h(n) to h(-n).*/

a[k]=h[l-k];

for(n=0;n<l;n++) /*Circular convolution.*/

y[0]=y[0]+x[n]*a[n];

y[1]=0;

b[0]=a[l-1];

for(k=1;k<l;k++) /*Folding h(n) to h(-n).*/

b[k]=a[k-1];

for(n=0;n<l;n++) /*Circular convolution.*/

y[1]=y[1]+x[n]*b[n];

y[2]=0;

Page 47: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

47 Dept Of ECE,VSMSRKIT

c[0]=b[l-1];

for(k=1;k<l;k++) /*Folding h(n) to h(-n).*/

c[k]=b[k-1];

for(n=0;n<l;n++) /*Circular convolution.*/

y[2]=y[2]+x[n]*c[n];

y[3]=0;

d[0]=c[l-1];

for(k=1;k<l;k++) /*Folding h(n) to h(-n).*/

d[k]=c[k-1];

for(n=0;n<l;n++) /*Circular convolution.*/

y[3]=y[3]+x[n]*d[n];

Printf(“\n The output of circular convolution is\n”);

for(n=0;n<l;n++)

Printf(“y[%d]=%d\n”,n,y[n]);

Page 48: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

48 Dept Of ECE,VSMSRKIT

3. Computation of n- point dft of a given sequence

Aim: To compute N-point DFT of a given sequence

Program:

#include<stdio.h>

#include<math.h>

main()

{

int N = ,n = 0, k = 0;

int x[] = { };

floatsumRe=0,sumIm=0,costerm=0,sinterm=0,pi= 3.1416;

for(k=0 ; k<N ; k++)

{

sumRe = 0;

sumIm = 0;

for (n=0; n<N ; n++)

{

costerm = cos(2*pi*k*n/N);

sinterm = sin(2*pi*k*n/N);

sumRe = sumRe + x[n] * costerm;

sumIm = sumIm - x[n] * sinterm;

}

printf("X[%d]= %7.3f %7.3fj \n", k,sumRe,sumIm );

}

}

Page 49: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

49 Dept Of ECE,VSMSRKIT

4. IMPULSE RESPONSE

4a) Aim: To compute Impulse Response of the system defined by

its difference equation of first order.

Program:

#include<stdio.h>

#include<math.h>

float y[8];

void main()

{

float x[8];

int num= ;

x[-1]=0;

y[-1]= ;

for(n=0;n<num;n++)

{

if(n==0)

x[n]=1; else

x[n]=0;

y[n]= ;

printf("y[%d]=%f\n",n,y[n]);

}

}

Page 50: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

50 Dept Of ECE,VSMSRKIT

4b) Aim: To compute Impulse Response of the system defined by

its difference equation of second order.

Program:

#include<stdio.h>

#include<math.h>

float y[8];

void main()

{

float x[8];

intnum= ;

x[-1]=0;

y[-1]= ;

y[-2]= ;

for(n=0;n<num;n++)

{

if (n==0)

x[n]=1;

else

x[n]=0;

y[n]= ;

printf("y[%d]=%f\n",n,y[n]);

}

}

Page 51: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

51 Dept Of ECE,VSMSRKIT

5. FIR FILTER

Aim: Realization of an FIR filter (any type) to meet given

specifications.The input can be a signal from function generator /

speech signal.

Procedure:

(1) Connect CRO to the Socket provided for LINE OUTsocket.

(2) Connect a Signal generator to the LINE IN socket.

(3) Switch on the signal generator with a sine wave of frequency >20 Hz and

Vp-p=1v.

(4) Now switch on the DSK and bring up code composer studio on the PC.

(5) Create a new project with name Ex: FIR.pjt or IIR.pjt.

(6) From the File menu newDSP/BIOS Configurationselect

“dsk6713.cdb” and save it as “fir.cdb”

(7) Add “fir.cdb” to the current project.

(8) Add the given “CODEC.C” file to the current project which has the main

function and calls the other necessary routines.

(9) Add the library file “dsk6713bsl.lib” to the current project

path”c:\ccstudio\C6000\dsk6713\lib\dsk6713bsl.lib”

(10) Add new file to the project and save as fir.c and write the source code.

(11) Copy header files “dsk6713.h” and “dsk6713_aic23.h” from

C:\CCStudio_v3.1\c6000\dsk6713\include and paste it in the

Current project folder.

(12) Compile the program.

(13) Build the program.

(14) Load the generated object file (*.out) on to target board.

(15) Run the program

(16) Observe the waveform that appears on the CRO screen.

(17) Vary the frequency on function generator to see the response of filter.

Page 52: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

52 Dept Of ECE,VSMSRKIT

CODEC.C

#include "fircfg.h"

#include "c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713.h"

#include"c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713_aic23.h"

extern signed int FILTER(signed int x);

DSK6713_AIC23_Config config = {\

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */\

0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\

0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */\

0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */\

0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */\

0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */\

0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control

*/\

0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \

0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control

*/\

0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \

};

/*main () - Main code routine, initializes BSL and generates tone */

void main()

{

DSK6713_AIC23_CodecHandle hCodec;

Uint32 l_input, r_input,l_output, r_output;

/* Initialize the board support library, must be called first */

DSK6713_init();

Page 53: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

53 Dept Of ECE,VSMSRKIT

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);

while(1)

{ /* Read a sample to the left channel */

while (!DSK6713_AIC23_read(hCodec, &l_input));

/* Read a sample to the right channel */

while (!DSK6713_AIC23_read(hCodec, &r_input));

l_output=FILTER(l_input);

r_output=l_output;

/* Send a sample to the left channel */

while (!DSK6713_AIC23_write(hCodec, l_output));

/* Send a sample to the right channel */

while (!DSK6713_AIC23_write(hCodec, r_output));

}

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec);

}

Page 54: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

54 Dept Of ECE,VSMSRKIT

FIR FILTER

Calculation:

I. Clearly specify the filter specifications.

Eg: Order = 30;

Sampling Rate = 8000 samples/sec.

Cut off Freq. = 400 Hz.

II. Compute the cut-off frequency Wc.

Eg: Wc= 2* π * fc/ Fs

= 2* π * 400/8000

= 0.1*π

III. Compute the desired Impulse Response hd(n) using particular

Window.

Eg: b_rect1=fir1(order, Wc, boxcar(31));{For Low-pass Filter.}

Eg:b_rect1= fir1(order, Wc, 'high',boxcar(31));{For High-pass

Filter.}

IV. Convolve input sequence with truncated Impulse Response

x (n)*h (n).

Page 55: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

55 Dept Of ECE,VSMSRKIT

Program:

#define ORDER 30

float h[] ={0.0161,0.0208,0.0062,-0.0169,-0.0276,

-0.0132,0.0176,0.0383, 0.0256,-0.0181,

-0.0598,-0.0553,0.0184,0.1410, 0.2558,

0.3025, 0.2558,0.1410,0.0184,-0.0553,

-0.0598,-0.0181,0.0256,0.0383, 0.0176,

-0.0132,-0.0276,-0.0169,0.0062,0.0208,

0.0161};

static short in_buffer[100];

signedint FILTER(signed int x)

{

int i=0;

signed long output=0;

in_buffer[0] = x;

for(i=ORDER;i>0;i--)

in_buffer[i] = in_buffer[i-1];

for(i=0;i<ORDER+1;i++)

output = output + h[i] * in_buffer[i];

return(output);

}

Page 56: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

56 Dept Of ECE,VSMSRKIT

Result:

The output plot is observed on the CRO.

This behaves as a low-pass filter.

See the effect of filtering by giving a sinusoidal input to DSP kit and

slowly varying its frequency.

Observe the cutoff frequency of the filter.

Change the filter co-efficients for different types of window & Cut-

off frequencies.

(Refer FIR filter design part from experiment-10 in part A-MATLAB)

Page 57: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

57 Dept Of ECE,VSMSRKIT

Additional Programs

1. Interference Suppression

Aim: To add noise above 3kHz and then remove; Interference

suppression using 400 Hz tone.

Procedure:

1. Generate a 400Hz tone corrupted by a 4kHz sinusoid for a 0.0052 second

duration.

2. Design a FIR LPF of order 30,and assign the coefficients to variable b[ ].

3. Set up the loop for the output variable (for the number of samples

required).

4. Assign sum=0.

5. Find the sum=b0x[n] + b1x[n-1] + …….. + b30x[n-30];inner loop.

6. Assign y[n]=sum, end of output loop.

7. Verify the results using matlab.

Program:

#include<stdio.h>

float x[101]={0, 0.6506,1.0764 ,1.1384,0.8365,0.3090,

-0.2197,-0.5253, -0.4693,-0.0520,0.5878,

1.2252, 1.6356, 1.6800, 1.3583, 0.8090,

0.2565,-0.0747,-0.0462, 0.3420, 0.9511,

1.5564, 1.9333, 1.9432, 1.5858, 1.0000,

0.4102, 0.0411, 0.0312, 0.3808, 0.9511,

1.5176, 1.8559, 1.8274, 1.4321, 0.8090,

0.1827,-0.2221,-0.2665, 0.0496, 0.5878,

1.1236, 1.4328, 1.3768, 0.9559, 0.3090,

-0.3391,-0.7637,-0.8257,-0.5250,-0.0000,

0.5250, 0.8257, 0.7637, 0.3391,-0.3090,

-0.9559,-1.3768,-1.4328,-1.1236,-0.5878,

-0.0496, 0.2665, 0.2221,-0.1827,-0.8090,

Page 58: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

58 Dept Of ECE,VSMSRKIT

-1.4321,-1.8274,-1.8559,-1.5176,-0.9511,

-0.3808,-0.0312,-0.0411,-0.4102,-1.0000,

-1.5858,-1.9432,-1.9333,-1.5564,-0.9511,

-0.3420, 0.0462, 0.0747,-0.2565,-0.8090,

-1.3583,-1.6800,-1.6356,-1.2252,-0.5878,

0.0520, 0.4693, 0.5253, 0.2197,-0.3090,

-0.8365,-1.1384,-1.0764,-0.6506,0.0000};

float h[31]={0.0048,0.0054,0.0072,0.0101,0.0141,

0.0188,0.0243,0.0301,0.0361,0.0419,

0.0474,0.0523,0.0563,0.0593,0.0612,

0.0618,0.0612,0.0593,0.0563,0.0523,

0.0474,0.0419,0.0361,0.0301,0.0243,

0.0188,0.0141,0.0101,0.0072,0.0054,

0.0048};

float y[101]={0.0};

void main()

{

int N=30,k=0,n=0;

float sum;

for (n=0;n<101;n++)

{

sum=0;

for(k=0;k<N;k++)

if(n-k>=0)

{

sum=sum+h[k]*x[n-k];

}

y[n]=sum;

}

for(n=0;n<101;n++)

printf("y[%d] = %f \n",n,y[n]);

}

Page 59: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

59 Dept Of ECE,VSMSRKIT

MATLAB program to generate the filter coefficients and to verify the

result:

clc;

clear all;

close all;

t=0:0.000025:0.0025;

x=sin(2*pi*400*t)+sin(2*pi*4000*t)

b=fir1(30,800/40000)

y=filter(b,1,x);

plot(t,x,'b',t,y,'r')

legend('Corrupted Signal', 'Original Signal');

Result:

The 4kHz interfering tone is successfully suppressed and is

observed in the plot and also the obtained result is verified in the

MATLAB.

Page 60: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

60 Dept Of ECE,VSMSRKIT

2. MATLAB program to verify the circular convolution property of

DFT

Circular convolution property: x(n)©y(n) X(k)Y(k)

% program to prove circular convolution property of DFT

clc;

clear all;

close all;

x1=input('enter the 1st input seq=')

x2=input('enter the 2nd input seq=')

N= input('enter the value for N=')

y1=cconv(x1,x2,N)

X1=fft(x1,N)

X2=fft(x2,N)

H=X1.*X2

y2=ifft(H,N)

if y1 == y2

disp('circular convolution property is proved');

else

disp('circular convolution property is not proved');

end

subplot(2,1,1)

stem(y1);

xlabel('N------>'),ylabel('amplitude')

subplot(2,1,2)

stem(y2);

xlabel('N------>'),ylabel('amplitude')

Page 61: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

61 Dept Of ECE,VSMSRKIT

REFERENCES

[1]. Digital signal processing using MATLAB –SanjeetMitra, TMH,2001.

[2]. Digital signal processing using MATLAB - J. G. Proakis&Ingale, MGH,

2000.

[3]. Digital Signal Processors, B. Venkataramani and Bhaskar, TMH,2002.

[4]. A.Gilat, MATLAB: An Introduction with Applications, John Wiley &

Sons, Inc. 2004.

[5]. R. Pratap, Getting Started with MATLAB 7: A Quick Introduction for

Scientists and Engineers, Oxford University Press, 2009.

[6]. D. Hanselman and B. Little_eld, Mastering MATLAB 5: A

Comprehensive Tutorial and Reference,Prentice Hall, 1998.

[7]. B. R. Hunt, R. L. Lipsman, and J. M. Rosenberg (with K. R. Coombes,

J. E. Osborn, and G. J.Stuck), A Guide to MATLAB: for beginners and

experienced users, Cambridge University Press 2001.

[8] RulphChassaing, “DSP Applications Using C and the TMS320C6X

DSK”, John Wiley, New York, 2002

Page 62: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

62 Dept Of ECE,VSMSRKIT

VIVA

1) What is DSP? Why do we need DSP?

2) List the merits and demerits of DSP

3) What are the applications of DSP?

4) What is sampling theorem?

5) What is aliasing effect?

6) Define Quantization.

7) Explain the principle of operation of analog to digital conversion of the

signal with a neat diagram.

8) Explain the significance of Nyquist rate and aliasing during the

sampling of continuous time signals.

9) What do you mean by process of reconstruction?

10) What are techniques of reconstructions?

11) What do you mean Aliasing? What is the condition to avoid aliasing

for sampling?

12) Write the conditions of sampling.How many types of sampling there?

13) Explain the statement: t= 0:0.000005:0.05

In the above example what does colon (: ) and semicolon (; ) denotes.

14) What is a) Undersampling b) nyquist plot c) Oversampling.

15) What is MATLAB? What are the applications of MATLAB?

16) What is the use of command ‗legend‘?

17) Distinguish between ‗plot‘ and ‗stem‘ functions.

18) Explain the function ‗subplot‘?

19) What is convolution? What are the properties of convolution?

20) What is linear convolution?

21) Distinguish between Linear convolution and circular convolution.

22) How will you obtain linear convolution from circular convolution?

23) Explain how convolution syntax built in function works.

24) What is the total output length of linear convolution sum?

25) What is an LTI system?

Page 63: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

63 Dept Of ECE,VSMSRKIT

26) Describe impulse response of a function.

27) What is the difference between convolution and filter?

28) Where to use command ‗filter‘ or ‗impz‘, and what is the difference

between these two?

29) What is the use of function command ‗deconv‘?

30) What is the difference between linear and circular convolution?

31) What do you mean by statement subplot (3,3,1).

32) What do you mean by command ―mod‖ and where it is used?

33) What do you mean by Autocorrelation and Crosscorrelation

sequences?

34) What is the difference between Autocorrelatio and Crosscorrelation?

35) List all the properties of autocorrelation and Crosscorrelaion

sequence.

36) Where we use the inbuilt function ‗xcorr‘ and what is the purpose of

using this function?

37) How to calculate output of DFT using MATLAB?

38) Distinguish between DFT and DTFT.

39) Where DFT is used?

40) What is the difference between DFT and IDFT?

41) What do you mean by built in function ‗abs‘ and where it is used?

42) What do you mean by phase spectrum and magnitude spectrum/give

comparison.

43) How to compute maximum length N for a circular convolution using

DFT and IDFT. (What is the command?).

44) Explain the statement- y=x1.*x2

45) What is FFT?

46) Why FFT is needed?

47) What is meant by Radix-2 FFT?

48) What is decimation-in-time algorithm?

49) What is decimation in frequency algorithm?

50) What are the differences and similarities between DIF and DIT

algorithm?

Page 64: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

64 Dept Of ECE,VSMSRKIT

51) How many stages are there for 8-point DFT?

52) How many multiplication terms are required for doing DFT by

expressional method and FFT method?

53) What is the main advantage of FFT?

54) What are the applications of FFT algorithms?

55) What do you mean by ‗filtic‘ command, explain.

56) How to calculate output length of the linear and circular convolution?

57) What do you mean by built in function ‗fliplr‘ and where we need to

use this?

58) What is steady state response?

59) Which built in function is used to solve a given difference equation?

60) Explain the concept of difference equation.

61) What is filter?

62) What are the types of digital filter according to their impulse

response?

63) What is FIR Filter?

64) Write the procedure for designing FIR filters

65) Write the characteristics of FIR filter.

66) What are the advantages and disadvantages and applications of FIR

FILTER?

67) What is GIBBS phenomenon?

68) Write the desirable characteristics of frequency response of window

functions.

69) Write the characteristics features of rectangular window.

70) List merits and demerits of rectangular window.

71) What do you understand by linear phase response?

72) What are the advantages of Kaiser Window?

73) What is the need for employing window technique for FIR filter design?

74) What is windowing and why it is necessary?

75) What is the necessary and sufficient condition for linear phase

characteristic in FIR filter?

76) Define IIR filter.

Page 65: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

65 Dept Of ECE,VSMSRKIT

77) What are the methods available for designing analog IIR filter?

78) Mention the importance of IIR filter.

79) What is warping effect?

80) Compare analog and digital filter.

81) What is FIR and IIR filter define, and distinguish between these two.

82) Explain the command – N=ceil(6.6*pi/tb)

83) What is the matlab command for Hamming window? Explain.

84) What do you mean by cut-off frequency?

85) What are the differences between FIR and IIR filters?

86) What are the differences between Butterworth and Chebyshevfilters?

87) What do you mean by command ‗butter‘ and ‗cheby1‘?

88) Explain the command in detail-[N,wc]=buttord(2*fp/fs,2*fstp/fs,rp,As)

89) What are the Features of TMS320C6713 DSK Kit?

90) What are the Difference between the Microcontroller and the DSP

Processor?

91) What is CCS? Explain in detail to execute a program using CCS.

92) Why do we need of CCS?

93) How to execute a program using 'dsk' and 'simulator'?

94) Which IC is used in CCS? Explain the dsk, dsp kit.

95) What do you mean by noise?

96) Explain the program for linear convolution for your given sequence.

97) Why we are using command 'float' in CCS programs.

98) Where we use 'float' and where we use 'int'?

99) Explain the command: i=(n-k)%N

100) Explain the entire CCS program in step by step of execution.

Page 66: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

66 Dept Of ECE,VSMSRKIT

DIGITAL SIGNAL PROCESSING LABORATORY Question Bank

A. Programs based on MATLAB implementation:

1) By using MATLAB implementation sample a band limited continuous time

signal band limited to frn = ………….Hz i) fs< 2fm ii) fs = 2fm iii) fs ≤2fm

2) Using MATLAB Compute the linear convolution of two given finite length of

sequences. Given: x(n)=[……………. ] and h(n)=[ ……………]

3) Using MATLAB Compute the circular convolution of two given finite length

of sequences. Given: x(n)=[ ………………..] and h(n)=[……………….]

4) Using MATLAB verify the associative, commutative and distributive

properties of convolution for the sequences. Given: x(n)=[………………] and

h(n)=[………………..]

5) Using MATLAB Compute the autocorrelation of a reference sequence and

verify its properties. Given: x(n)=[ …………………].

6) Using MATLAB Compute the cross correlation of two given finite length of

sequences and verify its properties. Given: Ref sequence x(n)=[……………]

and h(n)=[……………..]

7) Obtain the complete response of the system described by the following

difference equation …………………for the input x(n)=[ ……….] With initial

conditions …………………. Use MATLAB as a tool.

8) For a given sequence x(n)=[…………..].Compute the N-point DFT using

MATLAB. Plot magnitude and phase spectrum.(with equation method

and verify using built in function)

Page 67: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

67 Dept Of ECE,VSMSRKIT

9) Verify the DFT properties for given sequences. Given: x(n)=[………………]

and x2(n)=[………………..]

10) Compute the DFT for square pulse and sinc function.

11) Using MATLAB design a low-pass FIR filter with the following

Specifications:

a) Pass band cut-off frequency : ωP=__________rad

b) Stop band cut-off frequency : ωS=__________rad

c) Stop band attenuation : kS=__________dB

Plot the Frequency, phase and impulse response of the designed filter.

12) Using MATLAB, design a low-pass IIR Butterworth filter with the

following specifications.

kP = Pass band attenuation(dB) =

kS = Stop band attenuation( dB) =

fP = Pass band edge(Hz) =

fS = Stop band edge(Hz) =

FS = ST

1= Sampling rate (samples/sec) =

Plot the Magnitude Frequency response of the low-pass Butterworth

filter.

13) Using MATLAB ,design alow-pass IIR Chebyshev type I filter with the

Following specifications.

kP = Pass band attenuation(dB) =

kS = Stop band attenuation( dB) =

fP = Pass band edge(Hz) =

fS = Stop band edge(Hz) =

FS = ST

1= Sampling rate (samples/sec) =

Page 68: DSP LAB -15ECL57 - Nipani

DSP LAB -17ECL57

68 Dept Of ECE,VSMSRKIT

B. Programs based on DSP Processor TMS320C6713 (Code Composer

Studio):

1) Write a C program to compute linear convolution of two sequences for DSP

Processor (TMS320C671 3).Given: x (n) = […………] and h(n) = […………….]

Execute the program on Simulator/Emulator (DSP Starter kit - Board).

2) Write a C program to compute circular convolution of two sequences for

DSP Processor (TMS320C6713).Given: x(n)=[ ………………..] and

h(n)=[………….].

Execute the program on Simulator/Emulator (DSP Starter kit - Board).

3) Write a C program to find the impulse response of first and second order

system for DSP Processor (TMS320C6713). Assume zero initial conditions

for an initially relaxed system.

Given: First order equation:……………………….

Second order equation: ……………………

Execute the program on Simulator/Emulator (DSP Starter kit - Board).

4) Write a C program to compute N — Point DFT of a sequence for DSP

Processor (TMS320C6713).Given: x(n) = […………………………………….]

Execute the program on Simulator/Emulator (DSP Starter kit - Board).

5) Write a C program to realize the lowpass/highpass FIR filter to meet given

specifications. The input can be a signal from function generator / speech

signal for DSP Processor (TMS320C6713).

Given the the filter specifications.

Order (N).

Sampling Rate.

Cut off Freq.


Recommended