1.
INTRODUCTION TO MATLAB
Aim: To familiarize with MATLAB software, general functions and signal processing toolbox functions.
MATLAB stands for MATrix LABoratory produced by Mathworks Inc., USA. It is a matrix-based powerful
software package for scientific and engineering computation and visualization. Complex numerical
problems can be solved in a fraction of the time that required with other high level languages. It
provides an interactive environment with hundreds of built-in functions for technical computation,
graphics and animation. In addition to built-in functions, user can create his/her own functions.
MATLAB offers several optional toolboxes, such as signal processing, control systems, neural networks
etc. It is command driven software and has online help facility.
MATLAB has three basic windows normally: command window, graphics window and edit window.
Command window is characterized by the prompt ‘>>’. All commands and the ready to run program
filename can be typed here. Graphic window gives the display of the figures as the result of the program.
Edit window is to create program files with an extension .m.
Some important commands in MATLAB
Help List topics on which help is available
Help command name Provides help on the topic selected
Demo Runs the demo program
Who Lists variables currently in the workspace
Whos Lists variables currently in the workspace with their size
Clear Clears the workspace, all the variables are removed
Clear x,y,z Clears only variables x,y,z
Quit Quits MATLAB
Some of the frequently used built-in-functions in Signal Processing Toolbox
Filter(b.a.x) Syntax: Y = filter(b.a.x) and it filters the data in vector x with the
Filter described by vectors a and b to create the filtered data y.
Fft (x) DFT of vector x
Ifft (x) IDFT of vector x
Conv (a,b) Syntax: C = conv (a,b) and it convolves vectors a and b. The
Resulting vector is of Length, Length (a) + Length (b)-1
Deconv(b,a) Syntax: [q,r] = deconv(b,a) and it deconvolves vector q and the
Remainder in vector r such that b = conv(a,q)+r
Butter(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns
The filter coefficients in length N+1 vectors B (numerator) and A
(denominator). The coefficients are listed in descending powers of
z. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0
corresponding to half the sample rate.
Buttord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Butterworth filter that
loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and
Ws are the passband and stopband edge frequencies, Normalized from 0 to 1(where 1 corresponds to pi
rad/sec).
Cheby1(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with R decibels of peak-to-
peak ripple in the passband. CHEBY1 returns the filter coefficients in length N+1 vectors B (numerator)
and A (denominator). The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half
the sample rate.
Cheby1(N,R,Wn,’high’) designs a highpass filter.
Cheb1ord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type I filter
that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp
and Ws are the passband and stopband edge frequencies, normalized from 0 to 1 (where 1 corresponds
to pi radians/sample)
Cheby2(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with the stopband ripple R
decibels down and stopband edge frequency Wn. CHEBY2 returns the filter coefficients in length N+1
vectors B (numerator) and A. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding
to half the sample rate.
Cheb2ord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type II filter
that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies.
Abs(x) It gives the absolute value of the elements of x. When x is complex, abs(x) is the complex
modulus (magnitude) of the elements of x.
Angle(H) It returns the phase angles of a matrix with complex elements in radians.
Freqz(b,a,N) Syntax of this function is [h,w] = freqz(b,a,N) returns the N-point
Frequency vector w in radians and the N-point complex frequency response vector h of the filter b/a.
Stem(y) or stem(x,y) It plots the data sequence y as stems from the x axis terminated with circles for
the data value or at the values specified in x.
Plot(x,y) It plots vector y versus vector x. If x or y is a matrix, then the
Vector is plotted versus the rows or columns of the matrix, whichever line up.
Title(‘text’) It adds text at the top of the current axis.
Xlabel(‘text’) or ylabel(‘text’) It adds text beside the x-axis/y-axis on the current axis.