matlab

45
ASSIGNMENT NO. 1 OBJECT: Study of MATLAB and its tools 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. The name MATLAB stands for matrix laboratory. 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 non-interactive language such as C or Fortran. 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. 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 1

Upload: vinirox

Post on 23-Nov-2014

484 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Matlab

ASSIGNMENT NO. 1

OBJECT: Study of MATLAB and its tools

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. The name MATLAB stands for matrix laboratory.

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 non-interactive language such as C or Fortran. 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.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.

MATLAB DocumentationMATLAB provides extensive documentation, in both printable and HTML format, to help you learn about and use all of its features. If you are a new user, start with this Getting Started book. It covers all the primary MATLAB features at a high level, including many examples. To view the online documentation, select MATLAB Help from the Help menu in MATLAB. Online help appears in the Help browser, providing task-oriented and reference information about MATLAB features.

1

Page 2: Matlab

The MATLAB documentation is organized into these main topics:

Desktop Tools and Development Environment — Startup and shutdown, the desktop, and other tools that help you use MATLAB.

Mathematics — Mathematical operations on Data.

Analysis — Data analysis, including data fitting, Fourier analysis, and time-series tools.

Programming — The MATLAB language and how to develop MATLAB applications Graphics Tools and techniques for plotting, graph annotation, printing, and programming with Handle Graphics®3-D.

Visualization — Visualizing surface and volume data, transparency, and viewing and lighting techniques creating.

Graphical User Interfaces — GUI-building tools and how to write callback functions External

Interfaces — MEX-files, the MATLAB engine, and interfacing to Java, COM, and the serial port.

MATLAB also includes reference documentation for all MATLAB functions:

Functions — By Category —Lists all MATLAB functions grouped into categories Handle Graphics

Property Browser — Provides easy access to descriptions of graphics object properties

C and Fortran API Reference — Covers those functions used by the MATLAB external interfaces, providing information on syntax in the calling language, description, arguments, return values, and examples

The MATLAB online documentation also includes

Examples — An index of examples included in the documentation Release

Notes — New features, compatibility considerations, and bug reports Printable

Documentation — PDF versions of the documentation suitable for printing

2

Page 3: Matlab

Signal Processing Blockset

Signal Processing Blockset is a tool for digital signal processing algorithm simulation and code generation. It adds frame-based processing to the Simulink® environment. Signal Processing Blockset is made up of block libraries containing signal processing, linear algebra, and matrix math blocks. All of the blocks support double- and single-precision floating-point data types. Most blocks also support fixed-point and integer data types when you also have Simulink Fixed Point. You can interconnect Signal Processing Blockset blocks to create sophisticated models capable of simulating operations such as speech and audio processing, wireless digital communications, radar/sonar, and medical electronics.Signal Processing Blockset requires Simulink, a tool for simulating dynamic systems. Simulink is a model definition environment. Use Simulink blocks to create a block diagram that represents the computations of your system or application. Simulink is also a model simulation environment. Run the block diagram to see how your system behaves. All of the blocks in Signal Processing Blockset are designed for use with the blocks in the Simulink libraries. If you are new to Simulink, read Getting Started with Simulink to better understand its functionality. You can use Signal Processing Blockset and Simulink to develop your signal processing concepts and to efficiently revise and test these concepts until your design is production-ready. You can also use Signal Processing Blockset in conjunction with Real-Time Workshop® to automatically generate code for real-time execution on DSP hardware.

Required ProductsSignal Processing Blockset is part of a family of products from The MathWorks. You need to install the following products to use Signal Processing Blockset:

MATLAB Simulink Signal Processing Toolbox

MATLABYou can use MATLAB to open model files and view Signal Processing Blockset demos. You can import signal values from the MATLAB workspace into signal processing models and export signal values from signal processing models to the MATLAB workspace.

SimulinkSimulink provides an environment that enables you to create a block diagram to model your physical system. You can create these block diagrams by connecting blocks and using graphical user interfaces (GUIs) to edit block parameters.

Signal Processing ToolboxSignal Processing Toolbox provides basic filter capabilities. You can design and implement filters using the Filter Design and Analysis Tool (FDA Tool) and use them in your signal

3

Page 4: Matlab

processing models.

Blocks — By Category

Estimation : Perform spectrum estimates a autoregressive -modeling Filtering : Design, create, and work with filtersMath Functions : Perform linear algebra and basic math calculationsQuantizers : Design and implement quantization schemesSignal Management : Perform basic signal processing operationsSignal Operations : Control signal attributes, buffer signals, and index signalsSignal Processing Sinks : View or log signalsSignal Processing Sources : Generate discrete-time signalsStatistics : Perform statistical computations on signalsTransforms : Compute transforms

Estimation:

Linear Prediction Compute or work with linear predictive representations

Parametric Estimation Compute estimates of autoregressive model parameters

Power Spectrum Estimation Compute parametric and nonparametric spectral estimates

Linear Prediction:

Autocorrelation LPC Determine coefficients of Nth-order forward linear predictors

Levinson-Durbin Solve linear system of equations using Levinson-Durbin recursion

LPC to LSF/LSP Conversion Convert linear prediction coefficients to line spectral pairs or line spectral frequencies

LPC to/from Cepstral Coefficients Convert linear prediction coefficients to cepstral coefficients or cepstral coefficients to linear prediction coefficients

LPC to/from RC Convert linear prediction coefficients to reflection coefficients or reflection coefficients to linear prediction coefficients

4

Page 5: Matlab

Parametric Estimation

Burg AR Estimator Compute estimate of autoregressive (AR) model parameters using Burg method

Covariance AR Estimator Compute estimate of autoregressive (AR) model parameters using Covariance method

Modified Covariance AR Estimator Compute estimate of autoregressive (AR) model parameters using modified covariance method

Yule-Walker AR Estimator Compute estimate of autoregressive (AR) model parameters using Yule-Walker method

Power Spectrum Estimation

Burg Method Compute parametric spectral estimate using Burg Method

Covariance Method Compute parametric spectral estimate using covariance method

Magnitude FFT Compute nonparametric estimate of spectrum using periodogram method

Modified Covariance Method Compute parametric spectral estimate using modified covariance method

Periodogram Compute nonparametric estimate of spectrum

Yule-Walker Method Compute parametric estimate of spectrum using Yule-Walker autoregressive (AR) method

Filtering

Adaptive Filters Use adaptive filter algorithms

Filter Design Toolbox Design and implement single- and multi-rate FIR and IIR filters

Filter Designs Design and implement filters

Multi-rate Filters Implement multi-rate filters

5

Page 6: Matlab

Adaptive Filters

Block LMS Filter Compute filtered output, filter error, and filter weights for given input and desired signal using Block LMS adaptive filter algorithm

Fast Block LMS Filter Compute filtered output, filter error, and filter weights for given input and desired signal using Fast Block LMS adaptive filter algorithm

Kalman Adaptive Filter Compute filter estimates for inputs using Kalman adaptive filter algorithm

Kalman Filter Predict or estimate states of dynamic systems

LMS Filter Compute filtered output, filter error, and filter weights for given input and desired signal using LMS adaptive filter algorithm

RLS Filter Compute filtered output, filter error, and filter weights for given input and desired signal using RLS adaptive filter algorithm

Filter Design Toolbox

Arbitrary Magnitude Filter Design arbitrary response filter

Band-pass Filter Design band-pass filter

Band-stop Filter Design band-stop filter

CIC Compensator Design CIC compensator

CIC Filter Design Cascaded Integrator-Comb (CIC) Filter

Differentiator Filter Design differentiator filter

Fractional Delay Filter Design fractional delay filter

Half-band Filter Design half-band filter

High-pass Filter Design high-pass filter

Hilbert Filter Design Hilbert filter

Inverse Sinc Filter Design inverse sinc filter

Low-pass Filter Design low-pass Filter

Nyquist Filter Design Nyquist filter

Octave Filter Design octave filter

6

Page 7: Matlab

Filter Designs

Analog Filter Design Design and implement analog filters

Digital Filter Filter each channel of input over time using static or time-varying digital filter implementations

Digital Filter Design Design and implement digital FIR and IIR filters

Filter Realization Wizard Construct filter realizations using Digital Filter block or Sum gain, and Delay blocks

Overlap-Add FFT Filter Implement overlap-add method of frequency-domain filtering

Overlap-Save FFT Filter Implement overlap-save method of frequency-domain filtering

Multirate Filters

CIC Decimation Decimate signal using Cascaded Integrator-Comb filter

CIC Interpolation Interpolate signal using Cascaded Integrator-Comb filter

Dyadic Analysis Filter Bank Decompose signals into sub-bands with smaller bandwidths and slower sample rates

Dyadic Synthesis Filter Bank Reconstruct signals from sub-bands with smaller bandwidths and slower sample rates

FIR Decimation Filter and downsample input signals

FIR Interpolation Upsample and filter input signals

FIR Rate Conversion Upsample, filter, and downsample input signals

Two-Channel Analysis Subband Filter Decompose signal into high-frequency subband and low-frequency Subband

Two-Channel Synthesis Subband Filter Reconstruct signal from high-frequency subband and low-frequency subband

Quantizers

G711 Codec Quantize narrowband speech input signals

Scalar Quantizer Decoder Convert each index value into quantized output value

7

Page 8: Matlab

Scalar Quantizer Design Start Scalar Quantizer Design Tool (SQDTool) to design scalar quantizer using Lloyd algorithm

Scalar Quantizer Encoder Encode each input value by associating it with index value of quantization region

Uniform Decoder Decode integer input into floating-point output

Uniform Encoder Quantize and encode floating-point input into integer output

Vector Quantizer Decoder Find vector quantizer codeword that corresponds to given, zero-based index value

Vector Quantizer Design Design vector quantizer using Vector Quantizer Design Tool (VQD Tool)

Vector Quantizer Encoder For given input, find index of nearest codeword based on Euclidean or weighted Euclidean distance measure

Signal Management

Buffers Change sample rate or frame rate of signals by buffering or non-buffering

Indexing Manipulate ordering of signals

Signal Attributes Inspect or modify signal attributes

Switches and Counters Perform actions when events occur

Signal Operations

Constant Ramp Generate ramp signal with length based on input dimensions

Convolution Compute convolution of two inputs

Delay Delay discrete-time input by specified number of samples or frames

Downsample Resample input at lower rate by deleting samples

Interpolation Interpolate values of real input samples

NCO Generate real or complex sinusoidal signals

Offset Truncate vectors by removing or keeping beginning or ending values

8

Page 9: Matlab

Pad Pad or truncate specified dimension(s)

Peak Finder Determine whether each value of input signal is local minimum or maximum

Repeat Resample input at higher rate by repeating values

Sample and Hold Sample and hold input signal

Triggered Signal From Workspace Import signal samples from MATLAB® workspace when triggered

Unwrap Unwrap signal phase

Upsample Resample input at higher rate by inserting zeros

Variable Fractional Delay Delay input by time-varying fractional number of sample periods

Variable Integer Delay Delay input by time-varying integer number of sample periods

Window Function Compute and/or apply window to input signal

Zero Crossing Count number of times signal crosses zero in single time step

Signal Processing Sinks

Matrix Viewer Display matrices as color images

Signal To Workspace Write simulation data to array in MATLAB workspace

Spectrum Scope Compute and display periodogram of each input signal

Time Scope Display signals generated during simulation

To Audio Device Write audio data to computer's audio device

To Multimedia File Write video frames and/or audio samples to multimedia file

To Wave File Write audio data to file in Microsoft Wave (.wav) format

Triggered To Workspace Write input sample to MATLAB workspace when triggered

Vector Scope Display vector or matrix of time-domain, frequency-domain, or user-defined data

Waterfall View vectors of data over time

9

Page 10: Matlab

Signal Processing Sources

Chirp Generate swept-frequency cosine (chirp) signal

Constant Diagonal Matrix Generate square, diagonal matrix

Discrete Impulse Generate discrete impulse

DSP Constant Generate discrete- or continuous-time constant signal

From Audio Device Read audio data from computer's audio device

From Multimedia File Read video frames and/or audio samples from compressed multimedia file

From Wave File Read audio data from Microsoft Wave (.wav) file

Identity Matrix Generate matrix with ones on main diagonal and zeros elsewhere

Multiphase Clock Generate multiple binary clock signals

N-Sample Enable Output ones or zeros for specified number of sample times

Random Source Generate randomly distributed values

Signal From Workspace Import signal from MATLAB workspace

Statistics

Autocorrelation Compute autocorrelation of vector inputs

Correlation Compute cross-correlation of two inputs

Detrend Remove linear trend from vectors

Histogram Generate histogram of input or sequence of inputs

Maximum Find maximum values in input or sequence of inputs

Mean Find mean value of input or sequence of inputs

Median Find median value of input

Minimum Find minimum values in input or sequence of inputs

RMS Compute root-mean-square value of input or sequence of inputs

10

Page 11: Matlab

Sort Sort input elements by value

Standard Deviation Find standard deviation of input or sequence of inputs

Variance Compute variance of input or sequence of inputs

Math Functions

Math Operations Use specialized math operations for signal processing applications

Matrices and Linear Algebra Work with matrices

Transforms

Analytic Signal Compute analytic signals of discrete-time inputs

Complex Cepstrum Compute complex cepstrum of input

DCT Compute discrete cosine transform (DCT) of input

DWT Compute discrete wavelet transform (DWT) of input

FFT Compute fast Fourier transform (FFT) of input

IDCT Compute inverse discrete cosine transform (IDCT) of input

IDWT Compute inverse discrete wavelet transform (IDWT) of input

IFFT Compute inverse fast Fourier transform (IFFT) of input

Inverse Short-Time FFT Recover time-domain signals by performing inverse short-time,fast Fourier transform (FFT)

Magnitude FFT Compute nonparametric estimate of spectrum using periodogram method

RESULT:

We can say that MATLAB is a right hand of designs in engineering. It is very helpful to study the various systems before practical implementation on them.

11

Page 12: Matlab

ASSIGNMENT NO. 2

OBJECT: Realizing a given block diagram having multiplier, adder/subtractor and system (discrete or continuous with given impulse response. Calculating output for given input

In Multiplier Block: DSP constant: 20 Sine Wave Amplitude: 0.1

12

Page 13: Matlab

Adder block

In Adder Block: DSP constant: 1 Sine Wave Amplitude: 1

13

Page 14: Matlab

Subtractor block

In Subtractor block:

DSP constant: 1 Sine Wave Amplitude: 1

14

Page 15: Matlab

Division block

In Division Block: Sine Wave Amplitude: 20 DSP Constant: 20

15

Page 16: Matlab

RESULT: We have realized a given block diagram having multiplier, adder/subtractor and system (discrete or continuous with given impulse response).

ASSIGNMENT NO. 3

OBJECT: To simulate the transmitter and receiver for BPSK.

16

Page 17: Matlab

PN Sequence: 1000011Sine wave: Amplitude: 1 Frequency: 10 HzCutoff frequency of low pass filter: 10Hz

17

Page 18: Matlab

2nd order filter o/p

8th order filter o/p

10th order filter o/p

RESULT: We have simulated the transmitter and receiver for BPSK.

18

Page 19: Matlab

ASSIGNMENT NO. 4

OBJECT: To generate waveform (sine, cosine, square, triangular).

Cosine Wave:

clc;clear all;close all;f=input('enter frequency');timeperiod=1/f;a=1;t=0:0.001:2;y=a*cos(2*pi*f*t);plot(t,y);

Enter frequency>> 1

Cos Wave

19

Page 20: Matlab

Sine Wave:

clc;clear all;close all;f=input('enter frequency');timeperiod=1/f;a=1;t=0:0.001:2;y=a*sin(2*pi*f*t);plot(t,y);

Enter frequency >>1

Sine Wave

20

Page 21: Matlab

Square Wave:

clc;clear all;close all;t=0:.01:2;n=input('enter n');f=input('enter frequency');y=0;for s=1:n y=y+sin(2*pi*f*(2*s-1)*t)/(pi*(2*s-1)); s=s+1;endplot(t,y);

Enter n >>200Enter frequency>> 1

Square Wave

21

Page 22: Matlab

Triangular Wave:

clc;clear all;close all;t=0:.01:2;n=input('enter n');f=input('enter frequency');y=0;for s=1:n a=[8/(pi.^2)]*[(-1).^(0.5*(s-1))/(s.^2); y=y+a*sin(2*s*pi*f*t); s=s+1;endplot(t,y);

Enter n >>200Enter frequency >>1

Triangular Wave

RESULT: We have generated various waveforms.

22

Page 23: Matlab

ASSIGNMENT NO.5

OBJECT: To simulate the following Windows at different window length. 1. Rectangular 2. Hanning 3. Hamming 4. Blackman

1. Blackman window

(a) Window length=31

23

Page 24: Matlab

(b) Window length=51

(c) Window length=101

24

Page 25: Matlab

2. Rectangular window

(a) Window length=31

(b) Window length=51

25

Page 26: Matlab

(c) Window length=101

3. Hamming window

(a) Window length=31

26

Page 27: Matlab

(b) Window length=51

(c) Window length=101

27

Page 28: Matlab

4. Hanning window

(a) Window length=31

(b) Window length=51

28

Page 29: Matlab

(c) Window length=101

RESULT: Thus we have simulated different types of windows at different length.

29

Page 30: Matlab

ASSIGNMENT NO. 6

OBJECT: To design IIR low pass butterworth filter.

IIR low pass filter

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

Output: enter the passband ripple 0.5 enter the stopband ripple 50 enter the passband frequency 1200 enter the stopband frequency 2400 enter the sampling frequency 10000

30

Page 31: Matlab

RESULT: We have designed IIR low pass butterworth filter.

31

Page 32: Matlab

ASSIGNMENT NO. 7

OBJECT: To design IIR high pass butterworth filter.

IIR high pass filter

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

Output: enter the passband ripple .5 enter the stopband ripple 50 enter the passband frequency 1200 enter the stopband frequency 2400 enter the sampling frequency 10000

32

Page 33: Matlab

RESULT: We have designed IIR high pass butterworth filter.

33

Page 34: Matlab

ASSIGNMENT NO. 8

OBJECT: To design FIR low pass and high pass filters.

FIR low pass filter

clc;clear all;close all;b=fir1(50,0.48,'low');freqz(b,1,512);

34

Page 35: Matlab

FIR high pass filter

clc;clear all;close all;b=fir1(50,0.48,'high');freqz(b,1,512);

35

Page 36: Matlab

RESULT: We have designed FIR low pass and high pass filter.

36

Page 37: Matlab

ASSIGNMENT NO. 9

OBJECT: To find the Linear convolution of two sequences.

Programming:

clc;clear all;close all;x=input('enter first sequence');y=input('enter second sequence');subplot(3,1,1);stem(x);subplot(3,1,2);stem(y);z=conv(x,y);subplot(3,1,3);stem(z);

enter first sequence>> [ 1 2 3 4]enter second sequence>> [1 2 3]

RESULT: Thus we have calculated the linear convolution.

37

Page 38: Matlab

ASSIGNMENT NO. 10

OBJECT: To find the Circular convolution of two sequences.

Programming:clc;clear all;close all;x=input('enter first sequence');y=input('enter second sequence');subplot(3,1,1);stem(x);subplot(3,1,2);stem(y);z=x*y;subplot(3,1,3);stem(z);

enter first sequence>> [ 1 2 3 0 0 ; 0 1 2 3 0 ; 0 0 1 2 3 ; 3 0 0 1 2 ; 2 3 0 0 1]enter second sequence>> [1 ; 2 ; 3 ; 4 ; 5]

RESULT: Thus we have calculated the circular convolution.

38