0% found this document useful (0 votes)
67 views

Index: S.No Program Page No. Signatur E 1. 2

The document discusses digital signal processing programs and window techniques. It contains 8 programs that generate signals, perform linear convolution, design Butterworth and Chebyshev filters, take the FFT, and plot the DTFT. It then discusses how window functions can be applied to filters to reduce oscillations by modifying Fourier coefficients and converting discontinuities into transition bands. Common window functions include rectangular, Hamming, Hanning, and Blackman windows.

Uploaded by

Shiv Ahuja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Index: S.No Program Page No. Signatur E 1. 2

The document discusses digital signal processing programs and window techniques. It contains 8 programs that generate signals, perform linear convolution, design Butterworth and Chebyshev filters, take the FFT, and plot the DTFT. It then discusses how window functions can be applied to filters to reduce oscillations by modifying Fourier coefficients and converting discontinuities into transition bands. Common window functions include rectangular, Hamming, Hanning, and Blackman windows.

Uploaded by

Shiv Ahuja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 22

Digital Signal Processing Practical File

INDEX
S.NO 1. PROGRAM
Program for the generation of unit impulse, unit step, ramp, exponential, sinusoidal and cosine sequences:Program for the linear convolution of the sequence X = [ 1 2 ] and h = [ 1, 2, 4 ]. Program for the design of Butterworth low pass digital filter. Program for the design of Butterworth high pass digital filter Program for the design of Chebyshev Type-I low pass digital filter Program for the design of Chebyshev Type-I high pass digital filter Program to compute the FFT of the sequence and plot. Program to plot the DTFT of 10 point sequence Window Techniques

PAGE NO. SIGNATUR E 2

2. 3. 4. 5. 6. 7. 8. 9.

5 7 9 11 13 15 17 19

1SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

PROGRAM NO.1
Program for the generation of unit impulse, unit step, ramp, exponential, sinusoidal and cosine sequences. clc;clear all;close all; t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)];subplot(2,2,1);stem(t,y); ylabel('amplitude-->'); xlabel('(a) n-->'); n=input('enter the N value'); t=0:1:n-1; y1=ones(1,n);subplot(2,2,2); stem(t,y1);ylabel('amplitude-->'); xlabel('(b) n-->'); n1=input('enter the length of ramp sequence'); t=0:n1; subplot(2,2,3);stem(t,t);ylabel('amplitude-->'); xlabel('(c) n-->'); n2=input('enter the length of exponential sequence'); t=0:n2; a=input('enter the a value'); y2=exp(a*t);subplot(2,2,4); stem(t,y2);ylabel('amplitude-->'); xlabel('(d) n-->'); t=0:.01:pi; y=sin(2*pi*t);figure(2); subplot(2,1,1);plot(t,y);ylabel('amplitude-->'); xlabel('(a)n-->'); t=0:.01:pi; y=cos(2*pi*t); subplot(2,1,2);plot(t,y);ylabel('amplitude-->'); xlabel('(b) n-->');

2SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

OUTPUT:-

enter enter enter enter

the the the the

N value 7 length of ramp sequence 7 length of exponential sequence 7 a value 1

3SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

PROGRAM NO.2

4SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Program for the Linear convolution of the sequence X = [ 1 2 ] and h = [ 1, 2, 4 ].

clc; clear all; close all; x=input('enter the 1st sequence'); h=input('enter the 2nd sequence'); y=conv(x,h); figure;subplot(3,1,1); stem(x);ylabel('amplitude-->'); xlabel('(a) n-->'); subplot(3,1,2); stem(h);ylabel('amplitude-->'); xlabel('(b)n-->'); subplot(3,1,3); stem(y);ylabel('amplitude-->'); xlabel('(c)n--.'); disp('the resultant singal is ');y

OUTPUT :5SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

enter the 1st sequence [12] enter the 2nd sequence [124] the resultant singal is y= 1488

PROGRAM NO.3
6SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Program for the design of Butterworth low pass digital filter. clc; close all;clear all; format long rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); wp=input('enter the passband frequency'); ws=input('enter the stopband frequency'); fs=input('enter the sampling frequency'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); [b,a]=butter(n,wn); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('gain in db-->');xlabel('(a) normalised frequency-->'); subplot(2,1,2);plot(om/pi,an); xlabel('(b) normalized frequency-->'); ylabel('phase in radians-->');

OUTPUT :-

7SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

enter enter enter enter enter

the the the the the

passband ripple 0.5 stopband ripple 50 passband frequency 1200 stopband frequency 2400 sampling frequency 10000

PROGRAM NO.4

8SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Program for the design of Butterworth high pass digital filter. clc; close all;clear all; format long; rp=input('Enter the passband ripple'); rs=input('Enter the stopband ripple'); wp=input('Enter the passband frequency'); ws=input('Enter the stopband frequency'); fs=input('Enter the sampling frequency'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); [b,a]=butter(n,wn,'high'); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('gain in db-->');xlabel('(a) Normalised frequency-->'); subplot(2,1,2);plot(om/pi,an); xlabel('(b) Normalised frequency-->'); ylabel('phase in radians-->');

OUTPUT :Enter the passband ripple 0.5

9SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Enter Enter Enter Enter

the the the the

stopband ripple 50 passband frequency 1200 stopband frequency 2400 sampling frequency 10000

PROGRAM NO. 5
Program for the design of Chebyshev Type-I low pass digital filter.
10SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

clc; close all;clear all; format long; rp=input('Enter the passband ripple...'); rs=input('Enter the stopand ripple...'); wp=input('Ener the passband frequency...'); ws=input('Enter the stopband frequency...'); fs=input('Enter the sampling frequency...'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); [b,a]=cheby1(n,rp,wn); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('Gain in db-->');xlabel('(a) Normalised frequency-->'); subplot(2,1,2);plot(om/pi,an); xlabel('(b) Normalised frequency-->'); ylabel('Phase in raduians-->');

OUTPUT :Enter the passband ripple... 0.2 Enter the stopand ripple... 45 Ener the passband frequency... 1300

11SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Enter the stopband frequency... 1500 Enter the sampling frequency... 10000

PROGRAM NO. 6
Program for the design of Chebyshev Type-I high pass digital filter.

12SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

clc; close all;clear all; format long; rp=input('Enter the passband ripple...'); rs=input('Enter the stopband ripple...'); wp=input('Enter the passband frequency...'); ws=input('Enter the stopband frequency...'); fs=input('Enter the sampling frequency...'); w1=2*wp/fs;w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); [b,a]=cheby1(n,rp,wn,'high'); w=0:.01/pi:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1);plot(om/pi,m); ylabel('Gain in db-->');xlabel('(a) Normalised frequency-->'); subplot(2,1,2);plot(om/pi,an); xlabel('(b) Normalised frequency-->'); ylabel('phase in radians-->');

OUTPUT:Enter Enter Enter Enter the the the the passband ripple... 0.3 stopband ripple... 60 passband frequency... 1500 stopband frequency... 2000

13SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Enter the sampling frequency... 9000

PROGRAM NO. 7
Program to compute the FFT of the sequence and plot.

xn=[1,1,1]; n=50;
14SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

xk=fft(xn,n); magxk=abs(xk); angxk=angle(xk); k=0:n-1; subplot(2,1,1), stem(k,magxk); xlabel('k'),ylabel('!x(k)!'); subplot(2,1,2), stem(k,angxk); xlabel('k'), ylabel('arg(x(k)');

OUTPUT:-

15SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

PROGRAM NO. 8
Program to plot the DTFT of 10 point sequence.

%reading the desired length of DTFT


16SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

clc; title('No of freq points='); k=10; %reading num & den coeff. title('num coeff='); num=[1,2,4,6,7,8,9,10,5,3] title('den coeff='); den=[2,4,6,7,8,9,10,1,5,3] %compute freq response w=0:pi/(k-1):pi; h=freqz(num,den,w); a=real(h); b=imag(h); c=abs(h); d=angle(h); subplot(2,2,1); plot(a,w); subplot(2,2,2); plot(b,w); subplot(2,2,3); plot(c,w); subplot(2,2,4); plot(d,w);

OUTPUT:-

17SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

WINDOW TECHNIQUES
The finite duration impulse response may be converted to a finite duration impulse response simply by truncating the finite series n= N. however, this results in undesirable oscillations in the pass band and stop band of the digital filter. This is because of the slow convergence of the Fourier series near the points of

18SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

discontinuity. These undesirable oscillations can be reduced by using a set of timelimited weighting functions, w(n), known as window functions, to modify the Fourier coefficients. A major effect of windowing is that the discontinuities in H(e jw) are converted into transition bands between values on either side of the discontinuity. The width of these transition bands depends on the width of the main lobe of W(ejw). A secondary effect of windowing is that the ripples from the side lobes W(ejw) produces approximation errors for all w. Base on the above discussion, the desirable characteristics can be listed as under: 1. The Fourier transform of the window function W(ejw) must have a small width of main lobe having as much as of the total energy as possible. 2. The Fourier transform of the window function W(ejw) should have a side lobes which decrease in energy rapidly as w tends to pie. Some of the most frequently used window functions are described in the following sections to follow: 1. RECTANGULAR WINDOW FUNCTION (i.e TECHNIQUE): The rectangular window is denoted as wr(n) and it is defined as wR (n) = 1, for |n| (M-1)/2 0, otherwise We can obtain the spectrum of wr(n) by taking Fourier transform of equation as, WR(ejwT)= (M-1)/2 e-jwnT n= -(M-1)/2

Substituting n= m-(M-1)/2 and replacing m by n, we obtain, (M-1) e-jwnT n=0

WR(e )= e
jwT

jw(M-1)T/2

or or

WR(ejwT)= ejw(M-1)T/2 (1-ejwMT) / (1-e-jwT) WR(ejwT)= ( ejwMT/2 e-jwMT/2 ) / (ejwT/2 - e-jwT/2)

We know that e j- e-j = 2j sin Hence, above equation becomes WR(ejwT)= sin(wMT/2) / sin(wT/2)

19SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

The transition width of the main lobe is approximately 4pie/m. the first sidelobe will be 13 db down the peak of the main lobe and the roll off will be at 20 db per decade. For a casual rectangular window, the frequency response can be written as, WR(e ) =
jwT

(M-1) e-jwnT = e-jw(M-1)T/2 sin(wMT/2) / sin(wT/2) n=0

From equations, it may be noted that the linear phase response of the casual filter is written as (w) = w(M-1)T/2 , and the non-casual impulse response will have a zero phase shift.

2. HAMMING WINDOW FUNCTION (i.e TECHNIQUE): The hamming widow function is denoted as wH(n) and is given by WH(n) = 0.54 0.46 cos 2n / (M-1), 0 n M-1 0, elsewhere

The hamming window function (non-casual) is expressed as WH(n) = 0.54 0.46 cos ( 2n / (M-1) ), for | n | M-1 0, elsewhere

It may be observed that the non-casual hamming window function is related to the rectangular window function as shown below: wH(n) = wR(n) [ 0.54 + 0.46 Cos [ 2n / (M-1) ] In addition to this, the spectrum of hamming window can be obtained as

WH(ejwT) = 0.54 Sin [ wMT / 2] / Sin [ wT / 2 ] + 0.46 Sin [ wMT/2 M/(M-1) ] / Sin [ wT/2 /(M-1) ] + 0.46 Sin [ wMT/2 + M/(M-1) ] / Sin [ wT/2 + /(M-1) ] Further, we note that the width of the main lobe is approximately 8pie/m and the peak of he first side lobe is at -43 bd. The side lobe roll off is 20 db/decade. For a casual hamming window the second and third terms are negative as shown below: WH(ejwT) = 0.54 Sin [ wMT / 2] / Sin [ wT / 2 ] - 0.46 Sin [ wMT/2 M/(M-1)]/Sin [ wT/2

20SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

/(M-1) ] - 0.46 Sin [ wMT/2 + M/(M-1) ] / Sin [ wT/2 + /(M-1) ] 3. HANNING WINDOW FUNCTION (i.e. TECHNIQUE): the hanning window function (casual) is represented by wHann(n) is expressed as wHann(n) = 0.5 0.5 Cos ( 2n / (M-1) ), for 0 n M-1 0, elsewhere

On the other hand, the hanning window function (non-casual) is expressed as wHann(n) = 0.5 + 0.5 Cos ( 2n / (M-1) ), for 0 | n | M-1 0, elsewhere

In addition to this, the width of the main lobe is approximately 8pie/m and the peak of first side lobe is at -32 db. 4. BARTLETT WINDOW FUCTION (i.e TECHNIQUE): The Bartlett window function (non-casual) is denoted by wbart(n) and is given by wBart(n) = 1 + n, for (M-1) / 2 < n<1 1- n, for 1 < n< (M-1)/2

5. BLACKMAN WINDOW FUNCTION (i.e TECHNIQUE): Blackman window function (casual) is denoted as wb(n) and is given by wB(n) = 0.42 0.5 Cos [ 2n / (M-1) ] +0.08 Cos [ 4n / (M-1) ], 0 n M-1 0, otherwise

On the other hand, Blackman window function (non-casual) is given by wB(n) = 0.42 + 0.5 Cos [ 2n / (M-1) ] +0.08 Cos [ 4n / (M-1) ], for | n | (M-1)/2 0, otherwise

21SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

Digital Signal Processing Practical File

Further, the width of the main lobe will approximately be 12pie/m and the peak of the first side-lobe will be at -58 db. 6. THE KAISER WINDOW TECHNIQUES : a desirable property of the window function is that the function is of finite duration in the time domain and that the Fourier transform has the maximum energy in the main lobe or a given peak side lobe amplitude. The prolate spheroidal functions have this desirable property. But, these functions are quite complicated and hard to compute. A simple approximation to these functions have been developed by Kaiser in terms of zeroth order modified Bessel function of the first kind. In a Kaiser window, the side lobe level may be controlled with respect to the main lobe peak by varying a parameter, the width of the main lobe can be varied by adjusting the length of the filter. Thus, the Kaiser Window functions is given as wK(n) = ( Io () ) / ( Io ( ) ), for | n | (M-1)/2 0, otherwise is

Here is an independent variable found by Kaiser. Also, the parameter expressed as = [ 1- ( 2n / (M-1) )2 ]
0.5

22SWAMI

DEVI DYAL INSTITUTE OF ENGINEERING & TECHNOLOGY, BARWALA

You might also like