Вы находитесь на странице: 1из 59

DSP LAB MANUAL

CONTENTS
1. INTRODUCTION TO MATLAB. 2. GENERATION OF DIFFERENT TYPES OF SIGNAL ( BOTH CONTINUOUS & DISCRETE). 3. LINEAR CONVOLUTION WITHOUT USING INBUILT FUNCTION CONV. 4. CIRCULAR CONVOLUTION. 5. (a) FINDING AUTO CORRELATION OF A SEQUENCE. (b) FINDING CROSS CORRELATION OF A SEQUENCE. (c) FINDING POWER SPECTRAL DENSITY OF A SIGNAL. 6. FINDING CONVOLUTION USING DFT & IDFT. 7. IMPLEMENTATION OF FFT ALGORITHM. :DECIMATION IN TIME :DECIMATION IN FREQUENCY 8. DESIGN OF FILTER (LOW PASS ,BAND PASS, HIGH PASS) USING HAMMING , HANNING, RECTANGULAR,KAISER WINDOWING TECHNIQUE. 9.DESIGN OF IIR FILTER ( BUTTER WORTH & CHEBYSHEV) 10. CONVOLUTION OF LONG DURATION SEQUENCES USING OVERLAP ADD METHOD & OVER LAP SAVE METHOD. 11. WORKING WITH A DSP PROCESSOR( FIXED POINTTM320VC5416/ FLOATING POINT SERIES) (I) IMPLEMENTATION OF LINEAR AND CIRCULAR CONVOLUTION. (II) FIR & IIR IMPLEMENTATION

INTRODUCTION TO MATLAB 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. This collection includes the following topics: Introduction: Describes the components of the MATLAB system.

Matrices and Arrays:How to use MATLAB to generate matrices and perform mathematical operations on matrices. Graphics: Programming: How to plot data, annotate graphs, and work with images. How to use MATLAB to create scripts and functions, how to and manipulate data structures.

Creating Graphical User Interfaces: Introduces GUIDE, the MATLAB graphical user interface development environment. Desktop Tools and Development Environment: Information about tools and the MATLAB desktop.

Introduction : What Is MATLAB? 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. Typical uses include Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar noninteractive language such as C or Fortran.

The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation. 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 features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others. The MATLAB System: The MATLAB system consists of five main parts: Development Environment. This is the set of tools and facilities that help you use MATLAB functions and files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop and Command Window, a command history, an editor and debugger, and browsers for viewing help, the workspace, files, and the search path. The MATLAB Mathematical Function Library. This is a vast collection of computational algorithms ranging from elementary functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms. The MATLAB Language. This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both "programming in the small" to rapidly create quick and dirty throw-away programs, and "programming in the large" to create large and complex application programs. Graphics. MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for twodimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications.

The MATLAB Application Program Interface (API). This is a library that allows you to write C and Fortran programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files. MATLAB Desktop: When you start MATLAB, the MATLAB desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following illustration shows the default desktop. You can customize the arrangement of tools and documents to suit your needs.

Matlab has 3 windows. 2. Command window: It is the main window where the program is to be executed. As it depends up on the only commands it is called command window. Here all the command can be typed in a single line by giving a comma in between the command. 3. Edit window: As the name indicates here editing can be done and is called script file if is written by the user. If it is defined by the program it self then it is called function file. 4. Graphics window: In this window the output of the programme will display in graphical form.

Applications & Features: 1. Aerospace Blockset* 2. Bioinformatics Toolbox* 3. CDMA Reference Blockset 4. Communications Blockset* 5. Communications Toolbox* 6. Control System Toolbox* 7. Curve Fitting Toolbox 8. Data Acquisition Toolbox* 9. Database Toolbox 10. Datafeed Toolbox* 11. Distributed Computing Toolbox* 12. Embedded Target for Infineon 13. C166 Microcontrollers Embedded Target for Motorola HC12 14. Embedded Target for Motorola MPC555* 15. Embedded Target for OSEK/VDX 16. Embedded Target for TI C2000TM DSP* 17. Embedded Target for TI C6000TM DSP* 18. Excel Link Filter Design HDL Coder* 19. Filter Design Toolbox* 20. Financial Derivatives Toolbox 21. Financial Time Series Toolbox 22. Financial Toolbox* 23. Fixed-Income Toolbox 24. Fixed-Point Toolbox* 25. Fuzzy Logic Toolbox 26. GARCH Toolbox* 27. Gauges Blockset* 28. Genetic Algorithm and Direct Search Toolbox 29. Image Acquisition Toolbox* 30. Image Processing Toolbox* 31. Instrument Control Toolbox* 32. Link for Code Composer StudioTM Development Tools* 33. Link for ModelSim* 34. Mapping Toolbox* 35. MATLAB Builder for COM (now part of MATLAB Builder for .NET) MATLAB Builder for Excel MATLAB 36. Builder for .NET (new product) 37. MATLAB Compiler* 38. MATLAB Distributed Computing Engine* 39. MATLAB Report Generator 40. MATLAB Web Server 41. Model-Based Calibration Toolbox* 42. Model Predictive Control Toolbox 43. Neural Network Toolbox*

44. OPC Toolbox* 45. Optimization Toolbox* 46. Partial Differential Equation Toolbox* (no release notes) 47. Real-Time Windows Target 48. Real-Time Workshop* 49. Real-Time Workshop Embedded Coder* 50. RF Blockset* 51. RF Toolbox* 52. Robust Control Toolbox* 53. Signal Processing Blockset* 54. Signal Processing Toolbox* 55. SimBiology (new product) 56. SimDriveline* 57. SimEvents* (new product) 58. SimMechanics* 59. SimPowerSystems* 60. Simulink Accelerator* 61. Simulink Control Design* 62. Simulink Fixed Point* 63. Simulink Parameter Estimation 64. Simulink Report Generator* 65. Simulink Response Optimization* 66. Simulink Verification and Validation* 67. Spline Toolbox* 68. Stateflow and Stateflow Coder* 69. Statistics Toolbox* 70. Symbolic Math Toolbox 71. System Identification Toolbox* 72. Video and Image Processing Blockset* 73. Virtual Reality Toolbox* 74. Wavelet Toolbox 75. xPC Target* 76. xPCTargetBox

Matrices and Arrays

Matrices and Magic Squares: Enter matrices, perform matrix operations, and access matrix elements. Expressions: Work with variables, numbers, operators, functions, and expressions. Working with Matrices: Generate matrices, load matrices, create matrices from M-files and concatenation, and delete matrix rows and columns. More About Matrices and Arrays: Use matrices for linear algebra, work with arrays, multivariate data, scalar expansion, and logical subscripting, and use the find function. Controlling Command Window Input and Output :Change output format, suppress output, enter long lines, and edit at the command line

Entering Matrices

The best way for you to get started with MATLAB is to learn how to handle matrices. Start MATLAB and follow along with each example. You can enter matrices into MATLAB in several different ways: Enter an explicit list of elements. Load matrices from external data files. Generate matrices using built-in functions. Create matrices with your own functions in M-files. Start by entering Drer's matrix as a list of its elements. You only have to follow a few basic conventions: Separate the elements of a row with blanks or commas. Use a semicolon, ; , to indicate the end of each row. Surround the entire list of elements with square brackets, [ ]. To enter Drer's matrix, simply type in the Command Window A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

MATLAB displays the matrix you just entered: A= 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

Subscripts

The element in row i and column j of A is denoted by A(i,j). For example, A(4,2) is the number in the fourth row and second column. For our magic square, A(4,2) is 15. So to compute the sum of the elements in the fourth column of A, type A(1,4) + A(2,4) + A(3,4) + A(4,4)

This produces ans = 34

but is not the most elegant way of summing a single column. It is also possible to refer to the elements of a matrix with a single subscript, A(k). This is the usual way of referencing row and column vectors. But it can also apply to a fully twodimensional matrix, in which case the array is regarded as one long column vector formed from the columns of the original matrix. So, for our magic square, A(8) is another way of referring to the value 15 stored in A(4,2). If you try to use the value of an element outside of the matrix, it is an error: t = A(4,5) Index exceeds matrix dimensions.

On the other hand, if you store a value in an element outside of the matrix, the size increases to accommodate the newcomer: X = A; X(4,5) = 17 X= 16 3 5 10 9 6 4 15

2 13 11 8 7 12 14 1

0 0 0 17

The Colon Operator

The colon, :, is one of the most important MATLAB operators. It occurs in several different forms. The expression 1:10 is a row vector containing the integers from 1 to 10: 1 2 3 4 5 6 7 8 9 10 To obtain nonunit spacing, specify an increment. For example, 100:-7:50 is 100 93 86 79 72 65 58 51 and 0:pi/4:pi is 0 0.7854 1.5708 2.3562 3.1416 Subscript expressions involving colons refer to portions of a matrix: A(1:k,j) is the first k elements of the jth column of A. So sum(A(1:4,4)) computes the sum of the fourth column. But there is a better way. The colon by itself refers to all the elements in a row or column of a matrix and the keyword end refers to the last row or column. So sum(A(:,end)) computes the sum of the elements in the last column of A: ans = 34 Why is the magic sum for a 4-by-4 square equal to 34? If the integers from 1 to 16 are sorted into four groups with equal sums, that sum must be sum(1:16)/4 which, of course, is ans = 34

Variables

MATLAB does not require any type declarations or dimension statements. When MATLAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. If the variable already exists, MATLAB changes its contents and, if necessary, allocates new storage. For example, num_students = 25 creates a 1-by-1 matrix named num_students and stores the value 25 in its single element. To view the matrix assigned to any variable, simply enter the variable name. Variable names consist of a letter, followed by any number of letters, digits, or underscores. MATLAB is case sensitive; it distinguishes between uppercase and lowercase letters. A and a are not the same variable. Although variable names can be of any length, MATLAB uses only the first N characters of the name, (where N is the number returned by the function namelengthmax), and ignores the rest. Hence, it is important to make each variable name unique in the first N characters to enable MATLAB to distinguish variables. N = namelengthmax N= 63 The genvarname function can be useful in creating variable names that are both valid and unique. Numbers MATLAB uses conventional decimal notation, with an optional decimal point and leading plus or minus sign, for numbers. Scientific notation uses the letter e to specify a power-of-ten scale factor. Imaginary numbers use either i or j as a suffix. Some examples of legal numbers are 3 -99 0.0001 9.6397238 1.60210e-20 6.02252e23 1i -3.14159j 3e5i

All numbers are stored internally using the long format specified by the IEEE floating-point standard. Floating-point numbers have a finite precision of roughly 16 significant decimal digits and a finite range of roughly 10-308 to 10+308.

Functions MATLAB provides a large number of standard elementary mathematical functions, including abs, sqrt, exp, and sin. Taking the square root or logarithm of a negative number is not an error; the appropriate complex result is produced automatically. MATLAB also provides many more advanced mathematical functions, including Bessel and gamma functions. Most of these functions accept complex arguments. For a list of the elementary mathematical functions, type help elfun For a list of more advanced mathematical and matrix functions, type help specfun help elmat Some of the functions, like sqrt and sin, are built in. Built-in functions are part of the MATLAB core so they are very efficient, but the computational details are not readily accessible. Other functions, like gamma and sinh, are implemented in M-files. There are some differences between built-in functions and other functions. For example, for built-in functions, you cannot see the code. For other functions, you can see the code and even modify it if you want.

Several special functions provide values of useful constants.

Infinity is generated by dividing a nonzero value by zero, or by evaluating well defined mathematical expressions that overflow, i.e., exceed realmax. Not-a-number is generated by trying to evaluate expressions like 0/0 or Inf-Inf that do not have well defined mathematical values. The function names are not reserved. It is possible to overwrite any of them with a new variable, such as eps = 1.e-6 and then use that value in subsequent calculations. The original function can be restored with clear eps Examples of Expressions You have already seen several examples of MATLAB expressions. Here are a few more examples, and the resulting values: rho = (1+sqrt(5))/2 rho = 1.6180 a = abs(3+4i) a= 5 z = sqrt(besselk(4/3,rho-i)) z = 0.3730+ 0.3214i huge = exp(log(realmax)) huge = 1.7977e+308 toobig = pi*huge toobig = Inf

EXPERIMENT No: 01
AIM OF THE EXPERIMENT: Generation of Different types of signal (Both Continuous and Discrete). APPARATUS REQUIRED : 1. Computer System 2. Matlab Software

THEORY:

PROCEDURE: 1. Click on the Matlab icon on the desktop. 2. In the command window, click on file menu New M file. 3. In edit window, Type the program as follows below. 4. Then press F5 to save and run the current file. 5. Click on the command window for any error. 6. Now the out can be viewed in the figure window. PROGRAMME: 1 (A)Unit Step Sequence 1. 2. 3. 4. 5. N=21; n=0:1:N-1; x=ones(1,N); plot(x) % for continuous signal stem(x) % for Discrete signal

(B) Unit ramp Sequence 1. N=21; 2.n=0:1:N-1; 3.x=0:N-1 4. plot(x) % for continuous signal 5.stem(x) % for Discrete signal

(C )Sinusoidal Signal 1. 2. 3. 4. 5. N=21; n=0:1:N-1; x=sin(0.1*pi*n); plot(x) % for continuous signal stem(x) % for Discrete signal

(D) Addition of Two signals 1. 2. 3. 4. 5. N=21; n=0:1:N-1; x= sin(0.1*pi*n) + cos(0.1*pi*n); plot(x) % for continuous signal stem(x) % for Discrete signal

(E) Exponential Signal 1. 2. 3. 4. 5. N=21; n=0:1:N-1; x=exp(n); plot(x) stem(x)

% for Continuous signal % for Discrete signal

Conclusion: From the above experiment we have studied how different types of signal is generated by the help of mat lab and the output graph is successfully plotted.

EXPERIMENT No: 02
AIM OF THE EXPERIMENT: Linear Convolution of sequences( Without the help of Inbuilt function CONV available in Matlab) APPARATUS REQUIRED : 1. Computer System 2. Matlab Software CONVOLUTION

THEORY:

Convolution is an important technique used in digital signal processing. It is a formal mathematical operation, like addition, multiplication used to combine two signals to form a third signal. Convolution relates the input signal, output signal and the impulse response. The impulse response will be identity, delayed and attenuated or amplified version of the input impulse signal.

Basic concept of the DSP is the input signal decomposed into simple additive components, each of these components passed through a linear system and the resulting output components are added. When impulse decomposition is used, the procedure can be described by a mathematical operation called convolution. BASIC DIAGRAM: Convolution is represented as shown in the figure below. x[n]-------------- LINEAR SYSTEM h[n] ------------------ y[n]

Linear systems relates input, impulse and output signal. An input signal, x[n] enters a linear system and reacts with an impulse signal h[n] resulting an output y[n]. Convolution can also be represented by the following equation

x[n] [n] = y[n]


N-1

It can also be defined as y[n] = x[k] h[n-k]

K=0

PROCEDURE: 1. Click on the matlab icon on the desktop. 2. In the command window, click on file menu New M file. 3. In edit window, Type the program as follows below. 4. Then press F5 to save and run the current file. 5. Click on the command window for any error. 6. Now the out can be viewed in the figure window. PROGRAMME: 1. x= input(enter the 1st sequence); % x=[1 2 3 4] 2. h=input(enter the 2nd sequence); % h=[2 3 4 5] 3. n1=length(x) 4. n2=length(h) 5. n=n1+n2-1 6. H=zeros(n,n) 7. x1= zeros(1,n) 8. x1(1,1:n1)=x 9. x1=x1 10. h1=h 11. H(1:n2,1)=h1 12. For c=2:1:n 13. For r= 2:1:n 14. H(r,c)= H(r-1,c-1) 15. End 16. End 17. Y=H*x1 18. Y=Y 19. Stem(Y)

CONCLUSION: From the above experiment it is clear that to find out the response of a signal when a impulse is present.

EXPERIMENT No: 03
AIM OF THE EXPERIMENT: Circular Convolution of sequences APPARATUS REQUIRED : 1. Computer System 2. Matlab Software CIRCULAR CONVOLUTION

THEORY:

In circular convolution it is necessary that the two sequences be of same length. It is similar to the linear convolution except the scaling and shifting are performed in a circular fashion equation for the circular convolution.
N-1

X3(m) = x1(n) x2((m-n))N


n=0

m=0,1,2,3,N-1

PROCEDURE: 1. Click on the matlab icon on the desktop. 2. In the command window, click on file menu New M file. 3. In edit window, Type the program as follows below. 4. Then press F5 to save and run the current file. 5. Click on the command window for any error. 6. Now the out can be viewed in the figure window. PROGRAMME : 1. x = input( Enter the 1st sequence); 2. h= input(Enter the 2nd sequence); 3. n1= length(x) 4. n2= length(h) 5. n= max(n1,n2) 6. y=[] 7. for k=1:n 8. y= [ y h] 9. h= circshift(h, [1 1]) 10. end 11. out= y* x 12. cout=out 13. stem(cout)

CONCLUSION: From the above experiment, it is quit clear that the result obtained from the linear convolution and circular convolution is different and the circular convolution is not only used for the aperiodic signal as well as periodic signal. And the output graph also plotted successfully.

EXPERIMENT No: 04
AIM OF THE EXPERIMENT: i) Find Auto correlation of a sequence. ii) Find Cross correlation of two sequences iii) Finding Power spectral density of a sequence. APPARATUS REQUIRED : 1. Computer System 2. Matlab Software

THEORY:

AUTO CORRELATION & CROSS CORRELATION

Correlation is a mathematical operation that is very similar to convolution . Just as convolution, correlation uses two signals to produce a third signal. This third signal is called the Cross Correlation. If a signal is correlated with itself, the resulting signal is called auto correlation. EQUATION FOR CORRELATION: Consider two data sequences, x[n],y[n] taken from the two corresponding waveforms might be compared. If the two waveform varied similarly point to point, then the measure of correlation is the sum of the products of the corresponding pairs of points.
N-1

rxy = x[n] y[n]


n=0

PROCEDURE: 1. Click on the matlab icon on the desktop. 2. In the command window, click on file menu New M file. 3. In edit window, Type the program as follows below. 4. Then press F5 to save and run the current file. 5. Click on the command window for any error. 6. Now the out can be viewed in the figure window. PROGRAMME : Auto & Cross Correlation 1. 2. 3. 4. 5. 6. 7. 8. x = input( Enter the 1st sequence); h = input(Enter the 2nd sequence); y1 = xcorr(x,x) y2 = xcorr(x,h) subplot(1,2,1); stem(y1) subplot(1,2,2); stem(y2)

Power Spectral Density THEORY: The power spectral density (PSD) is intended for continuous spectra. The integral of the PSD over a given frequency band computes the average power in the signal over that frequency band. In contrast to the mean-squared spectrum, the peaks in this spectra do not reflect the power at a given frequency. PROCEDURE: 1. Click on the matlab icon on the desktop. 2. In the command window, click on file menu New M file. 3. In edit window, Type the program as follows below. 4. Then press F5 to save and run the current file. 5. Click on the command window for any error. 6. Now the out can be viewed in the figure window. PROGRAMME : 1. Fs = 1000; t = 0:1/Fs:.296; 2. x = exp(i*2*pi*200*t)+randn(size(t)); 3. h = spectrum.periodogram; % Instantiate a periodogram object. 4. psd(h,x,'Fs',Fs); % Plots the two-sided PSD by default.

CONCLUSION: From the above experiment, the characteristic of cross & auto correlation is studied successfully and the power over a band of frequency is calculated . the output graph also plotted successfully.

EXPERIMENT No: 05
AIM OF THE EXPERIMENT: finding convolution using DFT and IDFT APPARATUS REQUIRED : 1. Computer System 2. Matlab Software

THEORY:

DISCRETE FOURIER TRANSFORM

The discrete Fourier transform, or DFT, is the primary tool of digital signal processing. The foundation of the Signal Processing Toolbox is the fast Fourier transform (FFT), a method for computing the DFT with reduced execution time. Many of the toolbox functions (including z-domain frequency response, spectrum and cepstrum analysis, and some filter design and implementation functions) incorporate the FFT. MATLAB provides the functions fft and ifft to compute the discrete Fourier transform and its inverse, respectively. For the input sequence x and its transformed version X (the discrete-time Fourier transform at equally spaced frequencies around the unit circle), the two functions implement the relationships

In these equations, the series subscripts begin with 1 instead of 0 because of the MATLAB vector indexing scheme, and

PROCEDURE: 1. Click on the matlab icon on the desktop. 2. In the command window, click on file menu New M file. 3. In edit window, Type the program as follows below. 4. Then press F5 to save and run the current file. 5. Click on the command window for any error. 6. Now the out can be viewed in the figure window. PROGRAMME : 1. clear 2. m = input('please Enter the size of x1(n) and x2(n):') 3. for i = 1:m 4. x1(i) = input('Please enter the values of x1:'); 5. end 6. for i = 1:m 7. x2(i) = input('Please enter the values of x2:'); 8. end 9. for k = 1:m 10. y1(k) = 0.0; 11. y2(k) = 0.0; 12. for n = 1:m 13. y1(k) = y1(k) + x1(n)*exp(-i*2*pi*(k-1)*(n-1)/m); % DFT 14. y2(k) = y2(k) + x2(n)*exp(-i*2*pi*(k-1)*(n-1)/m); 15. end 16. end 17. sprintf('X1(k) is:') 18. disp(y1) 19. sprintf('X2(k) is:') 20. disp(y2) 21. for k = 1:m 22. y(k) = y1(k)*y2(k); 23. end 24. sprintf('X(k) = X1(k)*X2(k) is:') 25. disp(y) 26. for n = 1:m 27. x3(n) = 0.0; 28. for k = 1:m 29. x3(n) = x3(n) + y(k)*exp(i*2*pi*(k-1)*(n-1)/m); % IDFT 30. end 31. end 32. for n = 1:m 33. x(n) = x3(n)/m; 34. end 35. sprintf('x(n) is:') 36. disp(x) 37. stem(x)

% Creating N-point DFT function (Save as dft.m) function xk=dft(xn,N); L=length(xn); if(N<L) error('N must be >=L'); end x1=[xn,zeros(1,N-L)]; for k=0:N-1 for n=0:1:N-1 w=exp(-i*2*pi*n*k/N); x2(k+1,n+1)=w; end end xk=x1*x2; %*************************** % Implementation of DFT Function(Separate program) clear all; close all; clc; %*************************** xn=[1 1 1]; N=80; Xk=dft(xn,N); mag=abs(Xk); ang=angle(Xk); k=0:N-1; subplot(2,1,1); stem(k,mag); title('N point DFT '); xlabel('time --->'); ylabel('Magnitude ----->'); subplot(2,1,2);stem(k,ang); xlabel('time --->'); ylabel('angle ----->'); %******************************************************

%5.(b)N-point IDFT
% Creating N-point IDFT function (Save as idft.m) function xn=idft(Xk,N) for k=0:1:N-1 for n=0:1:N-1 p=exp(i*2*pi*n*k/N); x2(k+1,n+1)=p; end end xn=(Xk*x2)./N; %****************************************************** % Implementation of DFT Function(Separate program) clear all; close all; clc; %*************************** N=4; Xk=[2+2i,1,-2+3i,2]; xn=idft(Xk,N); k=0:1:N-1; stem(k,xn); xlabel('time --->'); ylabel('Magnitude ----->'); title('N point IDFT ');

EXPERIMENT No: 06
AIM OF THE EXPERIMENT: Implementation of FFT algorithm. (i) Decimation in time (ii) Decimation in frequency APPARATUS REQUIRED : 1. Computer System 2. Matlab Software THEORY: FFT Compute fast Fourier transform (FFT) of input The FFT block computes the fast Fourier transform (FFT) of each channel of an M-by-N or length-M input, u, where M must be a power of two. To work with other input sizes, use the Zero Pad block to pad or truncate the length-M dimension to a power-of-two length. The output of the FFT block is equivalent to the MATLAB fft function: y = fft(u) % Equivalent MATLAB code Thekth entry of the lth output channel, y(k, l), is equal to the kth point of the M-point discrete Fourier transform (DFT) of the lth input channel:

This block supports real and complex floating-point and fixed-point inputs. Algorithms Used for FFT Computation Depending on whether the block's input is floating-point or fixed-point, real- or complexvalued, and whether you want the output in linear or bit-reversed order, the block uses one or more of the following algorithms as summarized in the following tables: 1. Butterfly operation 2. Double-signal algorithm 3. Half-length algorithm 4. Radix-2 decimation-in-time (DIT) algorithm 5. Radix-2 decimation-in-frequency (DIF) algorithm

Fixed-Point Data Types The diagrams below show the data types used within the FFT block for fixed-point signals. You can set the sine table, accumulator, product output, and output data types displayed in the diagrams in the FFT block dialog as discussed in Dialog Box. Inputs to the FFT block are first cast to the output data type and stored in the output buffer. Each butterfly stage then processes signals in the accumulator data type, with the final output of the butterfly being cast back into the output data type. A twiddle factor is multiplied in before each butterfly stage in a decimation-in-time FFT, and after each butterfly stage in a decimation-in-frequency FFT.

Twiddle factor computation Specify the computation method of the term , shown in the first equation of this block reference page. In Table lookup mode, the block computes and stores the sine and cosine values before the simulation starts. In Trigonometric fcn mode, the block computes the sine and cosine values during the simulation. This parameter must be set to Table lookup for fixed-point signals. Optimize table for Select the optimization of the table of sine and cosine values for Speed or Memory. This parameter is only available when the Twiddle factor computation parameter is set to Table lookup. This parameter must be set to Speed for fixed-point signals. Output in bit-reversed order. Designate the order of the output channel elements relative to the ordering of the input elements. When selected, the output channel elements are in bit-reversed order relative to the input ordering. Otherwise, the output column elements are linearly ordered relative to the input ordering. Linearly ordering the output requires extra data sorting manipulation, so in some situations it might be better to output in bit-reversed order.

The Fixed-point pane of the FFT block dialog appears as follows:

Rounding mode Select the rounding mode for fixed-point operations. The sine table values do not obey this parameter; they always round to Nearest. Overflow mode Select the overflow mode for fixed-point operations. The sine table values do not obey this parameter; they are always saturated. Skip divide-by-two on butterfly outputs for fixed-point signals When you select this parameter, no scaling occurs. When you do not select this parameter, the output of each butterfly of the FFT is divided by two for fixed-point signals. Sine table Choose how you will specify the word length of the values of the sine table. The fraction length of the sine table values is always equal to the word length minus one: When you select Same word length as input, the word length of the sine table values will match that of the input to the block. When you select Specify word length, you are able to enter the word length of the sine table values, in bits. The sine table values do not obey the Rounding mode and Overflow mode parameters; they are always saturated and rounded to Nearest.

Product output Use this parameter to specify how you would like to designate the product output word and fraction lengths. Refer to Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block: When you select Inherit via internal rule, the product output word length and fraction length are automatically set according to the following equations:

When you select Same as input, these characteristics will match those of the input to the block. When you select Binary point scaling, you are able to enter the word length and the fraction length of the product output, in bits. When you select Slope and bias scaling, you are able to enter the word length, in bits, and the slope of the product output. This block requires power-of-two slope and a bias of zero. Accumulator Use this parameter to specify how you would like to designate the accumulator word and fraction lengths. Refer to Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the accumulator data type in this block: When you select Inherit via internal rule, the accumulator word length and fraction length are automatically set according to the following equations:

When you select Same as product output, these characteristics will match those of the product output. When you select Same as input, these characteristics will match those of the input to the block. When you select Binary point scaling, you are able to enter the word length and the fraction length of the accumulator, in bits. When you select Slope and bias scaling, you are able to enter the word length, in bits, and the slope of the accumulator. This block requires power-of-two slope and a bias of zero. Output Choose how you will specify the output word length and fraction length: When you select Inherit via internal rule, the output word length and fraction length are automatically set according to the following equations:

When you select Same as input, these characteristics will match those of the input to the block. When you select Binary point scaling, you are able to enter the word length and the fraction length of the output, in bits. When you select Slope and bias scaling, you are able to enter the word length, in bits, and the slope of the output. This block requires power-of-two slope and a bias of zero.

EXPERIMENT No: 07
AIM OF THE EXPERIMENT: Design of Filter ( Low pass, High pass, Band pass using Hamming, Hanning,Rectangular, Kaiser Window) APPARATUS REQUIRED : 1. Computer System 2. Matlab Software THEORY: FIR Filters

The Image Processing Toolbox supports one class of linear filter, the two-dimensional finite impulse response (FIR) filter. FIR filters have several characteristics that make them ideal for image processing in the MATLAB environment: FIR filters are easy to represent as matrices of coefficients. Two-dimensional FIR filters are natural extensions of one-dimensional FIR filters. There are several well-known, reliable methods for FIR filter design. FIR filters are easy to implement. FIR filters can be designed to have linear phase, which helps prevent distortion. Another class of filter, the infinite impulse response (IIR) filter, is not as suitable for image processing applications. It lacks the inherent stability and ease of design and implementation of the FIR filter. Digital filters with finite-duration impulse response (all-zero, or FIR filters) have both advantages and disadvantages compared to infinite-duration impulse response (IIR) filters. FIR filters have the following primary advantages: They can have exactly linear phase. They are always stable. The design methods are generally linear. They can be realized efficiently in hardware. The filter startup transients have finite duration. The primary disadvantage of FIR filters is that they often require a much higher filter order than IIR filters to achieve a given level of performance. Correspondingly, the delay of these filters is often much greater than for an equal performance IIR filter. PROCESS: Designing a Digital Filter In this topic, you use a Digital Filter Design block to create low frequency noise, which models the wind noise inside the cockpit: If the model you created in Modifying Your Model is not open on your desktop, you can open an equivalent model by typing doc_gstut3 at the MATLAB command prompt. This model contains a Time Scope block that displays the original sine wave and the sine wave with white noise added.

Open the Signal Processing Blockset library by typing dsplib at the MATLAB command prompt. Convert white noise to low frequency noise by introducing a Digital Filter Design block into your model. This noise is modeled by the Random Source block. This noise contains only certain frequencies and is more difficult to eliminate. In this example, you model the low frequency noise using a Digital Filter Design block. This block uses the functionality of the Filter Design and Analysis Tool (FDATool) to design a filter. Double-click the Filtering library, and then double-click the Filter Designs library. Click-and-drag the Digital Filter Design block into your model.

Set the Digital Filter Design block parameters to design a lowpass filter and create low frequency noise. Open the Digital Filter Design dialog box by double-clicking the block. Set the block parameters as follows: Response Type = Lowpass Design Method = FIR and, from the list, choose Window Filter Order = Specify order and enter 31 Window = Hamming Units = Normalized (0 to 1) wc = 0.5 Based on these parameters, the Digital Filter Design block designs a lowpass FIR filter with 32 coefficients and a cutoff frequency of 0.5. The block multiplies the time-domain response of your filter by a 32 sample Hamming window. View the magnitude response of your filter in the Magnitude Response window by clicking Design Filter at the bottom center of the dialog. The Digital Filter Design dialog box should now look similar to the following figure.

You have now designed a digital lowpass filter using the Digital Filter Design block. In the next topic, Adding a Digital Filter to Your Model, you integrate your filter into your model.

Adding a Digital Filter to Your Model In this topic, you add the lowpass filter you designed in Designing a Digital Filter to your block diagram. If the model you created in Designing a Digital Filter is not open on your desktop, you can open an equivalent model by typing doc_gstut4 at the MATLAB command prompt.

Incorporate the Digital Filter Design block into your block diagram. Click-and-drag the Digital Filter Design block, and place it between the Random Source block and the Sum block.

Run your model and view the results in the Time Scope window. This window shows the original input signal and the signal with low frequency noise added to it

Now digital filter is created and can be used to model the presence of colored noise in signal.

EXPERIMENT No: 08
AIM OF THE EXPERIMENT: Design of IIR Filter ( Butterworth, Chebyshev) APPARATUS REQUIRED : 1. Computer System 2. Matlab Software

THEORY: IIR Filter Design The primary advantage of IIR filters over FIR filters is that they typically meet a given set of specifications with a much lower filter order than a corresponding FIR filter. Although IIR filters have nonlinear phase, data processing within MATLAB is commonly performed "off-line," that is, the entire data sequence is available prior to filtering. This allows for a noncausal, zero-phase filtering approach (via the filtfilt function), which eliminates the nonlinear phase distortion of an IIR filter. The classical IIR filters, Butterworth, Chebyshev Types I and II, elliptic, and Bessel, all approximate the ideal "brick wall" filter in different ways. This toolbox provides functions to create all these types of classical IIR filters in both the analog and digital domains (except Bessel, for which only the analog case is supported), and in lowpass, highpass, bandpass, and bandstop configurations. For most filter types, you can also find the lowest filter order that fits a given filter specification in terms of passband and stopband attenuation, and transition width(s). The direct filter design function yulewalk finds a filter with magnitude response approximating a desired function. This is one way to create a multiband bandpass filter. You can also use the parametric modeling or system identification functions to design IIR filters. These functions are discussed in Parametric Modeling. The generalized Butterworth design function maxflat is discussed in the section Generalized Butterworth Filter Design.

PROGRAMME: BUTTER WORTH IIR FILTER 1. rp= input(enter the pass band ripple); 2. rs= input( enter the stop band ripple); 3. wp= input( enter the pass band freq); 4. ws= input( enter the stop band freq); 5. fs= input(enter the sampling freq); 6. w1=2*wp/fs; 7. w2=2*ws/fs; 8. [n,wn] = buttord(w1,w2,rp,rs); 9. [b,a] = butter(n,wn); 10. w=0:0.01:pi; 11. [h,om] = freqz(b,a,w); 12. m= 20* log10(abs(h)); 13. an= angle(h); 14. subplot(2,1,1), plot(om/pi,m); 15. xlabel(normalised freq); 16. ylabel(gain in db); 17. subplot(2,1,2), plot(om/pi,an); 18. xlabel(normalised freq); 19. ylabel(phase in radian); Input: Enter the pass band ripple Enter the stop band ripple Enter the pass band freq Enter the stop band freq Enter the sampling freq 0.5 50 1200 2400 10000

CHEBYSHEV IIR FILTER 1. rp= input(enter the pass band ripple); 2. rs= input( enter the stop band ripple); 3. wp= input( enter the pass band freq); 4. ws= input( enter the stop band freq); 5. fs= input(enter the sampling freq); 6. w1=2*wp/fs; 7. w2=2*ws/fs; 8. [n,wn] = cheblord(w1,w2,rp,rs); 9. [b,a] = chebyl(n,rp,wn); 10. w=0:0.01:pi; 11. [h,om] = freqz(b,a,w); 12. m= 20* log10(abs(h)); 13. an= angle(h); 14. subplot(2,1,1), plot(om/pi,m); 15. xlabel(normalised freq); 16. ylabel(gain in db); 17. subplot(2,1,2), plot(om/pi,an); 18. xlabel(normalised freq); 19. ylabel(phase in radian); Input: Enter the pass band ripple Enter the stop band ripple Enter the pass band freq Enter the stop band freq Enter the sampling freq 0.2 45 1300 1500 10000

EXPERIMENT No: 09
AIM OF THE EXPERIMENT: Convolution of long duration sequences using overlap add method & over lap save method. APPARATUS REQUIRED : 1. Computer System 2. Matlab Software

THEORY:

PROGRAMME: 1. clear 2. ls = input('Please enter the size of the vector x(n)::::::') 3. m = input(' Please enter the size of the vector h(n)::::::') 4. for i = 1:ls 5. x(i) = input('Please enter the values of x:::'); 6. end 7. for i = 1:m 8. h(i) = input('Please enter the values of h:'); 9. end 10. lb = input('Please enter the size required for each block of tre vector x(n):::') 11. n = ceil(ls/lb); 12. sprintf('The number of block is "n" =') 13. disp(n) 14. for i = 1:n*lb 15. if i>ls 16. x(i) = 0.0; 17. end 18. end 19. for i = 1:lb+m-1 20. if i<=m 21. h1(i) = h(i); 22. else 23. h1(i) = 0.0; 24. end 25. end 26. disp(h1) 27. for s=1:n 28. for i = 1:lb+m-1 29. if i<=lb 30. y(s,i) = x(lb*(s-1) + i); 31. else 32. y(s,i) = 0.0; 33. end

34. end 35. end 36. sprintf( 'The "n" number of blocks are:') 37. disp(y) 38. for i= 1:lb+m-1 39. for j = 1:lb+m-1 40. k = i -j; 41. if(k>=0) 42. t(i,j) = h1(k+1); 43. else 44. t(i,j)= h1((lb+m-1)+(k+1)); 45. end 46. end 47. end 48. sprintf('For circular convolution the matrix h is:') 49. disp(t) 50. for s = 1:n 51. for i = 1:lb+m-1 52. b(s,i) = 0.0; 53. for j = 1:lb+m-1 54. z(i,j) = t(i,j) * y(s,j); 55. b(s,i) = b(s,i) + z(i,j) 56. end 57. end 58. end 59. sprintf('The obtained matrix is:::') 60. disp(b) 61. r = ls+m-1 62. for s = 1:n 63. for i = 1:r 64. c(s,i) = 0.0; 65. end 66. end 67. for s=1:n 68. d = (s-1) * lb+1 69. for i = 1:lb+m-1 70. c(s,d) = b(s,i); 71. d = d+1; 72. end 73. end 74. sprintf('The matrix c is:::') 75. disp(c) 76. for i = 1:r 77. g(i) = 0.0; 78. for s= 1:n 79. g(i) = g(i) + c(s,i) 80. end 81. end 82. sprintf('The resultant convolution is:::') 83. disp(g)

84. stem(g) 85. title('CONVOLUTION OF A LONG SEQUENCE USING OVERLAP METHOD') 86. xlabel('Number of samples') 87. ylabel('Magnitude') Input: X=[ 1 2 -1 2 3 -2 -3 -1 1 1 2 -1] H=[ 1 2 1 1]

Output: Y= [1 4 4 3 8 5 -2 -6 -6 4 5 1 1 -1]

EXPERIMENT No: 10
AIM OF THE EXPERIMENT: Working with a DSP processor( Fixed pointTM320VC5416/ Floating point series) (I) Implementation of Linear and Circular convolution. (ii) FIR & IIR implementation APPARATUS REQUIRED : 1. Computer System with SP-2 OS. 2. Micro-5416 DSP kit 3. Serial Cable- RS232 4. CRO 5. VI Debugger software. 6. Code composer software THEORY:

PROCEDURE:

PROCEDURE FOR MICRO-5416 PROCESSOR


This is the software where we can convert our ASM( assembly file) to ASC (ascii code). Ten it will downloaded to the 5416 Kit. These are the steps to be followed.

1. Double click on the 5416 Debugger icon in the desktop. 2. When ever it open, it shows one massage like VI hardware found in COM-1. It means your kit and PC are communicating with each other properly. 3. If it is not showing, click on serial menu port setting Auto detect, before that reset your 5416 kit. 4. In the project menu click on the New Project for creating a new project. Give your name of project with the extension *.dpj if it is not available. 5. Then go to the file menu click on new file , in that click on asm file. 6. Then editor window will appear, in which we can type our asm file. 7. The alternative method is to copy your asm file to this location which is stored in another location.

8. After typing the asm file save the file by clicking save option in file menu with the extension *.asm. 9. Then add the file to the project by clicking on the project menu then on add file to project. 10. Do the same procedure to add the cmd file to project i.e Micro5416.cmd file. 11. Then select build from project menu. It is for building your asc file. If any error occurs it shows in the error massage box below the asm file. 12. After successful built , it shows confirmation massage. Now your asc file is created in the same folder as in the asm file. 13. Then browse your *.asc file and click ok. 14. After downloading the asc file go to serial menu click on communication window. 15. In communication window substitute your input at a location given in asm file by typing SD <location> then press enter key. 16. you can enter multiple value one by one by pressing enter key. 17. To come out of it press dot( ) mark after the desired last location. 18. Then type GO 0000 , press enter key. 19. Then Reset your Kit, go to your output location by typing SD <output location> and enter key.

PROCEDURE FOR CODE COMPOSER STUDIO This software is used to convert the C code file to *.out file which will later converted to asc file for downloading. After installing the CCS complier you will find two icons in the desktop. (i) CCS 5000 (ii) Setup for CCS 5000

1.

First click on Setup for CCS5000 icon , it will open a window in that select Platform as 54 and type as Simulator. Then select the 5416 device simulator and click Import. Now the 5416 device simulator was added to your system.

2. Then Select save &quit. It will ask for start of CCS compiler click ok. Then the code composer studio will open automatically. 3. For creating a new project click the Project menu and select the new project, then give the project name with the extension (*.pjt) click finish. The default directory is c:\ ti\ myprojects. 4. For creating a new file click the file menu and click new and select the source file. 5. Type your c file in the editor window and save it by clicking save from file menu. 6. Then give the file name as *.c file and click save option. 7. Go to project menu select add file to the project and add your *.c file to the project. 8. Do the same steps to add the cmd file to the project( MICRO5416.cmd). 9. After adding the *.c & *.cmd file , go to project menu click on the build option for compile the project. 10. after successful compilation the *.out file is created in the default directory i.e c:\ ti\ myprojects\*.pjt \debug\*.out. 11. Then open the 5416 debugger, in that click on tool convert *.out to *.asc option. 12. Then click on browse, select your *.out file and convert . Then *.asc file is also created in the same directory. 13. Then click on serial menu and select load program, browse for the *.asc file click ok. 14. After downloading click on serial menu communication window for execution.

15. In communication window substitute your input at a location given in c file by typing SD <location> then press enter key. 16. you can enter multiple value one by one by pressing enter key. 17. To come out of it press dot( ) mark after the desired last location. 18. Then type GO 0000 , press enter key. 19. Then Reset your Kit, go to your output location by typing SD <output location> and enter key.

PROGRAMME: main() { unsigned int *ptr;

LINEAR CONVOLUTION

int xval[255],hval[255], outval[255]; int n,k,n1,n2; ptr = (unsigned int *) 0x9200; // input and Output in 0x9200; n1 = 4; n2 = 4; for(n=0;n<255;n++) // initialize inputs to 0 { xval[n] = 0; hval[n] = 0; outval[n] = 0; } for(n=0;n<n1;n++) // Get input 1 xval[n] = *(ptr + n); for(n=0;n<n2;n++) // Get input 2 hval[n] = *(ptr + n + n1); for(n=0;n<(n1+n2-1);n++) // Convolution Formula for(k=0;k<=n;k++) outval[n] = outval[n] + (xval[k] * hval[n-k]); for(n=0;n<(n1+n2);n++) // Store the value

*(ptr+n1+n2+n) = outval[n]; }

CIRCULAR CONVOLUTION main() { unsigned int xval[255], hval[255], outval[255], n1, n2, i, j; unsigned int *outvaladdr; outvaladdr = (unsigned int *) 0x9200; // Starting Address of Input and outvalput

n1 = 4; // Fixed n2 = 4; for(i=0;i<n1;i++) { xval[i] = *(outvaladdr + i); hval[i] = *(outvaladdr + i + n1); outval[i] = 0; } i = xval[3]; xval[3] = xval[1]; xval[1] = i; outval[0] = (xval[0] * hval[0]) + (xval[1] * hval[1]) + (xval[2] * hval[2]) + (xval[3] * hval[3]); outval[1] = (xval[0] * hval[3]) + (xval[1] * hval[0]) + (xval[2] * hval[1]) + (xval[3] * hval[2]); outval[2] = (xval[0] * hval[2]) + (xval[1] * hval[3]) + (xval[2] * hval[0]) + (xval[3] * hval[1]); outval[3] = (xval[0] * hval[1]) + (xval[1] * hval[2]) + (xval[2] * hval[3]) + (xval[3] * hval[0]); for(i=0;i<n1;i++) *(outvaladdr + n1 + n2 + i) = outval[i]; while(1); } // To swap the sequence

Double-click the Sine Wave block. The Block Parameters: Sine Wave dialog box opens. Set the block parameters as follows: Amplitude = 1 Frequency = [15 40] Phase offset =0 Sample time = 0.001 Samples per frame = 128 Based on these parameters, the Sine Wave block outputs two, frame-based sinusoidal signals with identical amplitudes, phases, and sample times. One sinusoid oscillates at 15 Hz and the other at 40 Hz. Save these parameters and close the dialog box by clicking OK.

Double-click the Matrix Sum block. The Block Parameters: Matrix Sum dialog box opens. Set the Sum along parameter to Rows, and then click OK. Since each column represents a different signal, you need to sum along the individual rows in order to add the values of the sinusoids at each time step. Double-click the Complex to Magnitude-Angle block. The Block Parameters: Complex to Magnitude-Angle dialog box opens. Set the Output parameter to Magnitude, and then click OK. This block takes the complex output of the FFT block and converts this output to magnitude. Double-click the Vector Scope block. Set the block parameters as follows, and then click OK: Click the Scope Properties tab. Input domain = Frequency Click the Axis Properties tab. Frequency units = Hertz (This corresponds to the units of the input signals.) Frequency range = [0...Fs/2] Select the Inherit sample time from input check box. Amplitude scaling = Magnitude Run the model. The scope shows the two peaks at 0.015 and 0.04 kHz, as expected

Double-click the Sine Wave block. The Block Parameters: Sine Wave dialog box opens. Set the block parameters as follows: Amplitude = 1 Frequency = [15 40] Phase offset = 0 Sample time = 0.001 Samples per frame = 128 Based on these parameters, the Sine Wave block outputs two, frame-based sinusoidal signals with identical amplitudes, phases, and sample times. One sinusoid oscillates at 15 Hz and the other at 40 Hz. Save these parameters and close the dialog box by clicking OK Double-click the Matrix Sum block. The Block Parameters: Matrix Sum dialog box opens.

Set the Sum along parameter to Rows, and then click OK. Since each column represents a different signal, you need to sum along the individual rows in order to add the values of the sinusoids at each time step. Double-click the FFT block. The Block Parameters: FFT dialog box opens. Select the Output in bit-reversed order check box., and then click OK. Double-click the IFFT block. The Block Parameters: IFFT dialog box opens. Set the block parameters as follows, and then click OK: Select the Input is in bit-reversed order check box. Select the Input is conjugate symmetric check box. Because the original sinusoidal signal is real valued, the output of the FFT block is conjugate symmetric. By conveying this information to the IFFT block, you optimize its operation. Note that the Sum block subtracts the original signal from the output of the IIFT block, which is the estimation of the original signal. Double-click the Vector Scope block. Set the block parameters as follows, and then click OK: Click the Scope Properties tab. Input domain = Time Run the model.

Вам также может понравиться