Você está na página 1de 13

# DIGITAL SIGNAL PROCESSING

PRACTICAL FILE
SUBMITTED BY: PAWAN SEHGAL ROLL NUM: 02116412810 ECE (6TH SEMESTER)

INDEX
1) 2) 3) 4) Impulse Response Of An Lti System Linear Convolution Of Two Sequences Circular Convolution Of Two Sequences Dft Of An Input Sequence

## 1) IMPULSE RESPONSE OF AN LTI SYSTEM

clc; clear all; N=input('Enter the required length of impulse response N = '); n=0:N-1; b=input('Enter the co-efficients of x(n), b = '); a=input('Enter the co=efficients of y(n), a = '); x=[1,zeros(1,N-1)]; y=filter(b,a,x); stem(n,y); xlabel('time'); ylabel('amplitude'); title('IMPULSE RESPONSE'); grid on;

OUTPUT:
Enter the required length of impulse response N = 40 Enter the co-efficients of x(n), b = [0.8 -0.44 0.36 0.02] Enter the co=efficients of y(n), a = [1 0.7 -0.45 -0.6]

## 2) LINEAR CONVOLUTION OF TWO SEQUENCES

clc; clear all; x = input('Enter the sequence x(n) = '); subplot(3,1,1); stem(x); xlabel('time'); ylabel('amplitude'); title('INPUT SEQUENCE'); grid on; h = input('Enter the sequence h(n) = '); subplot(3,1,2); stem(h); xlabel('time'); ylabel('amplitude'); title('IMPULSE RESPONCE SEQUENCE'); grid on; lenx = length(x); lenh = length(h); for n = 1:lenx + lenh

y(n) = 0; for k = 1:lenx if n>k && n-k <= lenh y(n) = y(n) + x(k)*h(n-k); end end end

%lenx + lenh -1 is not used because the limit of k starts from 1 and not from 0

disp('The linear convolution sequence is = '); y subplot(3,1,3); stem(y); xlabel('time'); ylabel('amplitude'); title('CONVOLUTION SEQUENCE'); grid on;

OUTPUT:
Enter the sequence x(n) = [2 4 12 4 5] Enter the sequence h(n) = [6 9 11 4 6] The linear convolution sequence is = 0 12 42 130 184 226 161 143 44 30

## 3) CIRCULAR CONVOLUTION OF TWO SEQUENCES

clc; clear all; x = input('Enter the sequence x(n) = '); subplot(3,1,1); stem(x); xlabel('time'); ylabel('amplitude'); title('INPUT SEQUENCE'); grid on; h = input('Enter the sequence h(n) = '); subplot(3,1,2); stem(h); xlabel('time'); ylabel('amplitude'); title('IMPULSE RESPONCE SEQUENCE'); grid on; n1=length(x); n2=length(h); N=max(n1,n2); x=[x,zeros(1,N-n1)]; h=[h,zeros(1,N-n2)]; for n=0:N-1; y(n+1)=0; for k=0:N-1; j= mod(n-k,N); y(n+1)=y(n+1)+x(k+1)*h(j+1); end end disp('The circular convolution sequence is = '); y subplot(3,1,3); stem(y); xlabel('time'); ylabel('amplitude'); title('CIRCULAR CONVOLUTION SEQUENCE'); grid on;

OUTPUT:
Enter the sequence x(n) = [1 23 4 5] Enter the sequence h(n) = [8 5 12 9] The circular convolution sequence is = 288 285 204 345

## 4) DFT OF AN INPUT SEQUENCE

clc; clear all; x = input('Enter the sequence x(n) = '); subplot(3,1,1); stem(x); xlabel('time'); ylabel('amplitude'); title('INPUT SEQUENCE'); grid on; y1 = fft(x); disp('The dft sequence is = '); y1 subplot(3,1,2); stem(y1); xlabel('frequency(w)'); ylabel('amplitude'); title('DFT SEQUENCE'); grid on; y2 = fft(x,4); disp('The 4-point dft sequence is = '); y2 subplot(3,1,3); stem(y2); xlabel('frequency(w)'); ylabel('amplitude'); title('4-POINT DFT SEQUENCE'); grid on;

OUTPUT:
Enter the sequence x(n) = [1 2 3 4 ] The dft sequence is = y1 = 10.0000

## -2.0000 + 2.0000i -2.0000

-2.0000 - 2.0000i

## -2.0000 + 2.0000i -2.0000

-2.0000 - 2.0000i

## 5) BUTTERWORTH LOW PASS FILTER

clc; clear all; close all; rp=input('enter the passband attenuation:'); rs=input('enter the stop band attenuation:'); wp=input('enter the pass band frequency:'); ws=input('enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn); freqz(b,a); fprintf('the normalized cutoff frequency is = %f.',wn); fprintf('\nthe order of filter is = %f.',N);

OUTPUT:
enter the pass band attenuation:0.4 enter the stop band attenuation:30 enter the pass band frequency:0.2*pi enter the stop band frequency:0.4*pi the normalized cutoff frequency is = 0.246943. the order of filter is = 6.000000.

## 6) BUTTERWORTH HIGH PASS FILTER

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn,'high'); freqz(b,a); fprintf('the normalized cutoff frequency is = %f.',wn); fprintf('\nthe order of filter is = %f.',N);

OUTPUT:
Enter the pass band attenuation:0.4 Enter the stop band attenuation:30 Enter the pass band frequency:0.4*pi Enter the stop band frequency:0.2*pi the normalized cutoff frequency is = 0.333524. the order of filter is = 6.000000.

## 7) BUTTERWORTH BANDPASS FILTER

clc; clear all; close all; rp=input('enter the passband attenuation:'); rs=input('enter the stop band attenuation:'); wp=input('enter the pass band frequency:'); ws=input('enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn); freqz(b,a); fprintf('the normalized cutoff frequency is = %f.',wn); fprintf('\nthe order of filter is = %f.',N);

OUTPUT:
enter the passband attenuation:0.4 enter the stop band attenuation:30 enter the pass band frequency:[0.2*pi,0.6*pi] enter the stop band frequency:[0.1*pi,0.7*pi] the normalized cutoff frequency is = 0.181939. the normalized cutoff frequency is = 0.629932. the order of filter is = 10.000000.

## 8) BUTTERWORTH BAND STOP FILTER

clc; clear all; close all; rp=input('enter the passband attenuation:'); rs=input('enter the stop band attenuation:'); wp=input('enter the pass band frequency:'); ws=input('enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn); freqz(b,a); fprintf('the normalized cutoff frequency is = %f.',wn); fprintf('\nthe order of filter is = %f.',N);

OUTPUT:
enter the passband attenuation:0.4 enter the stop band attenuation:30 enter the pass band frequency:[0.1*pi,0.7*pi] enter the stop band frequency:[0.2*pi,0.6*pi] the normalized cutoff frequency is = 0.159976. the normalized cutoff frequency is = 0.668229. the order of filter is = 10.000000.