MPDSP LAB Dr.K.V. SUBBAREDDY INSTITUTE OF TECHNOLOGY DUPADU, KURNOOL Department of Electronics & Communications Engineering III B.Tech-II Sem (E.C.E) DEPARTMENT OF ECE Dr.KVSRIT Page 1
Feb 15, 2016
MPDSP LAB
Dr.K.V. SUBBAREDDY INSTITUTE OF TECHNOLOGYDUPADU, KURNOOL
Department of Electronics & Communications EngineeringIII B.Tech-II Sem (E.C.E)
DEPARTMENT OF ECE Dr.KVSRIT Page 1
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)DIGITAL SIGNAL PROCESSING LAB
LIST OF EXPERIMENTS
CYCLE 1: Software Experiments (Minimum of 5 experiments are to be conducted)
1) Generation of random signal and plot the same as a waveform showing all the specifications.
2) Finding Power and (or) Energy of a given signal.3) Convolution and Correlation (auto and cross correlation) of discrete sequences without
using built in functions for convolution and correlation operations.4) DTFT of a given signal5) N – point FFT algorithm6) Design of FIR filter using windowing technique and verify the frequency response of the
filter.7) Design of IIR filter using any of the available methods and verify the frequency response of
the filter.8) Design of analog filters.
CYCLE 2: Using DSP Processor kits(Minimum of 5 experiments are to be conducted)
1) Generation of random signal and plot the same as a waveform showing all the specifications.
2) Finding Power and (or) Energy of a given signal.3) Convolution and Correlation (auto and cross correlation) of discrete sequences without
using built in functions for convolution and correlation operations.4) DTFT of a given signal5) N – point FFT algorithm6) Design of FIR filter using windowing technique and verify the frequency response of the
filter.7) Design of IIR filter using any of the available methods and verify the frequency response of
the filter.8) Design of analog filters.
DEPARTMENT OF ECE Dr.KVSRIT Page 2
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
DEPARTMENT OF ECE Dr.KVSRIT Page 3
MPDSP LAB
III B.Tech-II Sem (ECE)
1) Generation of random signal and plot the same as a waveform showing all the
specifications
a) Generation of Sinusoidal signal
AIM : Generation of Sinusoidal Signal.
APPARATUS REQUIRED : MATLAB Software
PROGRAM : clc; clear all; close all; disp('SINE SIGNAL');N=input('Enter Number of Samples : '); n=0:.1:N x=sin(n) stem(n,x); xlabel('Time'); ylabel('Amplitude'); title('sine Signal');
OUTPUT: SINE SIGNAL Enter Number of Samples : 16
DEPARTMENT OF ECE Dr.KVSRIT Page 4
MPDSP LAB
RESULT:- Thus the MATLAB program for generation of Sinusoidal signal was performed and the output was verified.
b) Generation of Square signal
DEPARTMENT OF ECE Dr.KVSRIT Page 5
MPDSP LAB
AIM : Generation of Square Signal.
APPARATUS REQUIRED : MATLAB Software
PROGRAM :
clear all;close all;clc; N = input('Enter the number of cycles in a square wave....:: ');M = input('Enter the period of the square wave ....:: '); y=0:0.001:2;for j=0:M/2:M*N; x=y; plot(j,x,'r'); hold on;endfor k=0:M:M*N; x=k+y; m=2; plot(x,m,'r') hold onendfor k=2:M:M*N; x=k+y; m=0; plot(x,m,'r'); hold on;endhold offaxis([0 12 -0.5 2.5])xlabel('time---->');ylabel('Amplitude--->');title('Square wave');
OUTPUT
Enter the number of cycles in a square wave....:: 3
DEPARTMENT OF ECE Dr.KVSRIT Page 6
MPDSP LAB
Enter the period of the square wave ....:: 4
RESULT:- Thus the MATLAB program for generation Square wave was performed and the output was verified.
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)DEPARTMENT OF ECE Dr.KVSRIT Page 7
MPDSP LAB
2) Finding Power and (or) Energy of a given signal.
AIM : Finding Power and (or) Energy of a given signal.
APPARATUS REQUIRED : MATLAB Software
PROGRAM :
clear all;close all;clc; t = 0:0.01:4;tes = cos(2*pi*t); M = length(tes);sum = 0;for i = 1:M, sum = sum + tes(i)*tes(i);end;disp('Energy of the given sequence is ..... :: ');Energy = sumdisp('Average Power of the given sequence is ..... :: ');Average_power = sum/M
OUTPUT
Energy of the given sequence is ..... ::
Energy = 201
Average Power of the given sequence is ..... ::
Average_power = 0.5012
RESULT:- The power and energy of the given signal is calculated by using a matlab program
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
DEPARTMENT OF ECE Dr.KVSRIT Page 8
MPDSP LAB
3) Convolution and Correlation (auto and cross correlation) of discrete sequences without using built in functions for convolution and correlation operations.
a) Linear Convolution
AIM : To write a program in MATLAB to perform linear Convolution between two
discrete time sequences
APPARATUS REQUIRED : MATLAB Software
PROGRAM : % MATLAB program for linear convolution%linear convolution programclc;clear all;close all;disp('linear convolution program');x=input('enter i/p x(n):');m=length(x);h=input('enter i/p h(n):');n=length(h);x=[x,zeros(1,n)];subplot(2,2,1), stem(x);title('i/p sequence x(n)is:');xlabel('---->n');ylabel('---->x(n)');grid;h=[h,zeros(1,m)];subplot(2,2,2), stem(h);title('i/p sequence h(n)is:');xlabel('---->n');ylabel('---->h(n)');grid;disp('convolution of x(n) & h(n) is y(n):');y=zeros(1,m+n-1);for i=1:m+n-1y(i)=0;for j=1:m+n-1if(j<i+1)y(i)=y(i)+x(j)*h(i-j+1);end
DEPARTMENT OF ECE Dr.KVSRIT Page 9
MPDSP LAB
endendsubplot(2,2,[3,4]),stem(y);title('convolution of x(n) & h(n) is :');xlabel('---->n'); ylabel('---->y(n)');grid;
OUTPUT :
RESULT : The linear convolution of two sequences is verified by using MATLAB program.
b) Auto Correlation
AIM : To write a program in MATLAB to perform Auto Correlation of Discrète Sequences.
DEPARTMENT OF ECE Dr.KVSRIT Page 10
MPDSP LAB
APPARATUS REQUIRED : MATLAB Software
PROGRAM :
clc;clear all;close all;%% Inputs% You can specify the inputs or can take them through command window% h= input ('enter the sequence h');% x= input ('enter the sequence x');h=[1 1 2 3 4];x=[1 3 5 7 9 2 4 6 8];pp=h;qq=x;% Plot the inputs% subplot(3,1,1); stem(h,'m'); title ('h');ylabel('amplitude')% %% subplot(3,1,2); stem(x,'b'); title ('x');ylabel('amplitude')%% calculate the cross correlationl1= length (h); % calculate length of sequence hl2= length (x); % calculate length of sequence xl=abs (l1-l2); % calculate difference in lengths of sequenceif (l1 > l2)x= [x zeros(1,l)];else if(l2 > l)h= [h zeros(1,l)]; endend h= [h zeros(1, max (l1, l2))];for shift= 0:max(l1,l2); new_x = [zeros(1, shift) x zeros(1, (max (l1 , l2))-shift)];y(shift+1,:)= sum(h.* new_x);endy=y';% Display the correlation sumsubplot(3,1,1); stem(pp,'m'); title ('h');ylabel('amplitude')subplot(3,1,2); stem(qq,'b'); title ('x');ylabel('amplitude')subplot(3,1,3); stem(y,'r'); title ('cross correlation'); xlabel('time');
OUTPUT :RESULT :
DEPARTMENT OF ECE Dr.KVSRIT Page 11
MPDSP LAB
c) Cross Correlation
AIM : To write a program in MATLAB to perform Cross Correlation of Discrète Sequences.
APPARATUS REQUIRED : MATLAB Software
PROGRAM :
close all;
DEPARTMENT OF ECE Dr.KVSRIT Page 12
MPDSP LAB
clear all;clc;x=input('enter the value of 1st sequence');j=input('enter the value of 2nd sequence');h=fliplr(j);disp('the 1st sequence is-');disp(x); disp('the 2nd sequence is-');disp(j);lx=length(x);lh=length(h);n=lx+lh-1;subplot(3,1,1);stem(x);title('1st sequence');subplot(3,1,2);stem(j);title('2nd sequence');hh=[h zeros(1,n-lh)];xx=zeros(n);xx(1:lx,1)=x;for i=2:n for j=2:n xx(j,i)=xx(j-1,i-1); end;end;yy=xx*hh';subplot(3,1,3);stem(yy);disp('cross correlate o/p->');disp(yy');title('y=cross correlastion of x & j');
OUTPUT :RESULT :
DEPARTMENT OF ECE Dr.KVSRIT Page 13
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
4) DTFT of a given signal
AIM : To find DTFT of a given signal.
APPARATUS REQUIRED : MATLAB Software
PROGRAM :
% Write a MATLAB program to find the DTFT of a given sequence. %Enter the sequence : [1 3 5 6 7 2 4 9 8]
x=input('Enter the sequence : ')
DEPARTMENT OF ECE Dr.KVSRIT Page 14
MPDSP LAB
N=length(x)n=0:N-1K=0:N-1wn=exp(-j*2*pi/N)nK=n'*KwNnK=wn.^nKdf=x*wNnKsubplot(3,1,1)stem(x,abs(df))title('DTFT')xlabel('K')ylabel('Magnitude')subplot(3,1,2)stem(x,angle(df))title('DTFT')xlabel('K')ylabel('phase')wn=exp(j*2*pi/N)nK=n'*KwNnK=wn.^nKinversdf=(x*wNnK)/Nsubplot(3,1,3)stem(x,abs(inversdf))title('Inverse DTFT')xlabel('N')ylabel('Magnitude')
OUTPUT :RESULT :
DEPARTMENT OF ECE Dr.KVSRIT Page 15
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
5) N-point FFT algoritm
AIM : To find N-FFT of a given Sequence
APPARATUS REQUIRED : MATLAB Software
PROGRAM :%fast fourier transformclc;clear all;close all;tic;x=input('enter the sequence');n=input('enter the length of fft');%compute fftdisp('fourier transformed signal');X=fft(x,n)subplot(1,2,1);stem(x);title('i/p signal');
DEPARTMENT OF ECE Dr.KVSRIT Page 16
MPDSP LAB
xlabel('n --->');ylabel('x(n) -->');grid;subplot(1,2,2);stem(X);title('fft of i/p x(n) is:');xlabel('Real axis --->');ylabel('Imaginary axis -->');grid;
OUTPUT:
DEPARTMENT OF ECE Dr.KVSRIT Page 17
MPDSP LAB
RESULT: The FFT of a given sequence is verified using MATLAB program
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
6) FIR filtersDEPARTMENT OF ECE Dr.KVSRIT Page 18
MPDSP LAB
AIM : To write a program in MATLAB to Verify FIR filters
SOFTWARE : MATLAB software
PROGRAM : %fir filt design window techniquesclc;clear all;close all;rp=input('enter passband ripple');rs=input('enter the stopband ripple');fp=input('enter passband freq');fs=input('enter stopband freq');f=input('enter sampling freq ');wp=2*fp/f;ws=2*fs/f;num=-20*log10(sqrt(rp*rs))-13;dem=14.6*(fs-fp)/f;n=ceil(num/dem);n1=n+1;if(rem(n,2)~=0)n1=n;n=n-1;endc=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');if(c==1)y=rectwin(n1);disp('Rectangular window filter response');endif (c==2)y=triang(n1);disp('Triangular window filter response');endif(c==3)y=kaiser(n1);disp('kaiser window filter response');end%LPFb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,1);plot(o/pi,m);title('LPF');ylabel('Gain in dB-->');
DEPARTMENT OF ECE Dr.KVSRIT Page 19
MPDSP LAB
xlabel('(a) Normalized frequency-->');%HPFb=fir1(n,wp,'high',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,2);plot(o/pi,m);title('HPF');ylabel('Gain in dB-->'); xlabel('(b) Normalized frequency-->');%BPFwn=[wp ws];b=fir1(n,wn,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,3);plot(o/pi,m);title('BPF');ylabel('Gain in dB-->');xlabel('(c) Normalized frequency-->');%BSFb=fir1(n,wn,'stop',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,4);plot(o/pi,m);title('BSF');ylabel('Gain in dB-->');xlabel('(d) Normalized frequency-->');
OUTPUT:
DEPARTMENT OF ECE Dr.KVSRIT Page 20
MPDSP LAB
DEPARTMENT OF ECE Dr.KVSRIT Page 21
MPDSP LAB
RESULT: Using MATLAB program the FIR filter Verified.
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
DEPARTMENT OF ECE Dr.KVSRIT Page 22
MPDSP LAB
III B.Tech-II Sem (ECE)
7) IIR filters
AIM : To write a program in MATLAB to Verify IIR filters
SOFTWARE : MATLAB software
PROGRAM : % IIR filters LPF & HPFclc;clear all;close all;disp('enter the IIR filter design specifications');rp=input('enter the passband ripple');rs=input('enter the stopband ripple');wp=input('enter the passband freq');ws=input('enter the stopband freq');fs=input('enter the sampling freq');w1=2*wp/fs;w2=2*ws/fs;[n,wn]=buttord(w1,w2,rp,rs,'s');c=input('enter choice of filter 1. LPF 2. HPF \n ');if(c==1)disp('Frequency response of IIR LPF is:');[b,a]=butter(n,wn,'low','s');endif(c==2)disp('Frequency response of IIR HPF is:');[b,a]=butter(n,wn,'high','s');endw=0:.01:pi;[h,om]=freqs(b,a,w);m=20*log10(abs(h));an=angle(h);figure,subplot(2,1,1);plot(om/pi,m);title('magnitude response of IIR filter is:');xlabel('(a) Normalized freq. -->');ylabel('Gain in dB-->');subplot(2,1,2);plot(om/pi,an);title('phase response of IIR filter is:');xlabel('(b) Normalized freq. -->');ylabel('Phase in radians-->');
DEPARTMENT OF ECE Dr.KVSRIT Page 23
MPDSP LAB
RESULT: Using MATLAB program the IIR filter Verified.
DEPARTMENT OF ECE Dr.KVSRIT Page 24
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ECE Dr.KVSRIT Page 25
MPDSP LAB
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERINGIII B.Tech-II Sem (ECE)
1) Generation of sine wave and square wave
AIM:- To generate a sine wave and square wave using C6713 simulator
EQUIPMENTS:-
Operating System - Windows XP Software - CC STUDIO 3 DSK 6713 DSP Trainer kit. USB Cable Power supply
PROCEDURE:-
1. Open Code Composer Setup and select C6713 simulator, click save and quit2. Start a new project using „Project-> New‟ pull down menu, save it in a separate
directory (C:\My projects) with file name sinewave.pjt3. Create a new source file using File->New->Source file menu and save it in the project
folder(sinewave.c)4. Add the source file (sinewave.c) to the project
ProjectAdd files to ProjectSelect sinewave.c5. Add the linker command file hello.cmd
Project -> Add files to Project (path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)6. Add the run time support library file rts6700.lib
ProjectAdd files to Project (path: C\CCStudio\cgtools\lib\rts6700.lib)7. Compile the program using „projectCompile‟ menu or by Ctrl+F78. Build the program using „projectBuild‟ menu or by F79. Load the sinewave.out file (from project folder lcconv\Debug) using FileLoad Program10. Run the program using „DebugRun or F511. To view the output graphically Select ViewGraphTime and Frequency12. Repeat the steps 2 to 11 for square wave
PROGRAM: (a)
DEPARTMENT OF ECE Dr.KVSRIT Page 26
MPDSP LAB
#include <stdio.h> #include <math.h> float a[500]; void main() { int i=0; for(i=0;i<500;i++) { a[i]=sin(2*3.14*10000*i); } }
PROGRAM: (b)
#include <stdio.h> #include <math.h> int a[1000]; void main() { int i,j=0; int b=5; for(i=0;i<10;i++) { for (j=0;j<=50;j++) { a[(50*i)+j]=b; } b=b*(-1) ; } }
Output:- Sine wave
DEPARTMENT OF ECE Dr.KVSRIT Page 27
MPDSP LAB
DEPARTMENT OF ECE Dr.KVSRIT Page 28
MPDSP LAB
Square wave:-
Result:- The sine wave and square wave has been obtained.
DEPARTMENT OF ECE Dr.KVSRIT Page 29
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
2) LINEAR CONVOLUTION
AIM: To verify Linear Convolution
EQUIPMENTS:-
Operating System - Windows XP Software - CC STUDIO 3 DSK 6713 DSP Trainer kit. USB Cable Power supply
PROCEDURE: 1. Open Code Composer Setup and select C6713 simulator, click save and quit 2. Start a new project using Project New pull down menu, save it in a separate directory
(C:\My projects) with file name linearconv.pjt 3. Create a new source file using File New Source file menu and save it in the project folder (linearconv.c)
4. Add the source file (linearconv.c) to the project Project Add files to Project Select linearconv.c
5. Add the linker command file hello.cmd Project Add files to Project
(path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)
6. Add the run time support library file rts6700.lib Project Add files to Project
(Path: C\CCStudio\cgtools\lib\rts6700.lib) 7. Compile the program using project Compile menu or by Ctrl+F7 8. Build the program using project Build menu or by F7
9. Load the linearconv.out file (from project folder impulse response\Debug) using File Load Program 10. Run the program using „Debug Run or F5 11. To view the output graphically Select ViewGraph Time and Frequency 12. observe the values in the output window.
DEPARTMENT OF ECE Dr.KVSRIT Page 30
MPDSP LAB
PROGRAM:
// Linear convolution program in c language using CC Studio #include<stdio.h> int x[15],h[15],y[15]; main() { int i,j,m,n; printf("\n enter value for m"); scanf("%d",&m); printf("\n enter value for n");scanf("%d",&n); printf("Enter values for i/p x(n):\n"); for(i=0;i<m;i++) scanf("%d",&x[i]); printf("Enter Values for i/p h(n) \n"); for(i=0;i<n; i++) scanf("%d",&h[i]); // padding of zeros for(i=m;i<=m+n-1;i++) x[i]=0; for(i=n;i<=m+n-1;i++) h[i]=0; /* convolution operation */for(i=0;i<m+n-1;i++) { y[i]=0; for(j=0;j<=i;j++) { y[i]=y[i]+(x[j]*h[i-j]); } } //displaying the o/p for(i=0;i<m+n-1;i++) printf("\n The Value of output y[%d]=%d",i,y[i]); }
DEPARTMENT OF ECE Dr.KVSRIT Page 31
MPDSP LAB
Output:-
enter value for m 4 enter value for n 4 Enter values for i/p 1234 Enter Values for n 1234
The Value of output y[0]=1 The Value of output y[1]=4 The Value of output y[2]=10 The Value of output y[3]=20 The Value of output y[4]=25 The Value of output y[5]=24 The Value of output y[6]=16
RESULT: Thus linear convolution of 2 sequences is verified using CC Studio
DEPARTMENT OF ECE Dr.KVSRIT Page 32
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
3) FIR FILTER DESIGN
AIM: To verify FIR filter using CCS Studio.
EQUIPMENTS:-
Operating System - Windows XP Software - CC STUDIO 3 DSK 6713 DSP Trainer kit. USB Cable Power supply
PROGRAM:
#include<stdio.h>#include<math.h>#define pi 3.1415int n,N,c;float wr[64],wt[64];void main(){printf("\n enter no. of samples,N= :"); scanf("%d",&N);printf("\n enter choice of window function\n 1.rect \n 2. triang \n c= :");scanf("%d",&c);printf("\n elements of window function are:"); switch(c){case 1:for(n=0;n<=N-1;n++){wr[n]=1;printf(" \n wr[%d]=%f",n,wr[n]);}break;case 2:for(n=0;n<=N-1;n++)
DEPARTMENT OF ECE Dr.KVSRIT Page 33
MPDSP LAB
{wt[n]=1-(2*(float)n/(N-1));printf("\n wt[%d]=%f",n,wt[n]);}break; } }
OUTPUT:
DEPARTMENT OF ECE Dr.KVSRIT Page 34
MPDSP LAB
RESULT:
Here we designed FIR filter Using CC studio.
DEPARTMENT OF ECE Dr.KVSRIT Page 35
MPDSP LAB
Dr.K.V.Subba Reddy Institute of Technology:KURNOOLDEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
III B.Tech-II Sem (ECE)
4) IIR FILTER DESIGN
AIM: To verify IIR filter using CCS Studio.
EQUIPMENTS:-
Operating System - Windows XP Software - CC STUDIO 3 DSK 6713 DSP Trainer kit. USB Cable Power supply
PROGRAM:
//iirfilters#include<stdio.h>#include<math.h>int i,w,wc,c,N;float H[100];float mul(float, int);void main(){printf("\n enter order of filter ");scanf("%d",&N);printf("\n enter the cutoff freq ");scanf("%d",&wc);printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");scanf("%d",&c);switch(c){case 1:for(w=0;w<100;w++){H[w]=1/sqrt(1+mul((w/(float)wc),2*N));printf("H[%d]=%f\n",w,H[w]);}break;
DEPARTMENT OF ECE Dr.KVSRIT Page 36
MPDSP LAB
case 2:for(w=0;w<=100;w++){H[w]=1/sqrt(1+mul((float)wc/w,2*N));printf("H[%d]=%f\n",w,H[w]);}break;}}float mul(float a,int x){for(i=0;i<x-1;i++)a*=a;return(a);}
OUTPUT:
DEPARTMENT OF ECE Dr.KVSRIT Page 37
MPDSP LAB
RESULT:
Here we designed IIR filter Using CC studio.
DEPARTMENT OF ECE Dr.KVSRIT Page 38