Digital Signal Processing Lab: Practical Record
Digital Signal Processing Lab: Practical Record
title('The recovered sinusidal sampled at fs Hz'); xlabel('Time in seconds'); ylabel('Amplitude in volts'); % over sampling fs=3*f3; %fs = sampling frequency is greater than twice the max f ts=1/fs; tx=0:ts:0.1; m=max(size(tx)); ys=cos(2*pi*f1*tx)+cos(2*pi*f2*tx); figure(3); subplot(3,1,1); plot(t,y); grid on; title('The sinusoidal signal cos(2*pi*f1*t)+cos(2*pi*f2*t)'); xlabel('Time in seconds'); ylabel('Amplitude in volts'); subplot(3,1,2); stem(tx,ys); grid on; title('The sinusoidal signal sampled at fs Hz'); xlabel('Time in seconds'); ylabel('Amplitude in volts'); subplot(3,1,3); plot(tx,ys); grid on; title('The recovered sinusidal sampled at fs Hz'); xlabel('Time in seconds'); ylabel('Amplitude in volts');
Output:
1. Under Sampling:
2. Over Sampling
3. Right Sampling
Output:
X Coefficients: 0.2, 0.4, 0.6 Y Coefficients: 1.5, 1.99, 0.45 H coefficients: 0, 0, 0, 0, 0.133, 0.898, 0.2409, -3.465, 0.3874, -0.4101, 0.4278, -0.4445, -0.4614, 0.4787 Graph Output:
Output:
Console output:
Graph output:
Output:
Console output:
Graph output:
Output:
Console output:
Graph output:
Output:
Console:
Graph:
Code 2:
% y(n) -0.25 y(n-1) -0.125 y(n-2)= x(n) with x(n)=u(n)-u(n-10) and initial condition y(-1)=1, y(-2)=-2 b=input('enter the coefficients of x'); a=input('enter the coefficients of y'); c=input('enter the initial conditions'); n=[-5:50]; ic=filtic(b,a,c); x=[(n>=0)]-[(n>10)]; y=filter(b,a,x,ic); subplot(2,1,1); stem(n,x); title('input sequence x(n)'); xlabel('n'); ylabel('x'); subplot(2,1,2); stem(n,y); title('output sequence y(n)'); xlabel('n'); ylabel('y');
Output:
Input data: Y Coefficients: 1, -0.5 AND -0.25, -0.125, -1 X Coefficients: 1, 1 AND 1, -1 Initial condition: y(-1)=1, y(-2)=-2 Graph output:
Output:
Console:
Graph:
Output:
Console:
Graph:
Output:
Console:
1 4 10 20 30 40 43
Output:
30 25 25 30 40
Output:
11.000000+j0.000000 -0.407551+j-7.660229 -1.009553+j1.996802 2.424618+j-3.646700 -4.999949+j-0.022297 2.396778+j3.673697 -0.971310+j-2.009436 -0.460720+j7.633044
Experiment 13: Program to implement impulse response of order 2 using a DSP processor
Code: #include <stdio.h> #define order 2 // Define the order of impulse response #define len 10 // Define the length float Y[len]={0,0,0},sum; main() { int j,k; float a[order+1]={1,1,1}; float b[order+1]={1,2,1}; for(j=0;j<len;j++) { sum=0.0; for(k=1;k<=order;k++) { if((j-k)>=0) sum=sum+(a[k]*Y{j-k]); } if(j<=order) Y[j]=b[j]-sum; else Y[j]=sum; printf("response[%d]= %f",j,Y[j];); //print the computed response } } }
Output:
Response Response Response Response Response Response Response Response Response Response [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] = = = = = = = = = = 1.000000 1.000000 -1.000000 0.000000 -1.000000 -1.000000 -2.000000 -3.000000 -5.000000 -8.000000
plot(f/pi,H_mag); %Blackman% figure(5); y=blackman(n1); b=fir1(n,wp,y); [H,f]=freqz(b,1,256); H_mag=20*log10(abs(H)); plot(f/pi,H_mag); %Kaiser% figure(6); y=kaiser(n1); b=fir1(n,wp,y); [H,f]=freqz(b,1,256); H_mag=20*log10(abs(H)); plot(f/pi,H_mag);
Output:
Console:
Graphs:
Output:
Console:
Graphs: