Dsp Lab Manual.pdf

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Dsp Lab Manual.pdf as PDF for free.

More details

  • Words: 5,968
  • Pages: 51
SVS Institute of Technology

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD III Year B.Tech. ECE - II Sem

L T/P/D C 0

-/3/-

2

DIGITAL SIGNAL PROCESSING LAB (EC604PC) Note: 1. The Programs shall be implemented in Software (Using MATLAB / Lab View / C Programming/ Equivalent) and Hardware (Using TI / Analog Devices / Motorola / Equivalent DSP processors). 2. Minimum of 12 experiments to be conducted. List of Experiments: 1. Generation of Sinusoidal Waveform / Signal based on Recursive Difference Equations 2. Histogram of White Gaussian Noise and Uniformly Distributed Noise. 3. To find DFT / IDFT of given DT Signal 4. To find Frequency Response of a given System given in Transfer Function/Differential equation form. 5. Obtain Fourier series coefficients by formula and using FET and compare for half sine wave. 6. Implementation of FFT of given Sequence 7. Determination of Power Spectrum of a given Signal(s). 8. Implementation of LP FIR Filter for a given Sequence/Signal. 9. Implementation of HP IIR Filter for a given Sequence/Signal 10. Generation of Narrow Band Signal through Filtering 11. Generation of DTMF Signals 12. Implementation of Decimation Process 13. Implementation of Interpolation Process 14. Implementation of I/D Sampling Rate Converters 15. Impulse Response of First order and Second Order Systems Note: - Minimum of 12 experiments has to be conducted.

Department of ECE

SVS Institute of Technology

Introduction to MAT Lab The name MATLAB stands for matrix laboratory. It was invented in the late 1970s by Cleve Moler, then chairman of the computer science department at the University of New Mexico. MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-productivity

research,

development

and

analysis. MATLAB was first adopted by control design engineers, Little's specialty, but quickly spread to many other domains. It is now also used in education, in particular the teaching of linear algebra and numerical analysis, and is popular amongst scientists involved with image processing. MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Its wide range of commands, functions, and language constructs permit users to solve and analyze difficult computational problems from science and engineering without programming in a general purpose language. Typical uses include:

Department of ECE

SVS Institute of Technology

1. Math and computation 2. Algorithm development 3. Modeling, simulation and prototyping 4. Data analysis, exploration and visualization 5. Scientific and engineering graphics 6. Application development, including graphical user interface building REAL TIME APPLICATIONS 1. DATA SECURITY 2. IMAGE MANIPULATIONS 3. SIGNAL PROCESSING 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. 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. Department of ECE

SVS Institute of Technology

Basic Instructions in Mat lab 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. F= 20: 1: 100 Therefore F = [20 21 22 23 24 ……… 100] 3. T= 0:1/pi: 1 Therefore T= [0, 0.3183, 0.6366, 0.9549] 4. zeros (1, 3) The above instruction creates a vector of one row and three columns whose values are zero Output= [0 0 0] 5. zeros( 2,4) Output = 0 0 0 0 0000 6. ones (5,2) The above instruction creates a vector of five rows and two columns 9. plot (t, x) If x = [6 7 8 9]

t = [1 2 3 4]

This instruction will display a figure window which indicates the plot of x versus t 10. stem (t,x) :- This instruction will display a figure window as shown 11. Conv Syntax: w = conv(u,v) Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as multiplying the polynomials whose coefficients are the elements of u and v. 12.Disp Syntax: disp(X) Department of ECE

SVS Institute of Technology

Description: disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed.Another way to display an array on the screen is to type its name, but this prints a leading "X=," which is not always desirable.Note that disp does not display empty arrays. 13.xlabel Syntax: xlabel('string') Description: xlabel('string') labels the x-axis of the current axes. 14. ylabel Syntax : ylabel('string') Description: ylabel('string') labels the y-axis of the current axes. 15.Title Syntax : title('string') Description: title('string') outputs the string at the top and in the center of the current axes. 16.grid on Syntax : grid on Description: grid on adds major grid lines to the current axes. 17.FFT Discrete Fourier transform. FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT operation is applied to each column. For N-D arrays, the FFT operation operates on the first non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it has more. 18. ABS Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex modulus (magnitude) of the elements of X. 19. ANGLE Phase angle. ANGLE(H) returns the phase angles, in radians, of a matrix with complex elements. 20.INTERP Resample data at a higher rate using lowpass interpolation. Department of ECE

SVS Institute of Technology

Y = INTERP(X,L) resamples the sequence in vector X at L times the original sample rate. The resulting resampled vector Y is L times longer, LENGTH(Y)= L*LENGTH(X). 21. DECIMATE Resample data at a lower rate after lowpass filtering.

Y = DECIMATE(X,M) resamples the sequence in vector X at 1/M times the original sample rate. The resulting resampled vector Y is M times shorter, i.e., LENGTH(Y) = CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th order Chebyshev Type I lowpass filter with cutoff frequency .8*(Fs/2)/R, before resampling.

Department of ECE

SVS Institute of Technology

Experiment No.1 Generation of sinusoidal waveform / signal based on recursive difference equations

Aim: Generation of Sinusoidal waveform / signal based on recursive difference equations EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software THEORY: For the given difference equation, a sinusoidal signal/sequence is applied as the input. Using the given initial conditions, the sinusoidal response of the given discrete system is to be computed. 1. The difference equation is y(n)=x(n)+y(n-1), which is a first order system, with the initial condition y(-1)=4. PROGRAM:

I=input ('Enter the value of initial condition y(-1)') n=0:0.001:1 f=input ('Enter the frequency') x=sin (2*pi*f*n) y=zeros (1, length(n)) for i=1:length(n) y(i)=x(i)+I I=y(i) end subplot(2,1,1) plot(n,x) title('Input signal x(n) applied') xlabel('Time') ylabel('Amplitude') subplot(2,1,2) plot(n,y) title('Sinusoidal Response of the given first order system') Department of ECE

SVS Institute of Technology

xlabel('Time') ylabel('Amplitude') Enter the value of initial condition y(-1) I=4 Enter the frequency f =10

Expected Waveform: Input signal x(n) applied 1 0.5 Amplitude 0 -0.5 -1

0

0.1

0

0.1

0.2

0.3

0.4

0.5 0.6 0.7 0.8 0.9 Time Sinusoidal Response y(n) of the given first order system

0.2

0.3

0.4

1

40 Amplitude 30 20 10 0

Result:

Department of ECE

0.5 Time

0.6

0.7

0.8

0.9

1

SVS Institute of Technology

Experiment No: 2 Histogram of White Gaussian Noise and Uniformly Distributed Noise.

Aim: Histogram of White Gaussian Noise and Uniformly Distributed Noise using MAT Lab. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MATLAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Program: clc; clear all; x1=randn(1,5000); x2=randn(1,5000); figure; plot(x1,x2,'.') title('scattered plot of Gaussian Distribution Random numbers'); x1=rand(1,5000); x2=rand(1,5000); figure; plot(x1,x2,'.') title('scattered plot of uniform Distribution Random numbers'); x3=rand(1,100000); figure; subplot(2,1,1); hist(x3) title('uniform Distribution '); y=randn(1,100000); Department of ECE

SVS Institute of Technology

subplot(2,1,2); hist(y) title('Gaussian Distribution'); ymu=mean(y); ymsq=sum(y.^2)/length(y); ysigma=std(y); yvar=var(y); yskew=skewness(y); ykurt=kurtosis(y);

Expected Graph:

Department of ECE

SVS Institute of Technology uniform Distribution 15000

10000

5000

0 0

0.1

0.2

0.3

4

4

0.4

0.5

0.6

0.7

0.8

0.9

1

2

3

4

5

Gaussian Distribution

x 10

3 2 1 0 -5

Result:.

Department of ECE

-4

-3

-2

-1

0

1

SVS Institute of Technology

Experiment No: 3 To find DFT / IDFT of given DT signal.

Aim: To compute the N-point DFT of a sequence using MAT Lab. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MATLAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Program: %N-point DFT of a sequence. clc; clear all; close all; x=input('Enter the sequence x[n]= '); N=input('Enter the value N point= '); L=length(x); x_n=[x,zeros(1,N-L)]; for i=1:N for j=1:N temp=-2*pi*(i-1)*(j-1)/N; DFT_mat(i,j)=exp(complex(0,temp)); end end X_k=DFT_mat*x_n'; disp('N point DFT is X[k] = '); Department of ECE

SVS Institute of Technology

disp(X_k); mag=abs(X_k); phase=angle(X_k)*180/pi; subplot(2,1,1); stem(mag); grid on; xlabel('frequency index k'); ylabel('Magnitude of X[k]'); axis([0 N+1 -2 max(mag)+2]); subplot(2,1,2); stem(phase); grid on; xlabel('frequency index k'); ylabel('Phase of X[k]'); axis ([0 N+1 -180 180]);

Output: Enter the sequence x[n]= [ Enter the value N point= N point DFT is X[k] = Expected Graph:

Result:. Department of ECE

]

SVS Institute of Technology

Experiment No.4 To find frequency response of a given system given in (Transfer Function/ Differential equation form).

Aim: To find the frequency response of the following difference equation. y ( n) – 5 y(n–1) = x(n) + 4 x(n–1) EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MATLAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Program: clc; clear all; close all; b=[1,4]; %Numerator coefficients a=[1,-5]; %Denominator coefficients w=-2*pi:pi/256:2*pi; [h]=freqz (b, a, w); subplot(2, 1,1), plot(w,abs(h)); xlabel('Frequency \omega'); ylabel('Magnitude'); grid on; subplot(2, 1, 2); plot(w, angle(h)); xlabel('Frequency \omega'); Department of ECE

SVS Institute of Technology

ylabel('Phase - Radians'); grid on;

Expected Waveform:

Result:

Department of ECE

SVS Institute of Technology

Experiment No: 5 Implementation of FFT of given sequence.

Aim: To determine the N-point FFT of a given sequence. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MATLAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Program: clc; clear all; close all; x=input ('enter the sequence='); n=input ('enter the length='); xk=fft(x,n);

subplot(2,2,1); stem(x,'filled'); title('plot of input sequence'); subplot(2,2,2); stem(real(xk),'filled'); title('plot of real xk'); subplot(2,2,3); stem(abs(xk),'filled'); title('Magnitude spectrum');

Department of ECE

%N points for FFT

%computes FFT

disp (xk);

subplot(2,2,4);

%x[n] sequence

SVS Institute of Technology

stem(angle(xk),'filled'); title('Phase spectrum');

Expected Waveform: Enter the sequence= [1 2 1 0] Enter the length=5 4.0000 0.8090 - 2.4899i -0.3090 - 0.2245i -0.3090 + 0.2245i 0.8090 + 2.4899i

Result:

Department of ECE

SVS Institute of Technology

Experiment No: 6 Determination of Power Spectrum of a given signal(s).

Aim: To obtain power spectrum of given signal using MATLAB. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MAT LAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Program: %Power density spectrum of a sequence. clc; clear all; close all; x=input ('enter the length of the sequence='); y=input ('enter the sequence='); fs=input ('enter sampling frequency='); N=input ('enter the value of N='); q=input ('enter the window name1='); m=input ('enter the window name2='); s=input ('enter the window name3='); pxx1=psd(y, N, fs, q) plot (pxx1,'c'); hold on; grid on; pxx2=psd(y, N, fs, m) plot (pxx2,'k'); Department of ECE

SVS Institute of Technology

hold on; pxx3=psd(y, N, fs, s) plot (pxx3,'b'); hold on; xlabel ('-->Frequency'); ylabel ('-->Magnitude'); title ('POWER SPECTRAL DENSITY OF A SEQUENCE'); hold off;

Output: enter the length of the sequence=5 enter the sequence=[3 4 5 6 7] enter sampling frequency=200 enter the value of N=5 enter the window name1=triang (N) enter the window name2=Kaiser (N, 4.5) enter the window name3=rectwin (N) pxx1 = 106.5789 11.0127 0.3031

Result: Department of ECE

pxx2 = 77.3378 24.6721 0.2229

pxx3 =125.0000 3.6180 1.3820

SVS Institute of Technology

Experiment No: 7 Implementation of LP FIR & HP FIR filters for a given sequence.

Aim: To Design FIR LP Filter using Rectangular /Triangular/Kaiser Windowing Technique. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MATLAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Algorithm: 1) Enter the pass band ripple (rp) and stop band ripple (rs). 2) Enter the pass band frequency (fp) and stop band frequency (fs). 3) Get the sampling frequency (f), beta value. 4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f 5) Calculate the numerator and denominator 6) Use an If condition and ask the user to choose either Rectangular Window or Triangular Window or Kaiser Window. 7) Use rectwin, triang, Kaiser Commands 8) Calculate the magnitude of the frequency response in decibels (dBm=20*log10(abs( h)) 9) Plot the magnitude response [magnitude in neither dB Vs nor malized frequency (om/pi)] 10) Give relevant names to x and y axes and gives an appropriate ate title for the plot. 11) Plot all the responses in a single figure window. [Make use of subplot]

Department of ECE

SVS Institute of Technology

Program: %FIR Filter design window techniques. clc; clear all; close all; rp=input('enter pass band ripple ='); rs=input('enter the stop band ripple ='); fp=input('enter passband freq ='); fs=input('enter stopband freq ='); f=input('enter sampling freq ='); beta=input('enter beta value ='); 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; end c=input('enter your choice of window 1. rectangular 2. triangular 3.kaiser: \n'); if(c==1) y=rectwin(n1); disp('Rectangular window filter response'); end if(c==2) y=triang(n1); disp('Triangular window filter response') ; end if(c==3) Department of ECE

SVS Institute of Technology

y=kaiser( n1,beta); disp('Kaiser window filter response'); end %LPF b=fir1( n,wp,y) ; [h,o]=freqz(b,1,256); m=20*log10 (abs (h)); plot(o/pi, m); title('LPF Rectangular window filter response'); ylabel('Gain in dB-->'); xlabel(' Normalized frequency-->');

Expected Output: Rectangular window filter response enter pass band ripple =0.02 enter the stop band ripple =0.04 enter passband freq =1000 enter stopband freq =2000 enter sampling freq =5000 enter beta value = enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1 Rectangular window filter response

Result: Department of ECE

SVS Institute of Technology

Experiment No: 8 Implementation of HP FIR filters for a given sequence.

Aim: To Design FIR HP Filter using Rectangular /Triangular/Kaiser Windowing Technique. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure:1) Open MAT LAB 2) Open new M-file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Algorithm: 1) Enter the pass band ripple (rp) and stop band ripple (rs). 2) Enter the pass band frequency (fp) and stop band frequency (fs). 3) Get the sampling frequency (f), beta value. 4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f 5) Calculate the numerator and denominator 6) Use an If condition and ask the user to choose either Rectangular Window or Triangular Window or Kaiser Window. 7) Use rectwin, triang, Kaiser Commands 8) Calculate the magnitude of the frequency response in decibels (dBm=20*log10(abs( h)) 9) Plot the magnitude response [magnitude in neither dB Vs nor malized frequency (om/pi)] 10) Give relevant names to x and y axes and gives an appropriate ate title for the plot. 11) Plot all the responses in a single figure window. [Make use of subplot] Department of ECE

SVS Institute of Technology

Program: %FIR HP Filter design window techniques. clc; 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 ='); beta=input('enter beta value ='); 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; end c=input('enter your choice of window 1. rectangular 2. triangular 3.kaiser: \n ') ; if(c==1) y=rectwin( n1); disp('Rectangular window filter response'); end if(c==2) y=triang(n1); disp('Triangular window filter response') ; end if(c==3) y=kaiser( n1,beta);

Department of ECE

SVS Institute of Technology

disp('kaiser window filter response'); end %HPF b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs( h)); plot(o/pi,m); title('HPF Rectangular window filter response'); ylabel('Gain in dB-->'); xlabel('Normalized frequency-->');

Expected Output: Rectangular window filter response enter passband ripple =0.04 enter the stopband ripple =0.05 enter passband freq =2000 enter stopband freq =2500 enter sampling freq =6000 enter beta value = enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1 Rectangular window filter response

Result:

Department of ECE

SVS Institute of Technology

Experiment No: 9 Implementation of LP IIR filter for a given sequence

Aim: -To Design and generate IIR Butterworth Analog LP Filter using MATLAB EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure: 1)Open MATLAB 2)Open new M- file 3)Type the program 4)Save in current directory 5)Compile and Run the program 6)For the output see command window \ Figure window

Algorithm:1) Enter the pass band ripple (rp) and stop band ripple (rs). 2) Enter the pass band frequency (fp) and stop band frequency ( fs). 3) Get the sampling frequency ( f). 4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f 5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following function] [n,wn]=buttord (w1,w2,rp,rs, s ) 6) Des ign an nth order analog lowpass Butter worth filter using the following statement. [b,a]=butter (n,wn, s ) 7) F ind the complex frequency response of the filter by using , freqs( ) function [h,om]=freqs(b,a,w)

where, w = 0:.01:pi

This function retur ns complex frequency response vector „ h and frequency vector „ om in radians /samples of the filter. 8) Calculate the magnitude of the fr equency response in decibels (dB m=20*log10(abs( h)) 9) Plot the magnitude response [magnitude in dB Vs nor malized frequency (om/pi)] Department of ECE

SVS Institute of Technology

10) Calculate the phase response using an = angle( h) 11) Plot the phase response [phase in radians Vs nor malized frequency (om/pi) ] 12) Give relevant names to x and y axes and give an appropr iate title for the plot. 13)Plot all the responses in a single figure window.[Make use of subplot]

Program: % IIR LP filters. clc; clear all; close all; warning off; disp('enter the IIR LP 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'); % Find the order n and cut-off frequency disp ('Frequency response of IIR HPF is :'); [b,a]=butter (n, wn,'low','s'); % Find the filter co-efficients of LPF w=0:.01:pi; [h,om]=freqs(b,a,w); % Plot the frequency response m=20*log10(abs( h)); subplot(2,1,1); plot(om/pi,m); title('magnitude response of IIR Low Pass filter is:'); xlabel('(a)Nor malized freq. -->'); ylabel('Gain in dB-->'); an=angle(h) ; Department of ECE

SVS Institute of Technology

subplot(2,1,2); plot(om/pi,an); title('phase respons e of IIR Low Pass filter is:'); xlabel('(b)Normalized freq. -->'); ylabel('Phase in radians -->');

Expected Output: enter the IIR LP filter design specifications enter the passband ripple =0.5 enter the stopband ripple =60 enter the passband freq =400 enter the stopband freq =600 enter the sampling freq =1000 Frequency response of IIR LPF is :

Result:

Department of ECE

SVS Institute of Technology

%Design of IIR Chebyshew type I Low pass filter

Program: %Design of IIR Chebyshew type I Low pass filter . clc; clear all; close all; wp=input('Enter the passband edge Normalised frequency = '); ws=input('Enter the stopband edge Normalised frequency = '); Rp=input('Enter the passband attenuation level (dB) = '); Rs=input('Enter the stopband attenuation level (dB) = '); [N,wn]=cheb1ord(wp,ws,Rp,Rs); [b,a]=cheby1(N,Rp,wn);

%replace by following for other filters

%[b,a]=cheby1(N,Rp,wn,'high'); Highpass filter [h,w]=freqz(b,a); mag=20*log10(abs(h)); phase=180*angle(h)/pi; figure(1); plot(w,abs(h)); title('Chebyshev Lowpass Filter'); xlabel('Normalised frequency'); ylabel('Magnitude'); grid; figure(2); subplot(2,1,1); plot(w,mag); title('Magnitude response'); xlabel('Normalised frequency'); ylabel('Magnitude in dB'); grid; subplot(2,1,2); plot(w,phase); title('Phase response'); Department of ECE

SVS Institute of Technology

xlabel('Normalised frequency'); ylabel('Phase in degrees'); grid; Output: Enter the pass band edge Normalized frequency = 0.2*pi Enter the stop band edge Normalized frequency = 0.1*pi Enter the pass band attenuation level (dB) = 1 Enter the stop band attenuation level (dB) = 15

Figure: 1

Figure: 2

Result:

Department of ECE

SVS Institute of Technology

Experiment No: 10 Implementation of HP IIR filter for a given sequence

Aim: To Design and generate IIR Butterworth Analog HP Filter using MATLAB EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure: 1)Open MATLAB 2)Open new M- file 3)Type the program 4)Save in cur rent directory 5)Compile and Run the program 6)For the output see command window \ Figure window

Algorithm: 1) Enter the pass band ripple (rp) and stop band ripple (rs). 2) Enter the pass band frequency ( fp) and stop band frequency ( fs). 3) Get the sampling frequency ( f). 4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f 5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following function] [n,wn]=buttord (w1, w2, rp,rs, s ) 6) Des ign an nth order analog lowpass Butter worth filter using the following statement. [b,a]=butter (n,wn, s ) 7) F ind the complex frequency response of the filter by using „freqs( ) function [h,om]=freqs(b,a,w)

where, w = 0:.01:pi This function retur ns complex frequency

response vector „ h and frequency vector „ om in radians /samples of the filter. 8) Calculate the magnitude of the fr equency response in decibels (dB m=20*log10(abs( h))

Department of ECE

SVS Institute of Technology

9) Plot the magnitude response [magnitude in dB Vs nor malized frequency (om/pi)] 10) Calculate the phase response using an = angle ( h) 11) Plot the phase response [phase in radians Vs nor malized frequency (om/i) ] 12)Give relevant names to x and y axes and give an appropriate ate title for the plot. 13)Plot all the responses in a single figure window.[Make use of subplot] Program: % IIR HP butter worth filter. clc; clear all; close all; warning off; disp('enter the IIR HP 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'); % Find the order n and cut-off frequency disp('Frequency response of IIR HYPF is :'); [b,a]=butter(n,wn,'HIGH','s'); % Find the filter co-efficients of LPF w=0:.01:pi; [h,om]=freqs(b,a,w); % Plot the frequency response m=20*log10(abs( h)); subplot(2,1,1); plot(om/pi,m); title('magnitude response of IIR HIGH Pass filter is:'); xlabel('(a)Normalized freq. -->'); ylabel('Gain in dB-->'); an=angle(h) ; Department of ECE

SVS Institute of Technology

subplot(2,1,2); plot(om/pi,an); title('phase respons e of IIR HIGH Pass filter is:'); xlabel('(b)Normalized freq. -->'); ylabel('Phase in radians -->');

Output: enter the IIR HP filter design specifications enter the passband ripple =0.5 enter the stopband ripple =60 enter the passband freq =400 enter the stopband freq =600 enter the sampling freq =1000 Frequency response of IIR HPF is:

Department of ECE

SVS Institute of Technology

Result:

%IIR Chebyshew type I high pass filter Program: % IIR Chebyshew type I high pass filter clear all; close all; clc; wp=input('Enter the passband edge Normalised frequency = '); ws=input('Enter the stopband edge Normalised frequency = '); Rp=input('Enter the passband attenuation level (dB) = '); Rs=input('Enter the stopband attenuation level (dB) = '); [N,wn]=cheb1ord(wp,ws,Rp,Rs); [b,a]=cheby1(N,Rp,wn,'high'); %High pass filter [h,w]=freqs(b,a); mag=20*log10(abs(h)); phase=180*angle(h)/pi; figure(1); plot(w,abs(h)); title('Chebyshev Lowpass Filter'); xlabel('Normalised frequency'); ylabel('Magnitude'); grid; figure(2); subplot(2,1,1); plot(w,mag); title('Magnitude response'); xlabel('Normalised frequency'); ylabel('Magnitude in dB'); grid; subplot(2,1,2); Department of ECE

SVS Institute of Technology

plot(w,phase); title('Phase response'); xlabel('Normalised frequency'); ylabel('Phase in degrees'); grid;

Expected Output: Enter the passband edge Normalised frequency = 0.2*pi Enter the stopband edge Normalised frequency = 0.1*pi Enter the passband attenuation level (dB) = 1 Enter the stopband attenuation level (dB) = 15 >> 2

Figure: 1

Figure: 2

Result: .

Department of ECE

SVS Institute of Technology

Experiment No: 11 Generation of Narrow Band Signal through Filtering

Aim: To generate a sinusoidal signal through filtering. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software PROGRAM: clc; clear all; close all; echo on; t0=.2; % signal duration ts=0.001; % sampling interval fc=250; % carrier frequency fs=1/ts; % sampling frequency t=[-t0/2:ts:t0/2]; % time vector kf=100; % deviation constant m=cos(2*pi*10*t); % the message signal int_m(1)=0; for i=1:length(t)-1 % integral of m int_m(i+1)=int_m(i)+m(i)*ts; echo off ; end echo on ; u=cos(2*pi*fc*t+2*pi*kf*int_m); % modulated signal %now lets filter the signal [z,p] = butter(1,2*50/fs,'low'); Department of ECE

SVS Institute of Technology

filter_out = filter(50,[1 50],u); %this damn filter doesn't work! subplot(2,1,1); plot(t,u); hold on; plot(t,m,'r'); subplot(2,1,2); plot(t,filter_out); hold on; plot(t,m,'r');

Expected Output:

Result: .

Department of ECE

SVS Institute of Technology

Experiment No: 12 Generation of DTMF Signals Aim: To generate DTMF signals EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software THEORY: Introduction Analog DTMF telephone signaling is based on encoding standard telephone. Keypad digits and symbols in two audible sinusoidal signals of frequencies FL and FH. Thus the scheme gets its name as dual tone multi frequency (DTMF). 12 13 14 16 Hz 09 36 77 33 697

1

2

3

A

770

4

5

6

B

852

7

8

9

C

941

*

0

#

D

Each digit or symbol represented in figure 1 has 2 distinct high and low frequency components. Thus each high-low frequency pair uniquely identifies the corresponding telephone keypad digit or symbol. Each key pressed can be represented as a discrete time signal of form dt[n] = sin[ωLn] + sin[ωLn] , 0 ≤ n ≤ N-1 (1) Where N is defined as number of samples taken. Typically in the sampling frequency used is 8khz. Thus if the two individual frequency components of the signal can be identified then the number dialed can be decoded. -- In this report I have used (dual tone and digit/symbols) interchangeably but both mean the same. Dual tone means the encoded samples of the corresponding DTMF digits/symbols. The DTMF encoder is implemented in MATLAB function dtmfe.m. The implementation is based on a digital oscillator, that will generate sinusoidal tones at frequencies Fo in response to an input signal x[n] = δ[n]. Note :Implementation of DTMF Encoder x[n]

H[n]

y[n] {y[n] = x[n]*H[n]

Consider a causal filter with y(n) - 2*cos(2*pi * f *Ts)y(n-1) + y(n-2) =0*x(n) sin(f)x(n-1) + 0*x(n-2). The impulse response of this system tells us that this indeed is a digital oscillator. The H[n] is plotted and is sinusoidal and hence any input to this system will oscillate . Department of ECE

SVS Institute of Technology

PROGRAM: %Generation of DTMF signals Fs = 8000;

% Sampling frequency

Ts = 1/Fs; Numof_samples =input('enter the no of samples'); dialnumber=input('enter the dial number'); T = Ts*(0:Numof_samples-1)'; switch dial_num case 0 F1 = 941; F2 = 1336; case 1 F1 = 697; F2 = 1209; case 2 F1 = 697; F2 = 1336; case 3 F1 = 697; F2 = 1477; case 'A' F1 = 697; F2 = 1633; case 4 F1 = 770; F2 = 1209; Department of ECE

SVS Institute of Technology

case 5 F1 = 770; F2 = 1336; case 6 F1 = 770; F2 = 1477; case 'B' F1 = 770; F2 = 1633; case 7 F1 = 852; F2 = 1209; case 8 F1 = 852; F2 = 1336; case 9 F1 = 852; F2 = 1477; case 'C' F1 = 852; F2 = 1633; case '*' F1 = 941; F2 = 1209; case '#' F1 = 941; F2 = 1477; Department of ECE

SVS Institute of Technology

otherwise F1 = 941; F2 = 1633; end; firstsine = cos(2*pi*F1*T); secondsine = cos(2*pi*F2*T);

% first sinusoidal signal % second sinusoidal signal

d = firstsine + secondsine; dtmfoutput = d ; figure(1); title('THE DTMF OUTPUT'); plot(dtmfoutput);

Expected Output:: enter the no of samples 128 enter the dial number 3

RESULT: Department of ECE

SVS Institute of Technology

Experiment No: 13 Implementation of Decimation Process

Aim: To perform Decimation process using Mat lab. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure: 1) Open MAT LAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Theory: Sampling rate conversion (SRC) is a process of converting a discrete-time signal at a given rate to a different rate. This technique is encountered in many application areas such as:  Digital Audio  Communications systems  Speech Processing  Antenna Systems  Radar Systems etc

Department of ECE

SVS Institute of Technology

Sampling rates may be changed upward or downward. Increasing the sampling rate is called Interpolation and decreasing the sampling rate is called decimation. Reducing the sampling rate by a factor of M is achieved by discarding ever y M- 1 samples, or, equivalently keeping every M th sample. Increasing the sampling rate by a factor of L ( interpolation by factor L) is achieved by inserting L- 1 zeros into the output stream after ever y sample from the input stream of samples. This system can perform SRC for the following cases: • Decimation by a factor of M • Interpolation by a factor of L • SRC by a rational factor of L/M. Decimator: To reduce the sampling rate by an integer factor M, assume a new sampling period.The resampled signal is The system for performing this operation, called down- sampler, is shown below: Down-sampling generally results in aliasing. Therefore, in order to prevent aliasing, x (n) Should be filtered prior to down-sampling with a low-pass filter that has a cutoff frequency The cascade of a low-pass filter with a down- sampler illustrated below and is called Decimator.

Program: % Illustration of Decimation Process. clc; close all; clear all; M=input('enter Down-sampling factor : '); N=input('enter number of samples :') ; n=0:N- 1; x=sin(2*pi*0.043*n)+ sin(2*pi*0.031*n); y=decimate(x,M,'fir'); Department of ECE

SVS Institute of Technology

subplot(2,1,1); stem(n,x(1:N) ); title('Input Sequence') ; xlabel('Time index n'); ylabel('Amplitude'); subplot(2,1,2); m=0:(N/M)-1; stem(m,y(1:N /M)); title('Output Sequence'); xlabel('Time index n'); ylabel('Amplitude') ;

Expected Output: Enter Down-sampling factor: 4 Enter number of samples: 100

Result: Note: Observe the Output Sequence for Different values of M. Department of ECE

SVS Institute of Technology

Experiment No: 14 Implementation of Interpolation Process.

Aim: To perform interpolation process using Mat lab. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure: 1) Open MAT LAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Theory: To increase the sampling rate by an integer factor L. I f xa(t) is sampled with a sampling frequency fs = 1/Ts, then To increase the sampling rate by an integer factor L, it is necessary to extract the samples from x(n). The samples of xi( n) for values of n that are integer multiples of L are easily extracted from x(n) as follows: The system per forming the operation is called up- sampler and is shown below: After up-sampling, it is necessary to remove the frequency scaled images in xi(n), except those that are at integer multiples of 2p. This is accomplis hed by filter ing xi(n) with a low- pass filter that has a cutoff frequency of p /L and a gain of L. In the time domain, the low -pass filter inter - polates between the samples at integer multiples of L as shown below and is called interpolator.

Program: % Illustration of Interpolation Process clc; close all; clear all; L=input('Up-sampling factor = ') ; Department of ECE

SVS Institute of Technology

N=input('enter number of samples :') ; n=0:N- 1; x=sin(2*pi*0.043*n)+sin(2*pi*0.031*n); y=interp(x,L); subplot(2,1,1); stem(n,x(1:N) ); title('Input Sequence') ; xlabel('Time index n'); ylabel('Amplitude'); subplot(2,1,2); m=0:(N*L)-1; stem(m,y(1:N*L)); title('Output Sequence'); xlabel('Time index n'); ylabel('Amplitude');

Expected Output: Up-sampling factor = 5 Enter number of samples: 50

Result: Department of ECE

SVS Institute of Technology

Experiment No: 15 Implementation of I/D sampling rate converters.

Aim: To study sampling rate conversion by a rational for m using M ATLAB EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Procedure: 1) Open MAT LAB 2) Open new M- file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window \ Figure window

Theory: SRC by rational factor: SRC by L/M requires performing an interpolation to a sampling rate which is divisible by both L and M. The final output is then achieved by decimating by a factor of M. The need for a non-Integer sampling rate conversion appears when the two systems operating at different sampling rates have to be connected, or when there is a need to convert the sampling rate of the recorded data into another sampling rate for further processing or reproduction. Such applications are very common in telecommunications, digital audio, multimedia and others. An example is transferring data from compact disc (CD) system at a rate of 44.1 kHz to a digital audio tape at 48 kHz. This can be achieved by increasing the data rate of the CD by a factor of 48/44.1, a non- integer.

Department of ECE

SVS Institute of Technology

Illustration for sampling rate converter is: I f M> L, the resulting operation is a decimation process by a non- integer, and when M
Program: clc; close all; clear all; L=input('Enter Up-sampling factor :'); M=input('Enter Down-sampling factor :'); N=input('Enter number of samples :'); n=0:N- 1; x=sin(2*pi*0.43*n)+sin(2*pi*0.31*n); y=resample(x,L,M) ; subplot(2,1,1); stem(n,x(1:N) ); axis([0 29 -2.2 2.2]); title('Input Sequence') ; xlabel('Time index n'); ylabel('Amplitude') ; subplot(2,1,2); m=0:(N*L/M)-1; stem(m,y(1:N*L/M)); axis([0 (N*L/M)-1 -2.2 2.2]); title('Output Sequence'); xlabel('Time index n'); Department of ECE

SVS Institute of Technology

ylabel('Amplitude') ;

Expected Output: Enter Up-sampling factor: 6 Enter Down-sampling factor: 3 Enter number of samples: 40

Result:

Department of ECE

SVS Institute of Technology

Experiment No: 16 IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER SYSTEM Aim: To determine the response of first order and second order systems. EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software PROGRAM: %impulse response of a first order system clear all; b=[1]; a=[1,-.8]; w=0:0.1:2*pi; [h]=freqz(b,a,w); subplot(2,1,1); plot(w/pi,abs(h)); xlabel('normalised frequency\omega/\pi'), ylabel('magnitude'); title('impulse response of first order system h(n)=(0.8)^n u(n)'); subplot(2,1,2); plot(w/pi,angle(h)); xlabel('normalised frequency'), ylabel('phase angle in radians');

Expected Output:

Department of ECE

SVS Institute of Technology

RESULT:

Department of ECE

Related Documents

Dsp Lab Manual
April 2020 7
Dsp Lab Manual (1)
November 2019 12
Dsp Lab Manual.pdf
May 2020 5
Dsp
June 2020 21
Dsp
June 2020 14