You are on page 1of 47

DSP FILE: MATLAB

ANKIT PRUSTY EEE (6TH SEM) 06713204909

Introduction to Matlab What Is MATLAB? MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-touse 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 engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation. 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 consists of five main parts: 1. 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. 2. 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. 3. 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. 4. 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 two-dimensional 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. 5. 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 TOOLBOXES
1. Bioinformatics Toolbox
The Bioinformatics Toolbox extends MATLAB to provide an integrated software environment for genome and proteome analysis. Together, MATLAB and the Bioinformatics Toolbox give scientists and engineers a set of computational tools to solve problems and build applications in drug discovery, genetic engineering, and biological research.

2. Communications Toolbox
The Communications Toolbox extends the MATLAB technical computing environment with functions, plots, and a graphical user interface for exploring, designing, analyzing, and simulating algorithms for the physical layer of communication systems. The toolbox helps you create algorithms for commercial and defense wireless or wireline systems

3. Curve Fitting Toolbox


The Curve Fitting Toolbox is a collection of graphical user interfaces (GUIs) and M-file functions built on the MATLAB technical computing environment. The toolbox provides you with these main features: Data preprocessing such as sectioning and smoothing Parametric and nonparametric data fitting: You can perform a parametric fit using a toolbox library equation or using a custom equation. Library equations include polynomials, exponentials, rationals, sums of Gaussians, and so on. Custom equations are equations that you define to suit your specific curve fitting needs.

You can perform a nonparametric fit using a smoothing spline or various interpolants. Standard linear least squares, nonlinear least squares, weighted least squares, constrained least squares, and robust fitting procedures Fit statistics to assist you in determining the goodness of fit Analysis capabilities such as extrapolation, differentiation, and integration A graphical environment that allows you to: Explore and analyze data sets and fits visually and numerically Save your work in various formats including M-files, binary files, and workspace variables

4. Data Acquisition Toolbox


The Data Acquisition Toolbox is a collection of M-file functions and MEX-file dynamic link libraries (DLLs) built on the MATLAB technical computing environment. The toolbox provides you with these main features: A framework for bringing live, measured data into MATLAB using PC-compatible, plug-in data acquisition hardware Support for analog input (AI), analog output (AO), and digital I/O (DIO) subsystems including simultaneous analog I/O conversions Support for these popular hardware vendors/devices: Advantech boards that use the Advantech Device Manager Agilent Technologies E1432A/33A/34A VXI modules Keithley boards that use DriverLINX drivers. Measurement Computing Corporation (ComputerBoards) boards National Instruments boards that use NIDAQ software (except SCXI) Parallel ports LPT1-LPT3 Windows sound cards Additionally, you can use the Data Acquisition Toolbox Adaptor Kit to interface unsupported hardware devices to the toolbox. Eventdriven acquisitions

5. Datafeed Toolbox
This document describes the Datafeed Toolbox for MATLAB. The Datafeed Toolbox effectively turns your MATLAB workstation into a financial data acquisition terminal. Using the Datafeed Toolbox, you can download a wide variety of security data from financial data servers into your MATLAB workspace. Then, you can pass this data to MATLAB or to another toolbox, such as the Financial Time Series Toolbox, for further analysis.

6. Filter Design Toolbox


The Filter Design Toolbox is a collection of tools that provides advanced techniques for designing, simulating, and analyzing digital filters. It extends the capabilities of the Signal Processing Toolbox with filter architectures and design methods for complex real-time DSP applications, including adaptive filtering and multirate filtering, as well as filter transformations. Used with the Fixed-Point Toolbox, the Filter Design Toolbox provides functions that simplify the design of fixed-point filters and the analysis of quantization effects. When used with the Filter Design HDL Coder, the Filter Design Toolbox lets you generate VHDL and Verilog code for fixed-point filters

7. Financial Toolbox
MATLAB and the Financial Toolbox provide a complete integrated computing environment for financial analysis and engineering. The toolbox has everything you need to perform mathematical and statistical analysis of financial data and display the results with presentation-quality graphics. You can quickly ask, visualize, and answer complicated questions.

8. Fixed-Point Toolbox
The Fixed-Point Toolbox provides fixed-point data types in MATLAB and enables algorithm development by providing fixedpoint arithmetic. The Fixed-Point Toolbox enables you to create the following types of objects: fi -- Defines a fixed-point numeric object in the MATLAB workspace. Each fi object is composed of value data, a fimath object, and a numerictype object. fimath -- Governs how overloaded arithmetic operators work with fi objects fipref -Defines the display of fi objects numerictype -- Defines the data type and scaling attributes of fi objects quantizer -- Quantizes data sets

9.

Fuzzy Logic Toolbox

The Fuzzy Logic Toolbox is a collection of functions built on the MATLAB numeric computing environment. It provides tools for you to create and edit fuzzy inference systems within the framework of MATLAB, or if you prefer, you can integrate your fuzzy systems into simulations with Simulink

10.

Genetic Algorithm and Direct Search Toolbox

The Genetic Algorithm and Direct Search Toolbox is a collection of functions that extend the capabilities of the Optimization Toolbox and the MATLAB numeric computing environment. The Genetic Algorithm and Direct Search Toolbox includes routines for solving optimization problems using Genetic algorithm Direct search

11.

Image Processing Toolbox

The Image Processing Toolbox is a collection of functions that extend the capability of the MATLAB numeric computing environment. The toolbox supports a wide range of image processing operations, including Spatial image transformations Morphological operations

Neighborhood and block operations Linear filtering and filter design Transforms Image analysis and enhancement Image registration Deblurring Region of interest operations

12.

Instrument Control Toolbox

The Instrument Control Toolbox is a collection of M-file functions built on the MATLAB technical computing environment. The toolbox provides you with these features: A framework for communicating with instruments that support the GPIB interface (IEEE-488), the VISA standard, and the TCP/IP and UDP protocols. Note that the toolbox extends the basic serial port features included with MATLAB. Support for IVI, VXIplug&play, and MATLAB instrument drivers Functions for transferring data between MATLAB and your instrument: The data can be binary (numerical) or text. The transfer can be synchronous and block the MATLAB command line, or asynchronous and allow access to the MATLAB command line. Event-based communication Functions for recording data and event information to a text file Tools that facilitate instrument control in an easy-to-use graphical environment 13.

Partial Differential Equation Toolbox

The objectives of the PDE Toolbox are to provide you with tools that Define a PDE problem, e.g., define 2-D regions, boundary conditions, and PDE coefficients. Numerically solve the PDE problem, e.g., generate unstructured meshes, discretize the equations, and produce an approximation to the solution. Visualize the results.

14.

RF Toolbox

The RF Toolbox enables you to create and combine RF (Radio Frequency) circuits for simulation in the frequency domain with support for both nonlinear and noise data. You can read, write, analyze, combine, and visualize RF network parameters. RF technology is used to design and test RF circuits for cable television, wireless LAN, and other wireless applications such as broadcasting, radar, satellite communications, microwave relay, and mobile telephony.

15.

Robust Control Toolbox

The Robust Control Toolbox (RCT) is a collection of functions and tools that help you to analyze and design MIMO control systems with uncertain elements. You can build uncertain LTI system models containing uncertain parameters and uncertain dynamics. You get tools to analyze MIMO system stability margins and worst case performance

16.

Signal Processing Toolbox

The Signal Processing Toolbox is a collection of tools built on the MATLAB numeric computing environment. The toolbox supports a wide range of signal processing operations, from waveform generation to filter design and implementation, parametric modeling, and spectral analysis.

Operators Expressions use familiar arithmetic operators and precedence rules. + * / \ Addition Subtraction Multiplication Division Left division (described in Matrices and Linear Algebra in the MATLAB documentation) Power Complex conjugate transpose Specify evalution order

^ ()

Functions MATLAB provides a large number of standard elementary mathematical functions, including abs, sqrt, exp and sin.. MATLAB also provides many more advanced mathematical functions, including Bessel and gamma functions. Most of these functions accept complex arguments.

Some of the functions, like sqrt and sin, are built in functions 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 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 provides values of useful constants. Pi I J Eps realmin realmax Inf NaN 3.14159265 Imaginary unit, Same as I, Floating-point relative precision, Smallest floating-point number, Largest floating-point number, Infinity Not-a-number

Infinity is generated by dividing a non zero value by zero, or by evaluating well defined mathematical expressions that overflow, i.e. exceed realmax.

Subplot
Syntax h = subplot(m,n,p) or subplot(mnp) subplot(m,n,p,'replace') subplot(m,n,P) subplot(h) Description subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane contains an axes object which you can manipulate using Axes Properties. Subsequent plots are output to the current pane. h = subplot(m,n,p) or subplot(mnp) breaks the figure window into an mby-n matrix of small axes, selects the pth axes object for the current plot,

and returns the axes handle. The axes are counted along the top row of the figure window, then the second row, etc. For example, subplot(m,n,p,'replace') If the specified axes object already exists, delete it and create a new axes. subplot(m,n,P), where P is a vector, specifies an axes position that covers all the subplot positions listed in P, including those spanned by P. For example, subplot(2,3,[2 5]) creates one axes spanning positions 2 and 5 only (because there are no intervening locations in the grid), while subplot(2,3,[2 6]) creates one axes spanning positions 2, 3, 5, and 6. subplot(h) makes the axes object with handle h current for subsequent plotting commands.

Plot
Syntax plot(Y) plot(X1,Y1,...,Xn,Yn) Description plot(Y) plots the columns of Y versus the index of each value when Y is a real number. For complex Y, plot(Y) is equivalent to plot(real(Y),imag(Y)). plot(X1,Y1,...,Xn,Yn) plots each vector Yn versus vector Xn on the same axes. If one of Yn or Xn is a matrix and the other is a vector, plots the vector versus the matrix row or column with a matching dimension to the vector. If Xn is a scalar and Yn is a vector, plots discrete Yn points vertically at Xn. If Xn or Yn are complex, imaginary components are ignored. plot automatically chooses colors and line styles in the order specified by ColorOrder and LineStyleOrder properties of current axes.

Stem
Syntax stem(Y) stem(X,Y) stem(...,'fill') stem(...,LineSpec) h = stem(...) Description A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A circle (the default) or other marker whose yposition represents the data value terminates each stem. stem(Y) plots the data sequence Y as stems that extend from equally spaced and automatically generated values along the x-axis. When Y is a matrix, stem plots all elements in a row against the same x value. stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows. stem(...,'fill') specifies whether to color the circle at the end of the stem. stem(...,LineSpec) specifies the line style, marker symbol, and color for the stem and top marker (the baseline is not affected). h = stem(...) returns a vector of stemseries object handles in h, one handle per column of data in Y.

Clc: Clc clears all input and output from the Command Window display, giving you a "clean screen."After using Clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow to recall statements from the command history. Clear all: Clear removes all variables from the workspace, releasing them from system memory.clear name removes just the code file or MEX-file function or variable name from your base workspace. If called from a function, clear name removes name from both the function workspace and in your base workspace. You can use wildcards (*) to remove items selectively. Clearing removes debugging breakpoints in code files and reinitializes persistent variables.

Ones
Create array of all ones Syntax Y = ones(n) Y = ones(m,n) Y = ones([m n]) Y = ones(m,n,p,...) Y = ones([m n p ...]) Description Y = ones(n) returns an n-by-n matrix of 1s. An error message appears if n is not a scalar. Y = ones(m,n) or Y = ones([m n]) returns an m-by-n matrix of ones.

Y = ones(m,n,p,...) or Y = ones([m n p ...]) returns an m-by-n-by-p-by-... array of 1s.

Zeros
Create array of all zeros Syntax B = zeros(n) B = zeros(m,n) B = zeros([m n]) B = zeros(m,n,p,...) B = zeros([m n p ...]) Description B = zeros(n) returns an n-by-n matrix of zeros. An error message appears if n is not a scalar. B = zeros(m,n) or B = zeros([m n]) returns an m-by-n matrix of zeros. B = zeros(m,n,p,...) or B = zeros([m n p ...]) returns an m-by-n-by-p-by... array of zeros.

Experiment 1
AIM To determine transpose, inverse, addition, subtraction and division of given matrix. THEORY A matrix is a two dimensional array of real or complex numbers. Linear algebra defines many matrix operations that are directly supported by MATLAB. Linear algebra includes matrix arthimatic, linear equations, eigenvalues, singular values and matrix factorizations.

This section describes the following topics: 1. Creating Matrices 2. Adding and subtracting Matrices 3. Vector products and Transpose 4. Multiplying Matrices 5. The Identity Matrix

PROGRAM CODE:

clc clear all close all % MATRIX A A= [12 34 56; 9 10 11; 23 54 55] %MATRIX B B= [12 34 77;4 7 6;11 10 19] %Addition of matrix A and B C=A+B %Subtraction of matrix A and B D=A-B %Multiplication of matrix A and B E=A*B %Inverse of matrix A F=inv(A) %Transpose of matrix B G= B'

OUTPUT

EXPERIMENT 2
AIM Program for generation of sin, cos, exponential, unit impulse, step function, ramp function. THEORY Sine Function: A function f(x)=sin(x) is a periodic function with a period of 2, it will form a periodic wave after 2. The f(x) will lie between -1 to +1. Cosine Function: A function f(x)=cos(x) is a periodic function with a period of 2, it will form a periodic wave after 2. Exponential Function: A function f(x)=ex is defined as: 0<f(x)1; 1f(x)<; for -x0 for 0x

Unit impulse Function: Unit impulse is a signal that is 0 everywhere except at n=0 where it is 1. In discrete time domain the unit impulse signal is defined as: (n) =1; = 0; n=0 elsewhere

Unit Step Function: The integral of the impulse function is a unit step signal. In discrete time unit step signal is defined as: U(n) =1; = 0; n>=0 n<0

PROGRAM CODE: clc clear all close all %Code for sine wave x= -pi:0.1:pi y=sin(x) subplot(321) stem(x,y) xlabel('Time') ylabel('Amplitude') title('Sine Wave') %Code for cosine wave y=cos(x) subplot(322) stem(x,y) xlabel('Time') ylabel('Amplitude') title('Cosine Wave') %Code for exponential wave z=exp(x) subplot(323) stem(x,z) xlabel('Time') ylabel('Amplitude') title('Exponential Wave')

%Code for Step function m=-4:5 for j=1:4 g(j)=0 end for j=5:10 g(j)=1 end subplot(324) stem(m,g) xlabel('Time') ylabel('Amplitude') title('Step Function') %Code for Unit Impulse h(5)=1 for i=1:4 h(i)=0 end for i=6:10 h(i)=0 end; subplot(325) stem(m,h) xlabel('Time') ylabel('Amplitude') title('Unit Impulse') %Code for Ramp function v=0:5 subplot(326) stem(v,v) xlabel('Time') ylabel('Amplitude') title('Ramp ')

OUTPUT

OUTPUT

EXPERIMENT 3(a)
AIM To perform convolution using MATLAB THEORY A convolution is an integral that expresses the amount of overlap of one function as it is shifted over another function. It therefore blends from one function to another.
Y(n)= x(k)h(n-k)

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. PROPERTIES OF CONVOLUTION
1. 2.

COMMUTATIVE LAW: x(n)*h(n) = h(n)* x(n) ASSOCIATIVE LAW: [x(n)*h1(n)]*h2(n) = x(n)*[h1(n)*h2(n)]

3. DISTRIBUTIVE LAW: x(n)*[h1(n)+h2(n)] = x(n)*h1(n) + x(n) * h2(n)

PROGRAM CODE: clc clear all close all %Code to perform convolution function x= [1 2 3 4 5] y= [2 5 6 9 3] z= conv(x,y) subplot(311) stem(x) xlabel('Time') ylabel('Amplitude') title('Input x') subplot(312) stem(y) xlabel('Time') ylabel('Amplitude') title('Intput y') subplot(313) stem(z) xlabel('Time') ylabel('Amplitude') title('Convolved Output')

OUTPUT

EXPERIMENT 3(b)
AIM To perform Circular Convolution using MATLAB THEORY

cconv
Modulo-N circular convolution Syntax c = cconv(a,b,n) Description Circular convolution is used to convolve two discrete Fourier transform (DFT) sequences. For very long sequences, circular convolution may be faster than linear convolution. c = cconv(a,b,n) circularly convolves vectors a and b. n is the length of the resulting vector. If you omit n, it defaults to length(a)+length(B)-1. When n = length(a)+length(B)-1, the circular convolution is equivalent to the linear convolution computed with conv. You can also use cconv to compute the circular cross-correlation of two sequences.

PROGRAM CODE %Code to perform circular convolution function x= [1 2 3 4 5] y= [2 5 6 9 3] z= cconv(x,y,5) subplot(311) stem(x) xlabel('Time') ylabel('Amplitude') title('Input x') subplot(312) stem(y) xlabel('Time') ylabel('Amplitude') title('Intput y') subplot(313) stem(z) xlabel('Time') ylabel('Amplitude') title('Convolved Output')

OUTPUT

EXPERIMENT 4
AIM To determine the correlation of two sequences. THEORY: Suppose that we have two signal sequences x(n) and y(n) each of which has finite energy. The cross correlation of x(n) and y(n) is a sequence rxy(l), which is defined as r xy (l) = or equivalently as r xy (l) = x(n+l) y(n) x(n) y(n-l)

the index l is the time shift (or lag) parameter and the subscript xy on the cross correlation sequence r xy (l) indicates the sequence being correlated. The order of the subscript, with x preceding y, indicates the direction in which one sequence is shifted relative to other. If we reverse the role of x(n) and y(n) in above equation we obtain the correlation sequence r yx (l) = or equivalently as r yx (l) = y(n+l) x(n) y(n) x(n-l)

by comparing the equations r xy (l) = r yx (-l)

therefore r yx (l) is simply folded version of r xy (l) where the folding is done with respect to l=0. Syntax c = xcorr(x,y) In the special case where y(n)=x(n) , we have AUTOCORRELATION of x(n) which is defined as the sequence r xx (l) = or equivalently as r xx (l) = Syntax c = xcorr(x,x) x(n+l) x(n) x(n) x(n-l)

PROGRAM CODE:
clc close all clear all %Code to generate cross-correlation of two sequences x=[4 9 8 7 2] y=[5 1 3 6 0] z= xcorr(x,y) subplot(221) stem(x) xlabel('Time') ylabel('Amplitude') title('Input x') subplot(222) stem(z) xlabel('Time') ylabel('Amplitude') title('Input y') subplot(223) stem(z) xlabel('Time') ylabel('Amplitude') title('Cross-correlation')

%Code to generate autocorrelation of two sequences w= xcorr(x,x) subplot(224) stem(w) xlabel('Time') ylabel('Amplitude') title('Autocorrelation')

OUTPUT

EXPERIMENT 5
AIM Program for addition of two signals . THEORY Ones Create array of all ones Syntax Y = ones(n) Y = ones(m,n) Y = ones([m n]) Y = ones(m,n,p,...) Y = ones([m n p ...]) Y = ones(size(A)) ones(m, n,..., classname) ones([m,n,...], classname) Description Y = ones (n) returns an n-by-n matrix of 1s. An error message appears if n is not a scalar. Y = ones (m,n) or Y = ones([m n]) returns an m-by-n matrix of ones. Y = ones (m,n,p,...) or Y = ones([m n p ...]) returns an m-by-n-by-p-by... array of 1s.

Zeros
Create array of all zeros Syntax B = zeros(n) B = zeros(m,n) B = zeros([m n]) B = zeros(m,n,p,...) B = zeros([m n p ...]) Description B = zeros(n) returns an n-by-n matrix of zeros. An error message appears if n is not a scalar. B = zeros(m,n) or B = zeros([m n]) returns an m-by-n matrix of zeros. B = zeros(m,n,p,...) or B = zeros([m n p ...]) returns an m-by-n-by-p-by... array of zeros. Unit Step Function: The integral of the impulse function is a unit step signal. In discrete time unit step signal is defined as: U(n) =1; n>=0 = 0; n<0 Ramp Function: The integral of the unit step function is a ramp signal. In discrete time ramp signal is defined as: R(n) =n; n>=0 = 0; n<0

PROGRAM CODE %Generate rectangular function n= -3:1:3 a= ones(1,7) for i=1:7 b(i)=n(i)+3 end subplot(311) stem(n,a) xlabel('n') ylabel('a(n)') title('Rectangular Function') %Generate triangular function subplot(312) stem(n,b) xlabel('n') ylabel('b(n)') title('Triangular Function') x=a+b subplot(313) stem(n,x) xlabel('n') ylabel('x(n)') title('Superimposed Function')

OUTPUT

EXPERIMENT 6
AIM Program to perform Discrete Fourier Transform(DFT) of a sequence using Fast Fourier Transform(FFT) . THEORY The Discrete Fourier Transform computes the values of the z transform for evenly spaced points around the unit circle for a given sequence. If the sequence to be represented is of finite duration, i.e., has only a finite number of non-zero values, the transform is discrete Fourier transform. N-1 X(k) = x(n) e-j2kn/N n=0 k = 0,1,2..,N-1

Fast Fourier Transform


Syntax Y = fft(X) Y = fft(X,n)

Definition The functions Y=fft(x) and y=ifft(X) implement the transform and inverse transform pair given for vectors of length by:

Description Y = fft(X) returns the discrete Fourier transform (DFT) of vector X, computed with a fast Fourier transform (FFT) algorithm. If X is a matrix, fft returns the Fourier transform of each column of the matrix. If X is a multidimensional array, fft operates on the first non-singleton dimension. Y = fft(X,n) returns the n-point DFT. If the length of X is less than n, X is padded with trailing zeros to length n. If the length of X is greater than n, the sequence X is truncated.

PROGRAM CODE clc close all clear all %Code to generate DFT using FFT x=[4 1 8 5] z= fft(x) subplot(211) stem(x) xlabel('Time') ylabel('Amplitude') title('Input x') subplot(212) stem(z) xlabel('Time') ylabel('Amplitude') title('DFT Function')

OUTPUT

EXPERIMENT 6(b)
AIM Program to perform Inverse Discrete Fourier Transform (IDFT) . THEORY Inverse Discrete Fourier Transform

Syntax
y = ifft(X) y = ifft(X,n) y = ifft(X,[],dim) y = ifft(X,n,dim) Description y = ifft(X) returns the inverse discrete Fourier transform (DFT) of vector X, computed with a fast Fourier transform (FFT) algorithm. If X is a matrix, ifft returns the inverse DFT of each column of the matrix. ifft tests X to see whether vectors in X along the active dimension are conjugate symmetric. If so, the computation is faster and the output is real. An N-element vector x is conjugate symmetric if x(i) = conj(x(mod(N-i+1,N)+1)) for each element of x. If X is a multidimensional array, ifft operates on the first non-singleton dimension. y = ifft(X,n) returns the n-point inverse DFT of vector X. y = ifft(X,[],dim) and y = ifft(X,n,dim) return the inverse DFT of X across the dimension dim.

PROGRAM CODE clc close all clear all %Code to generate IDFT x=[4 1 8 5] z= ifft(x) subplot(211) stem(x) xlabel('Time') ylabel('Amplitude') title('Input x') subplot(212) stem(z) xlabel('Time') ylabel('Amplitude') title('IDFT Function')

OUTPUT

You might also like