Matlab
Matlab
Matlab
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.
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 Documentation
MATLAB 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
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.
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.
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
2
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 Products
Signal 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
MATLAB
You 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.
Simulink
Simulink 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.
3
Blocks — By Category
Estimation : Perform spectrum estimates a autoregressive -modeling
Filtering : Design, create, and work with filters
Math Functions : Perform linear algebra and basic math calculations
Quantizers : Design and implement quantization schemes
Signal Management : Perform basic signal processing operations
Signal Operations : Control signal attributes, buffer signals, and index signals
Signal Processing Sinks : View or log signals
Signal Processing Sources : Generate discrete-time signals
Statistics : Perform statistical computations on signals
Transforms : Compute transforms
Estimation:
Linear Prediction:
Autocorrelation LPC Determine coefficients of Nth-order forward linear
predictors
4
Parametric Estimation
Filtering
Filter Design Toolbox Design and implement single- and multi-rate FIR and
IIR filters
5
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
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
6
Filter Designs
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
Multirate Filters
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
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
Scalar Quantizer Decoder Convert each index value into quantized output value
Scalar Quantizer Design Start Scalar Quantizer Design Tool (SQDTool) to design
scalar quantizer using Lloyd algorithm
7
Scalar Quantizer Encoder Encode each input value by associating it with index
value of quantization region
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
Signal Operations
Constant Ramp Generate ramp signal with length based on input dimensions
8
Repeat Resample input at higher rate by repeating values
Triggered Signal From Workspace Import signal samples from MATLAB® workspace when
triggered
Variable Integer Delay Delay input by time-varying integer number of sample periods
Zero Crossing Count number of times signal crosses zero in single time step
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
9
Signal Processing Sources
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
N-Sample Enable Output ones or zeros for specified number of sample times
Statistics
10
Math Functions
Transforms
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
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
Adder block
In Adder Block:
DSP constant: 1
Sine Wave Amplitude: 1
13
Subtractor block
In Subtractor block:
DSP constant: 1
Sine Wave Amplitude: 1
14
Division block
In Division Block:
Sine Wave Amplitude: 20
DSP Constant: 20
15
ASSIGNMENT NO. 3
OBJECT: To simulate the transmitter and receiver for BPSK.
PN Sequence:
1000011
Sine wave:
Amplitude: 1
Frequency: 10 Hz
Cutoff frequency of low pass filter: 10Hz
16
2nd order filter o/p
17
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
18
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);
Sine Wave
19
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;
end
plot(t,y);
Enter n >>200
Enter frequency>> 1
Square Wave
20
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;
end
plot(t,y);
Enter n >>200
Enter frequency >>1
Triangular Wave
21
ASSIGNMENT NO.5
OBJECT: To simulate the following Windows at different window
length.
1. Rectangular
2. Hanning
3. Hamming
4. Blackman
1. Blackman window
22
(b) Window length=51
23
2. Rectangular window
24
(c) Window length=101
3. Hamming window
(a) Window length=31
25
(b) Window length=51
26
4. Hanning window
(a) Window length=31
27
(c) Window length=101
28
ASSIGNMENT NO. 6
OBJECT: To design IIR low pass butterworth 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--->');
29
RESULT: We have designed IIR low pass butterworth filter.
30
ASSIGNMENT NO. 7
OBJECT: To design IIR high pass butterworth 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--->');
31
RESULT: We have designed IIR high pass butterworth filter.
32
ASSIGNMENT NO. 8
OBJECT: To design FIR low pass and high pass filters.
clc;
clear all;
close all;
b=fir1(50,0.48,'low');
freqz(b,1,512);
33
FIR high pass filter
clc;
clear all;
close all;
b=fir1(50,0.48,'high');
freqz(b,1,512);
34
RESULT: We have designed FIR low pass and high pass filter.
35
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);
36
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);
37