1
OBJECTIVES OF THE LAB
----------------------------------------------------------------------
Matlab will be used extensively in all the succeeding labs. The goal of this first lab is to gain
familiarity with Matlab and build some basic skills in the Matlab language. Some specific topics
covered in this lab are:
• Introduction to Matlab
• Matlab Environment
• Matlab Help
• Variable arithmetic
• Built in Mathematical Functions
• Input and display
• Timing functions
• Introduction to M-files
----------------------------------------------------------------------
1.1 WHAT IS MATLAB?
Double click on the MATLAB icon to launch and a command window will appear with the
prompt:
>>
You are now in MATLAB. From this point on, individual MATLAB commands may be given at
the program prompt. They will be processed when you hit the <ENTER> key. The following
figure shows the screenshot of matlab.
1.3 LEAVING MATLAB
Online help is available from the MATLAB prompt, both generally (listing all available
commands).
>> help
[a long list of help topics follows]
and for specific commands:
>> help command_name
If you want to search for all the commands related to some particular functionality, use
keyword lookfor followed by a keyword that explains the functionality.
>>lookfor convolution
1.5 VARIABLES
MATLAB has built-in variables like pi, eps, and ans. You can learn their values from the
MATLAB interpreter.
>> eps
eps =
2.2204e-16
>> pi
ans =
3.1416
At any time you want to know the active variables you can use who:
>> who
Your variables are:
ans x y
To save the value of the variable "x" to a plain text file named "x.value" use
>> save x.value x -ascii
To save all variables in a file named mysession.mat, in reloadable format, use
>> save mysession
To restore the session, use
>> load mysession
MATLAB uses some fairly standard notation. More than one command may be entered on a
single line, if they are separated by commas.
>> 2+3;
>> 3*4, 4^2;
Powers are performed before division and multiplication which are done before subtraction and
addition. For example
>> 2+3*4^2;
generates
ans = 50.
That is:
2+3*4^2
==> 2 + 3*4^2 <== exponent has the highest precedence
==> 2 + 3*16 <== then multiplication operator
==> 2 + 48 <== then addition operator
==> 50
1.6.1 Double Precision Arithmetic
All arithmetic is done to double precisions, which for 32 bit machines is about 16
decimal digits of accuracy. Normally the results will be displayed in a shorter form.
>> a = sqrt(2)
a=
1.4142
>> format long, b=sqrt(2)
b=
1.41421356237310
>> format short
1.6.2 Command-Line Editing
The arrow keys allow "command-line editing," which cuts down on the amount of typing
required, and allows easy error correction. Press the "up" arrow, and add "/2." What will this
produce?
>> 2+3*4^2/2
Parentheses may be used to group terms, or to make them more readable. For example:
>> (2 + 3*4^2)/2
Generates ans=25
MATLAB has a platter of built-in functions for mathematical and scientific computations. Here
is a summary of relevant functions.
Function Meaning Example
======================================================
sin sine sin(pi) = 0.0
cos cosine cos(pi) = 1.0
tan tangent tan(pi/4) = 1.0
asin arcsine asin(pi/2)= 1.0
acos arccosine acos(pi/2)= 0.0
atan arctangent atan(pi/4)= 1.0
exp exponential exp(1.0) = 2.7183
log natural logarithm log(2.7183) = 1.0
log10 logarithm base 10 log10(100.0) = 2.0
======================================================
The arguments to trigonometric functions are given in radians.
Example: Let's verify that
sin(x)^2 + cos(x)^2 = 1.0
for arbitrary x. The MATLAB code is:
>> x = pi/3;
>> sin(x)^2 + cos(x)^2 - 1.0
ans =
0
1.7 TIMING COMMANDS
Timing functions may be required to determine the time taken by a command to execute or an
operation to complete. Several commands are available to accomplish it:
1.7.1 Clock
CLOCK returns current date and time as date vector. CLOCK returns a six element date vector
containing the current time and date in decimal form:
CLOCK = [year month day hour minute seconds]
The first five elements are integers. The second’s element is accurate to several digits beyond the
decimal point. FIX(CLOCK) rounds to integer display format.
1.7.2 Etime
Gives the user the prompt in the text string and then waits for the input from the keyboard.The
input can be any MATLAB expression, which is evaluated, using the variables in the current
workspace, and the result returned in R. If the user presses the return key without entering
anything, INPUT returns an empty matrix.
5
1.8.2 DISP
DISP Display array, without printing the array name. In all other way it’s the same as
leaving the semicolon off an expression except that empty arrays don’t display
DISP(‘string’) is another variation of the same function that is used to display a string on the
command prompt.
Example:
>> disp('I am using MATLAB 7.0')
I am using MATLAB 7.0
1.9 M-Files
Typing errors are time-consuming to fix if you are working in the command window because
you need to retype all or part of the program. Even if you do not make any mistakes, all of your
work may be lost if you inadvertently quit MATLAB. To preserve large sets of commands,
you can store them in a special type of file called an M-file. MATLAB supports two types of M-
files: script and function M-files. To hold a large collection of commands, we use a script M-
file. The function M-file is discussed in coming lab. The script file has a '.m' extension and is
referred to as an M-file (for example, myfile.m myfuncion.m, etc.). The commands in the script
file can then be executed by typing the file name without its extension in the command window.
Commands in a script utilize and modify the contents of the current workspace. It is possible to
embed comments in a script file.
To make a script M-file, you need to open a file using the built-in MATLAB editor. There are
two ways to accomplish it:
1. From file menu, click NEW
2. Type edit on command line
---------------------------TASK 1----------------------------
Create an m-file and write a program for calculating area of a circle. Try out several other
programs of similar computation.
---------------------------TASK 2----------------------------
Create an m-file to get 10 numbers from user and generate the square of those numbers.
LAB NO. 2
MATLAB works with essentially only one kind of object, a rectangular numerical matrix
possibly, with complex entries. Every MATLAB variable refers to a matrix [a number is a 1 by 1
matrix]. In some situations, 1-by-1 matrices are interpreted as scalars, and matrices with only one
row or one column are interpreted as vectors.
A matrix is a rectangular array of numbers. For example:
[3692
1485
2875
1 4 2 3]
Depending on the specific values of coefficients in matrices A and B, there may be: (a) no
solutions to A.X = B, (b) a unique solution to A.X = B, or (c) an infinite number of solutions to
A.X = B.
In this particular case, however, the solution matrix
[1]
X= [2]
[3]
makes the right-hand side of the matrix equations (i.e., A.X) equal the left-hand side of the
matrix equations (i.e., matrix B).
The matrix element located in the i-th row and j-th column of a is referred to in the usual way:
>> A(1,2), A(2,3)
ans =
2
ans =
6
It's very easy to modify matrices:
>> A(2,3) = 10;
MATLAB has many types of matrices which are built into the system e.g.
Function Description
===============================================
diag returns diagonal M.E. as vector
eye identity matrix
hilb Hilbert matrix
magic magic square
ones matrix of ones
rand randomly generated matrix
triu upper triangular part of a matrix
tril lower triangular part of a matrix
zeros matrix of zeros
===============================================
Here are some examples:
i. Matrices of Random Entries: A 3 by 3 matrix with random entries is produced by
typing
>> rand(3)
ans =
0.0470 0.9347 0.8310
0.6789 0.3835 0.0346
0.6793 0.5194 0.0535
General m-by-n matrices of random entries are generated with
>> rand(m,n);
v. Diagonal Matrices: If x is a vector, diag(x) is the diagonal matrix with x down the
diagonal.
If A is a square matrix, then diag(A) is a vector consisting of the diagonal of A. What is
diag(diag(A))? Try it.
These matrix operations apply of course to scalars (1-by-1matrices) as well . if the sizes of the
matrices are incompatible for the matrix operation, an error message will result ,except in the
case of the scalar-matrix operations(for addition , subtraction and division as well as
multiplication)in which case each entry of the matrix is operated on by the scalar.
1.2.1 Matrix Transpose
Let matrix "A" have m rows and n columns, and matrix "B" have p rows and q columns. The
matrix sum "A + B" is defined only when m equals p and n equals q, the result is a n-by-m
matrix having the element-by-element sum of components in A and B.
For example:
>> A = [ 2 3; 4 5.0; 6 7];
>> B = [ 1 -2; 3 6.5; 10 -45];
>> A+B
Ans=
3.0000 1.0000
7.0000 11.5000
16.0000 -38.0000
Matrix multiplication requires that the sizes match. If they don't, an error message is generated.
>> A*B, B*A; <== results into error as inner matrix dimensions doesn’t agrees
>> B'*A;
>> A*A', A'*A;
>> B'*B, B*B';
Scalars multiply matrices as expected, and matrices may be added in the usual way (both are
done "element by element”):
>> 2*A, A/4;
>> A + [b,b,b]; <== results into error as inner matrix dimensions doesn’t agrees
Example:
We can use matrix multiplication to check the "magic" property of magic squares.
>> A = magic(5);
>> b = ones(5,1);
>> A*b; <== (5x1) matrix containing row sums.
>> v = ones(1,5);
>> v*A; <== (1x5) matrix containing column sums.
There is a function to determine if a matrix has at least one nonzero entry, any, as well as a
function to determine if all the entries are nonzero, all.
>> A = zeros(1,4)
>> any(A)
>> D = ones(1,4)
>> any(D)
>> all(A)
1 4 8 5
2 8 7 5
1 4 2 3]
---------------------------TASK 2-----------------------------
Generate two 10000 sampled random discrete time signals (1 dimensional) using rand() function
i.e. rand(1,10000). Write a program to add the two signals together using simple vector addition.
Determine the time required for addition using tic, toc pair or etime function.
1.3 SUB-MATRICES
Colon notation can be used to generate vectors. A very common use of the colon notation is to
extract rows, or columns, as a sort of "wild-card" operator which produces a default list. For
example,
A(1:4,3) is the column vector consisting of the first four entries of the third column of A .
A(:,3) is the third column of A. A colon by itself denotes an entire row or column.
A(1:4,:) is the first four rows of A.
---------------------------TASK 3-------------------------
Create two matrices i.e. A consisting of 1 through 6 & 12 through 7, while B consisting of 6
through 1 & 7 through 12. Perform the following operations: A+B,
A-B, A.*B, A./B, A.^2, 1./A, A/2, A+1. Take matrices of ur choice and perform the above
mentioned operations on them.
---------------------------TASK 4-------------------------
MATLAB has functions to round floating point numbers to integers. These are round, fix, ceil,
and floor. Test how these functions work. Determine the output of the following:
>> f = [-.5 .1 .5]
>> round(f)
>> fix(f)
>> ceil(f)
>> floor(f)
>> sum(f)
>> prod(f)
t=0:0.1:1;
x=exp(-10.*t);
subplot(231);
plot(t,x);
xlabel('time')
ylabel('amplitude')
title('DSP 1 ')
grid on
subplot(232);
plot(t,x,'ro');
xlabel('time')
ylabel('amplitude')
title(' DSP 2')
grid on
subplot(233);
stem(t,x,'g');
xlabel('time')
ylabel('amplitude')
title(' DSP 3')
grid on
subplot(234);
stem(t,x,'f');
xlabel('time')
ylabel('amplitude')
title(' DSP 4')
grid on
subplot(235);
stem(t,x,'o')
xlabel('time')
ylabel('amplitude')
title(' DSP 5 ')
grid on
subplot(236);
stem(t,x,'f')
e=0:pi/5:5*pi;
plot3(sin(t),cos(t),t)
xlabel('time')
ylabel('amplitude')
title(' DSP 6')
grid on
---------------------------TASK 5-------------------------
Generate a plot e^0.1y.sin(wy)
W=15 rad/sec and 0<=y<=15
With an increment of 0.1 .keep the range of axis (0,20) label the graph.
w=15;
y=0:0.1:15;
signal=exp(-0.7.*y).*(sin(w*y));
plot(y,signal);
axis([0 20 -1 1])
grid on
title('Lab task')
xlabel('time')
ylabel('amplitude')
LAB NO. 3
OBJECTIVE OF THE LAB
----------------------------------------------------------------------
In this lab, we will get an understanding of the following topics:
• Making Functions
• Control Structures
• Relational Constructs
• Logical Constructs
• Branching Constructs
• Looping constructs
•Discrete signal representation
•Matlab graphics
----------------------------------------------------------------------
1.1 MAKING FUNCTIONS
Save the program with the same name adv, go back to command window, type the following
>> help addv
-------------------------------------------------
This function takes two values as input,
finds its sum, & displays the result.
inputs: x & y
output: z
Example: addv(3,6)
Result: z=9
--------------------------------------------------
SCRIPT VS FUNCTION
• A script is simply a collection of Matlab commands in an m-file. Upon typing the name of
the file (without the extension), those commands are executed as if they had been entered
at the keyboard.
Functions are used to create user-defined matlab commands.
• A script can have any name.
A function file is stored with the name specified after keyword function.
• The commands in the script can refer to the variables already defined in Matlab, which are
said to be in the global workspace.
When a function is invoked, Matlab creates a local workspace. The commands in the
function cannot refer to variables from the global (interactive) workspace
Unless they are passed as inputs.
---------------------------TASK 1----------------------------
Construct a function in M-file by the name of greater(x,y), which will take two inputs from the
user, finds the value that is greater among the two and then displays it.
Similarly create the functions of “average” and “factorial”
Here the condition is a logical expression that will evaluate to either true or false
(i.e., with values 1 or 0). When the logical expression evaluates to 0, the program
control moves on to the next program construction. You should keep in mind that
MATLAB regards A==B and A<=B as functions with values 0 or 1.
Example:
>> a = 1;
>> b = 2;
>> if a < b
c = 3;
end;
>> c
c=
3
----------------------------TASK 2---------------------------
Find for integer 0 < a ≤ 10, the values of C, defined as follows:
C= 5ab, 0<a<=5
C= ab, 5<a<=10
where b = 15.
Example: MATLAB will allow you to put any vector in place of the vector 1:n in this
construction. Thus the construction
>> for i = [2,4,5,6,10]
<program>
end
is perfectly legitimate.
In this case program will execute 5 times and the values for the variable i during
execution are successively, 2,4,5,6,10.
----------------------------TASK 3----------------------------
Add the following two matrices using for loop.
[5 12 3 [2 1 9
9 6 5 10 5 6
2 2 1] 3 4 2]
ii. While Loops
>> n = [-3:1:3]
n=
-3 -2 -1 0 1 2 3
>> x = [1 -1 0 2 1 4 6]
x=
1 -1 0 2 1 4 6
----------------------------TASK 4----------------------------
1.4 GRAPHICS
Two- and three-dimensional MATLAB graphs can be given titles, have their axes
labeled, and have text placed within the graph. The basic functions are:
Function Description
============================================================================
plot(x,y) plots y vs x
plot(x,y1,x,y2,x,y3) plots y1, y2 and y3 vs x on the same graph
stem(x) plots x and draws a vertical line at each
datapoint to the horizontal axis
xlabel('x axis label') labels x axis
ylabel('y axis label') labels y axis
title ('title of plot') puts a title on the plot
gtext('text') activates the use of the mouse to position a
crosshair on the graph, at which point the
'text' will be placed when any key is pressed.
zoom allows zoom IN/OUT using the mouse cursor
grid draws a grid on the graph area
print filename.ps saves the plot as a black and white postscript
file
Shg brings the current figure window forward.
CLF clears current figure.
Another way is with hold. The command hold freezes the current graphics screen
so that subsequent plots are superimposed on it. Entering hold again releases the
``hold.''
x = 0:.01:2*pi;
y1=sin(x);
y2=sin(2*x);
y3=sin(4*x);
plot(x,y1);
hold on;
plot(x,y2);
plot(x,y3);
xlabel('Time (sec)');
ylabel('Amplitude (A)');
output:
Enter the first discrete time signal
[3 5 1 0 2]
Enter the second discrete time signal
[1 1 3 2 1]
------------------------------TASK 6 ---------------------------
Make two separate functions for signal addition and multiplication. The functions
should take the signals as input arguments and return the resultant signal. In the
main program, get the signals from user, call the functions for signal addition
and multiplication, and plot the original signals as well as the resultant signals.
LAB NO.4
OBJECTIVES OF THE LAB
----------------------------------------------------------------------
In this lab, we will cover the following topics:
Gain familiarity with Complex Numbers
Built in functions related to complex numbers
phasors
Plotting real & imaginary parts of a function
Plot complex exponential signal
----------------------------------------------------------------------
1. COMPLEX NUMBERS
A complex number z is an ordered pair (x, y) of real numbers. Complex numbers can be
represented in rectangular form as z = x + iy, which is the vector in two-dimensional
plane. The horizontal coordinate x is called the real part of z and can be represented as
x = Re {z}, while the vertical coordinate y is called the imaginary part of z and
represented as y = Imag {z}. That is:
z = (x, y)
= x + iy
= Re {x} + i Imag {x}
Another way to represent a complex number is in polar form. In polar form, the vector is
defined by its length (r) or magnitude (|z|) and its direction (θ). A rectangular form can
be converted into polar form using formulas:
|z| = r = (x^2 + y^2)½
θ = arctan (y/x)
z = r e^j θ
where e^j θ = cos θ + i sin θ,and known as the Euler’s formula.
Example
To define the complex number, for instance, z = (3, 4) in matlab write in matlab editor
>> z = 3 + 4i
z=
3.0000 + 4.0000i
Example
To find the real and imaginary parts of the complex number, write
>> x = real(z)
x=
3
>> y = imag(z)
y=
4
Example
To find the length and direction of z, write
>> r = abs(z)
r=
5
>> θ = angle(z)
θ=
0.9273
Example
>> zx = conj(z)
zx =
3.0000 – 4.0000i
Example
To find all the information about a complex number, use the zprint function, i.e.
>> zprint(z)
Z = X + jY Magnitude Phase Ph/pi Ph(deg)
3 4 5 0.927 0.295 53.13
Example
Example
To plot the circular representation of complex number, ucplot function can be used. It
takes the radius of circle as first argument, complex number as second argument and
any plotting option as third argument. For instance, to draw z1 = 2 + 3i as a dottedgreen
circle with radius r = 2 in matlab, write in matlab
>> huc = ucplot( 2, z1 , ':g');
------------------------------TASK 1----------------------------
Define z1 = -1+j0.3 and z2 = 0.8+j0.7. Enter these in Matlab and plot them with
zvect, and print them with zprint.
------------------------------TASK 2----------------------------
Compute the conjugate z¤ and the inverse 1/z for both z1 and z2 and plot the
results. Display the results numerically with zprint.
------------------------------TASK 3----------------------------
Compute z1 +z2 and plot. Use zcat to show the sum as vectors head-to-tail. Use
zprint to display the results numerically.
------------------------------TASK 4----------------------------
Compute z1z2 and z1/z2 and plot. Use the zvect plot function to show how the
angles of z1 and z2 determine the angles of the product and quotient. Use zprint
to display the results numerically.
Example
clc
clear all
close all
n = 0:1/10:10;
k = 5;
a = pi/2;
x = k * exp(a*n*i);
------------------------------TASK 7----------------------------
Multiply the two discrete signals x1=5exp^(i*n*pi/4) and x2= a^n (use point-by-point
multiplication of the two signals). Plot the real as well as the exponential parts for
0<a<1 and a>1.
------------------------------TASK 8----------------------------
a) Generate the signal x(t) = Aej(wt+𝜋) for A = 3,𝜋= -0.4, and w=2𝜋(1250). Take
a range for t that will cover 2 or 3 periods.
b) Plot the real part versus t and the imaginary part versus t. Use subplot(2,1,i) to
put both plots in the same window.
DSP LAB # 5
LAB NO. 5
OBJECTIVES OF THE LAB
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
In this lab, we will cover the following topics:
Beat Notes
Amplitude Modulation
Applications of Fourier Series
Synthesis of Square wave
Synthesis of Triangular wave
Frequency spectrum of a signal
Frequency Modulated Signal
Chirp Signal
Modeling Chirp Signal in Simulink
Spectrogram
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
5.1 BEAT NOTES
When two sinusoidal signals with different frequencies are multiplied, a beat note is produced.
To fulfill
the spectrum representation, the resultant signal is expressed as an additive linear combination of
complex exponential signals. For instance, consider a beat signal as the product of two sinusoids
x(t) = sin(10πt) cos(πt)
= ½ cos(11πt – π/2) + ½ cos(9πt – π/2)
Or in other words, beat note can be produced by adding two sinusoids with nearly identical
frequencies,
i.e.
x(t) = cos(2πf1t) + cos(2πf2t) 1)
where f1 = fc – fd � first frequency
f2 = fc + fd � second frequency
fc = ½ (f1 + f2) � center frequency
fd = ½ (f1 ‐ f2) � deviation or difference frequency
And, thus
x(t) = sin(2πfdt) cos(2πfct) 2)
= ½ cos(2π(fc – fd)t) + ½ cos(2π(fc + fd)t)
= ½ cos(2πf1t) + ½ cos(2πf2t) 3)
Example
To implement the beat note for fc = 200, & fd = 20,
consider the following matlab code:
Modify the above code in such a way that the resultant beat signal & its envelope both are
shown.
--------------------------TASK 2--------------------------
Write the matlab code that produces a beat signal along with its envelope for frequencies f1 =
191 hertz and f2 = 209 hertz.
---------------------------TASK 3-------------------------
Modify the above code in such a way that the resultant AM signal & its envelope both is shown.
---------------------------TASK 4-------------------------
Write the matlab code that produces an AM signal along with its envelope for frequencies f1 =
191 hertz and f2 = 209 hertz.
Example
clear
clc
t=0:0.0001:8;
ff=0.5;
y = (4/pi)*sin(2*pi*ff*t);
% COMPLEX AMPLITUDE = (4/(j*pi*k))
for k = 3:2:7
fh=k*ff;
x = (4/(k*pi))*sin(2*pi*fh*t);
y=y+x;
end
plot(t,y,'linewidth',1.5);
title('A square wave with harmonics 1st, 3rd, 5th, and 7th');
xlabel('Time');
ylabel('Amplitude')
Example
clear
clc
t=0:0.0001:8;
ff=0.5;
y = (4/pi)*sin(2*pi*ff*t);
% COMPLEX AMPLITUDE = (4/(j*pi*k))
for k = 3:2:17
fh=k*ff;
x = (4/(k*pi))*sin(2*pi*fh*t);
y=y+x;
end
plot(t,y,'linewidth',1.5);
title('A square wave with harmonics 1st‐17th);
xlabel('Time');
ylabel('Amplitude');
Example
t=0:0.0001:8;
ff=0.5;
y = (4/pi)*sin(2*pi*ff*t);
% COMPLEX AMPLITUDE = (4/(j*pi*k))
for k = 3:2:55
fh=k*ff;
x = (4/(k*pi))*sin(2*pi*fh*t);
y=y+x;
end
plot(t,y,'linewidth',1.5);
title('A square wave with harmonics 1st to 27th');
xlabel('Time');
ylabel('Amplitude');
5.4 SYNTHESIS OF A TRIANGULAR WAVE
---------------------------TASK 5 -------------------------
EXAMPLE:
To plot spectrum diagram which gives the frequency content of a signal x(t)
x(t) = 14 cos(200*pi*t -pi/3)
Fs = 1000;
t = 0:1/Fs:1-(1/Fs);
x = 14*cos(200*pi*t-pi/3);
xdft = (1/length(x))*fft(x);
freq = -500:(Fs/length(x)):500-(Fs/length(x));
plot(freq,abs(fftshift(xdft)));
---------------------------TASK 6-------------------------
(i) Plot the spectrum of the given AM signal and beat signal.
(ii) plot the spectrum of square signal whose Fourier series coefficients are
= 0 k= even numbers
With fo= 25 hz
(iii) Similarly plot the spectrum of triangular signal having fundamental frequency, fo =25 hz
5.6 FREQUENCY MODULATED SIGNALS:
---------------------------TASK 7----------------------------
(a) Determine the range of frequencies (in hertz) that will be synthesized by above mentioned
Matlab script. What are the minimum and maximum frequencies that will be heard? Listen to the
signal to verify that it has the expected frequency content.
(b) Use the code provided in part (a) to help you write a Matlab function that will synthesize a
“chirp" signal according to the following comments:
(c) Generate a chirp sound to match the frequency range of the chirp in part (a). Listen to
the chirp using the sound function. Also, compute the spectrogram of your chirp using the
Matlab function: spectrogram
---------------------------TASK 8 ----------------------
Synthesize a frequency sweep from f1=3hz to f2=30 hz over the time interval t=0 to T=1.8 sec
Plot the signal and also show the frequency –time relation using function spectrogram.
We can model chirp signal by using blocks of dsptool box in simulink or we can also
generate the chirp signal using the built in block of chirp signal generator.
OUTPUT:
MODELING USING DSPTOOL BOX IN SIMULINK
5.8 SPECTROGRAM:
It is often useful to think of signals in terms of their spectra. A signal's spectrum is a
representation of the frequencies present in the signal. For a constant frequency sinusoid the
spectrum consists of two spikes, one at 2Ψf0, the other at ¡2Ψf0. For more complicated signals
the spectra may be very interesting and, in the case of FM, the spectrum is considered to be
time‐varying. One way to represent the time‐varying spectrum of a signal is the spectrogram
(see Chapter 3 in the text). A spectrogram is found by estimating the frequency content in short
sections of the signal. The magnitude of the spectrum over individual sections is plotted as
intensity or color on a two‐dimensional plot versus frequency and time.
A beat note signal may be viewed as a single frequency signal whose amplitude varies with
time, or as two signals with different constant frequencies.
---------------------------TASK 9 ----------------------------
Create and plot a beat signal with
(i) f¢ = 32 Hz
(ii) Tdur = 0:26 sec
(iii) fs = 8000 Hz,
(iv) f0 = 2000 Hz
Find the spectrogram using the commands:
spectrogram(x); colormap(1‐gray(256)).
LAB NO. 6 :
Example:
t = 0:0.0005:1;
f = 13;
xa = cos(2*pi*f*t);
subplot(2,1,1)
plot(t,xa);
grid
xlabel('Time, msec');
ylabel('Amplitude');
title('Continuous-time signal x(t)');
axis([0 1 -1.2 1.2])
subplot(2,1,2);
Example
t=0:0.001:1;
f1=2*cos(2*pi*1*t);
f2=2*cos(2*pi*11*t);
n=0:0.1:1;
y1=2*cos(2*pi*1*n);
y2=2*cos(2*pi*11*n);
subplot(2,2,1)
plot(t,f1);
xlabel('Time');
ylabel('Amplitude');
title('Continous time wave of frequency 1 Hz');
grid;
subplot(2,2,2)
plot(t,f2);
xlabel('Time');
ylabel('Amplitude');
title('Continous time wave of frequency 11 Hz');
grid;
subplot(2,2,3)
stem(y1);
xlabel('sample number');
ylabel('Amplitude');
title('Sampling 1 Hz signal at 10 Hz');
grid;
subplot(2,2,4)
stem(y2);
xlabel('sample number');
ylabel('Amplitude');
title('Sampling 11 Hz signal at 10 Hz');
grid;
6.3 FOLDING
In signal processing, Folding refers to an effect that causes change in the frequency and phase of
signal when reconstructed after sampling.
Folding uses the property cos (q) = cos (-q).
This causes the frequencies from 0.5 fs to fs become a mirror image of frequencies of 0 to 0.5fs.
fapparent = fs – fo, where fs>fo>0.5fs
Example
t=0:0.001:1;
f1=2*cos(2*pi*4*t);
f2=2*cos(2*pi*6*t);
n=0:0.1:1;
y1=2*cos(2*pi*4*n);
y2=2*cos(2*pi*6*n);
subplot(2,2,1)
plot(t,f1);
xlabel('Time');
ylabel('Amplitude');
title('Continous time wave of frequency 4 Hz');
grid;
subplot(2,2,2)
plot(t,f2);
xlabel('Time');
ylabel('Amplitude');
title('Continous time wave of frequency 6 Hz');
grid;
subplot(2,2,3)
stem(y1);
xlabel ('sample number');
ylabel('Amplitude');
title('Sampling 4 Hz signal at 10 Hz');
grid;
subplot(2,2,4)
stem(y2);
xlabel('sample number');
ylabel('Amplitude');
title('Sampling 6 Hz signal at 10 Hz');
grid;
---------------------------TASK 2-------------------------
n= ‐10:10;
%unit step
x1=[zeros(1,10) ones(1,11)];
stem(n,x1,'filled');
xlabel('sample #');
ylabel('signal amplitude');
title('Unit step');
axis([‐10 10 ‐1 2]);
----------------------------------------TASK 1-----------------------------------
Plot the signum sequence. It can be defined as:
Sign(n)= 1, for n>0
-1, for n<0
0, for n=0
1) Signal Shifting
clc
clear all
close all
n=0:0.002:4;
x=sin(2*pi*1*n);
subplot(2,1,1);
plot(n,x,'linewidth',2);
title('Original Signal');
xlabel('Time');
ylabel('Signal Amplitude');
axis([‐3 3 ‐1 1]);
grid;
subplot(2,1,2);
plot(n‐1,x,'linewidth',2);
title('Advanced signal');
xlabel('Time');
ylabel('Signal Amplitude');
axis([‐3 3 ‐1 1]);
grid
-------------------------------------TASK 2---------------------------------
Delay the above signal by 1 sec. Plot both the delayed & original signal on the same figure
2) Amplitude Scaling
clear
n=1:7;
x=[1 2 2 3 2 2 1];
subplot(2,1,1);
stem(n,x, 'filled');
title('Original signal');
xlabel('Time index');
ylabel('Signal Amplitude');
axis([1 7 0 4]);
grid;
S=2;
subplot(2,1,2);
stem(n,S*x, 'filled');
title('Amplitude Scaled signal');
xlabel('Time index');
ylabel('Signal Amplitude');
axis([1 7 0 8]);
grid;
--------------------------------------TASK 3 ------------------------------
Scale the continuous-time sinusoid by a factor of 2.
4) Amplitude Clipping
clear
x=[3 4 4 2 1 ‐4 4 ‐2];
len=length(x);
y=x;
hi=3;
lo=‐3;
for i=1:len
if(y(i)>hi)
y(i)=hi;
elseif(y(i)<lo)
y(i)=lo;
end
end
subplot(2,1,1);
stem(x,'filled');
title('original signal');
xlabel('Sample number');
ylabel('Signal Amplitude');
subplot(2,1,2);
stem(y,'filled');
title('Clipped Signal');
xlabel('Sample number');
ylabel('Signal Amplitude');
5) Signal Replication
clear
x=[1 2 3 2 1];
y=[x x x x];
subplot(2,1,1);
stem(x,'filled');
title('Original Signal');
xlabel('Sample Number');
ylabel('Signal Amplitude');
axis([1 20 0 3]);
grid;
subplot(2,1,2);
stem(y,'filled');
title('Replicated Signal');
xlabel('Sample Number');
ylabel('Signal Amplitude');
axis([1 20 0 3]);
grid;
7.3 DISCRETE TIME SYSTEMS:
There are different ways to characterize discrete‐time systems including difference equation,
impulse response, transfer function, and frequency response. We are considering here only
difference equation.
Difference Equation
A discrete‐time system is characterized by the following general form difference equation
y(n) + a1y1(n-1) + a2y2(n-2) + … + aNyN(n-N) = b0x0(n) + b1x1(n-1) + …+ bMxM(n-M)
Where
� x(n) and y(n) are input and output, respectively.
� Finite integers M and N represent the maximum delays in the input and output respectively.
� The constants ai and bi are called the filter coefficients.
Difference equation can be implemented in Matlab as follow:
y = filter (b,a,x)
Which takes the input signal in vector x and filter coefficient a and b. The Vector B constitutes
the feed forward filter coefficients and vector A constitutes the feed‐backward filter
coefficients. In case of FIR filters, the feed‐backward filter coefficient consists of a single 1.
Example
y (n) + 2y(n‐1) + 3y(n‐2) = x(n) + 3x(n‐1) + x(n‐2)
A = coefficients of y(n) = [1 2 3]
B = coefficients of x(n) = [1 3 1]
X = input sequence = [1 2 3 4 5 6 ]
Program
A = [1 2 3];
B = [1 3 1];
X = [1 2 3 4 5 6];
Y =filter (B, A, X)
Output :
Y=
1 3 1 4 9 ‐5
--------------------------------TASK 5-----------------------------------
Given the following difference equation and input signal, calculate the output.
� 5y(n) = ‐4x(n) + x(n‐1) + 6x(n‐3)
� X = input sequence = [1 3 5 7 9]
Example
clc
clear
b = [1 2 3 4 5 4 3 2 1];
a = 1;
x = cos(0.2*pi*[0:20]);
y = filter(b,a, x);
figure;
subplot(2,1,1);
stem (x);
title('Discrete Filter Input x[n]');
xlabel('index, n');
ylabel('Value, x[n]');
axis([0 21 ‐1 1]);
grid;
subplot(2,1,2);
stem(y, 'r');
title('Discrete Filter Output y[n]');
xlabel('index, n');
ylabel('Value, y[n]');
axis([0 21 ‐20 20]);
grid;
7.3.2 IMPULSE RESPONSE:
0.9
0.8
Matlab code
0.7
a=[1 0 -0.268];
b=[0.634 0 0.634]; 0.6
x=[1 zeros(1,31)];
y=filter(b,a,x); 0.5
y=stem(y);
grid; 0.4
0.3
0.2
0.1
0
0 5 10 15 20 25 30 35
Impulse Response of: Y[n]-0.268y [n-2] =0.634x[n] +0.634x [n-2]With
IMPZ function Impulse Response
0.9
0.8
Matlab code
0.7
a=[1 0 -0.268];
0.6
b=[0.634 0 0.634]
x=[1 zeros(1,31)];
Amplitude
y=filter(b,a,x);%impulse 0.5
response
y=stem(y); 0.4
grid
0.3
hold on;
impz(b,a);
0.2
0.1
0
0 2 4 6 8 10 12 14
n (samples)
---------------------------------TASK 6------------------------------------------
Determine the Impulse response of
Y(n)=0.5x(n)+0.27x(n-1)+0.77(n-2)
clear
n=‐3:7;
% input signal
x=[0 0 0 2 4 6 4 2 0 0 0];
% filter coefficients
b=[1/3 1/3 1/3]; %feedforward filter coefficeints
a=1; %feedback filter coefficients
% output signal
y=filter(b,a,x);
figure;
subplot(2,1,1);
stem(n,x, 'filled');
xlabel('sample number');
ylabel('signal amplitude');
title('origianl signal');
grid;
subplot(2,1,2);
stem(n,y, 'filled');
xlabel('sample number');
ylabel('signal amplitude');
title('Result of 3‐point averager: y[n]=(x[n]+x[n‐1]+x[n‐2])/3');
grid;
------------------------------------TASK 7 ---------------------------------
Modify above program to implement:
1. A 3‐point non‐causal averager
2. A centralized average
-------------------------------------TASK 8----------------------------------
A non‐recursive discrete‐time system has filter coefficients {1, ‐2, 3, 2}. An input signal (shown
in Fig) is applied to the system. Determine the discrete‐time output of the filtering. Write code
to plot the original signal as well as the output on two subplots of the same figure.
7.4.1 ILLUSTRATION OF FIR FILTERING:
Example
n=0:40;
% input signal
x=(1.02).^n + 0.5*cos(2*pi*n/8 + pi/4);
% filter coefficients
b1=[1/3 1/3 1/3];
a1=1;
% plot of original signal
Figure;
subplot(2,1,1);
stem(n,x, 'filled');
title('input signal');
xlabel('sample number');
ylabel('signal amplitude');
grid;
% output of 3‐ point filtering
y1=filter(b1,a1,x);
subplot(2,1,2);
stem(n,y1, 'filled');
title('output of 3‐point filtering');
xlabel('sample number');
ylabel('signal amplitude');
grid;
-----------------------------------TASK 9 ---------------------------------
Develop a causal FIR filter that averages five samples of the input signal
x[n]= 2δ[n] + 5δ[n‐1] + 8δ[n‐2] + 4δ[n‐3] + 3δ[n‐4]
-----------------------------------TASK 10 ---------------------------------
Consider a moving average filter in which input is taken from the user
n=0:99
x1=cos(2*pi*0.03*n);
x2=cos(2*pi*0.51*n);
x=x1+x2;
Plot the low frequency signal (x1) and high frequency signal (x2) and then plot (x) .then pass the
signal (x) through filter (y) whose coefficients are entered by the user. Then plot the filtered
signal (y).
Comment! by observing the plots.
A delay system is a simple FIR filter. A delay by 2 is given by filter coefficients {0, 0, 1}. Its
implementation on input signal i.e. x[n] = {2 4 6 4 2} is shown in figure below:
-----------------------------------TASK 11--------------------------------
A delay filter delays an input signal. The amount of delay depends on filter coefficients. Design a
delay filter that delays an input signal by 6 units.
Causal Signal: A signal is said to be causal if it is zero for time<0. A signal can be made causal
by multiplying it with unit step.
Example
clc
clear all
close all
t = ‐2:1/1000:2;
x1 = sin(2*pi*2*t);
subplot(3,1,1);
plot(t,x1,'LineWidth',2);
xlabel('time');
ylabel('signal amplitude');
title('sin(2*\pi*f*t)');
u = (t>=0);
x2 = x1.*u;
subplot(3,1,2);
plot(t,u, 'r','LineWidth',2);
xlabel('time');
ylabel('Signal Amplitude');
title('Unit Step');
subplot(3,1,3);
plot(t,x2, 'k','LineWidth',2);
xlabel('time');
ylabel('signal amplitude');
title('causal version of sin(2*\pi*f*t)');
figure;
plot(t,x1,t,u,'‐.',t,x2,'LineWidth',2);
text(0,1.2,'u(t)','FontSize',16);
text(‐1.2,‐1.1,'x(t)','FontSize',16);
text(0.8,‐1.1,'x(t)*u(t)','FontSize',16);
axis([‐2 2 ‐1.5 1.5]);
----------------------------------TASK 01----------------------------------
A signal is said to be anti‐causal if it exists for values of n<0. Make the signal given in above
example anti‐causal . also display the lolly-pop plot of each signal.
8.2 CONVOLUTION:
Use the Matlab command Conv(h,x) to find convolution where
H = impulse response
X = input signal
Example
clc
clear all
close all
h = [1 2 3 4 5 4 3 2 1];
x = sin(0.2*pi*[0:20]);
y = conv(h, x);
figure(1);
stem (x);
title('Discrete Filter Input x[n]');
xlabel('index, n');
ylabel('Value, x[n]');
figure (2);
stem(y, 'r');
title('Discrete Filter Output y[n]');
xlabel('index, n');
ylabel('Value, y[n]');
Even though there are only 21 points in the x array, the conv function produces 8 more points
because it uses the convolution summation and assumes that x[n] = 0 when n>20.
Example
Matlab code
%Convolution
% n= 0 1 2 3 4 5 6 7 8
% x (n) =-4 2 -1 3 -2 -6 -5 4 5
% h(x) =-4 1 3 7 4 -2 -8 -2 -1
h=input('Enter value of h ');
x=input('Enter value oh x ');
c=conv(h,x);
M=length(c)-1;
n=0:1:M;
stem(n,c);
title('Convolution output');
grid
Command window
Matlab code
%Convolution
% n= 0 1 2 3 4 5 6 7 8
% x(n)= -4 2 -1 3 -2 -6 -5 4 5
% h(x)= -4 1 3 7 4 -2 -8 -2 -1
h=input('Enter value of h');
x=input('Enter value of x');
a=1;
b=h;
c=filter(b,a,x);
M=length(c)-1;
n=0:1:M;
stem(n,c);
title('Convolution output');
grid
Command window
------------------------------------TASK 03-------------------------------
Convolve the signal x[n]=[1 2 3 4 5 6] with an impulse delayed by two samples. Plot the original
signal and the result of convolution.
ASSOCIATIVE PROPERTY:
Associative property can be shown by the following equation
------------------------------------TASK 04-------------------------------
Convolution is associative. Given the three signal x1[n], x2[n], and x3[n] as:
x1[n]= [ 3 1 1]
x2[n]= [ 4 2 1]
x3[n]=[ 3 2 1 2 3]
Show that (x1[n] * x2[n]) * x3[n] = x1[n] * (x2[n] * x3[n])
COMMUTATIVE PROPERTY:
Commutative property can be shown by the following equation
x[n] * h[n] = h[n] * x[n]
-------------------------------------TASK 05-----------------------------------
Convolution is commutative. Given x[n] and h[n] as:
X[n]=[1 3 2 1]
H[n]=[1 1 2]
Show that x[n] * h[n] = h[n] * x[n]
----------------------------------TASK 06----------------------------------
Given the impulse response of a system as:
h[n] = 2δ[n] + δ[n‐1] + 2δ[n‐2] + 4δ[n‐3] + 3δ[n‐4]
If the input x[n] = δ[n] + 4δ[n‐1] +3δ[n‐2] + 2δ[n‐3] is applied to the system, determine the
output of the system.
-----------------------------------TASK 07---------------------------------
Two systems are connected in cascade.
h1[n]=[1 3 2 1]
h2[n]=[1 1 2]
If the input x[n] = δ[n] + 4δ[n‐1] +3δ[n‐2] + 2δ[n‐3] is applied, determine the output.
LAB NO. 9 :
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
This lab aims at the understanding of:
• Frequency response of FIR filters
• Implementation of low pass, high pass and bandpass filters and their frequency response
• Use of Matlab command FIR1 to design filter coefficients
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
9.1 FREQUENCY RESPONSE
subplot(3,1,1);
plot(w, abs(H), 'LineWidth', 2);
title('Magnitude of Frequency Response of filter with coefficients bk={1, 2, 1}');
xlabel('\omega');
ylabel('H(\omega)');
grid;
subplot(3,1,2);
plot(w, abs(H), 'r ', 'LineWidth', 2);
title('Zoomed view of the above graph from ‐\pi to \pi');
xlabel('\omega');
ylabel('H(\omega)');
axis([‐pi pi min(H) max(H)+0.5]);
grid;
subplot(3,1,3);
plot(w, angle(H), 'k ', 'LineWidth', 2);
title('Phase of Frequency Response of filter with coefficients b_k={1, 2, 1}');
xlabel('\omega');
ylabel('H(\omega)');
grid;
----------------------------------TASK 01-----------------------------------
Plot the magnitude and phase of the frequency response of an FIR filter with coefficients bk =
{1 ‐2 4 ‐2 1}. Determine the type of filter.
Note:
Freqz command can also be used as:
[H W] = freqz(b, a, n);
Where H contains the frequency response, W contains the frequencies between 0‐π where the
response is calculated, and n is the number of points at which to determine the frequency
response. If n is missing, this value defaults to 512.
9.2 FIR1
Fir1 is used to design filter coefficients. The syntax of this command is:
b = fir1(N, Wc)
Where b contains the filter coefficients returned by this command, N is the order of filter, and
Wc is the cutoff frequency normalized between 0 ‐‐ 1 where 1 refers to π. The number of
coefficients created is one more than the order of filter. By default, a low pass filter is created. A
high pass filter can be created using the argument ‘high’ at the end in the above command. A
bandpass filter can be created using [Wa Wb] instead of Wc where frequencies between Wa and
Wb are allowed to pass. If such a vector is specified instead of Wc, a bandpass filter is created
by default.
A band stop filter can be created by using the argument ‘stop’ in the aforementioned command.
B=fir1(N, Wc) //creates coefficients for low pass filter
B=fir1(N, Wc, ‘high’) //creates coefficients for high pass filter
B=fir1(N, [Wa Wb]) //creates coefficients for bandpass filter
B=fir1(N, [Wa Wb], ‘stop’) //creates coefficients for band stop filter
After the coefficients are obtained, freqz command can be used to determine the frequency
response.
Note: For High pass and band stop filters, N must be even. Else Matlab will increase the order
itself by 1.
------------------------------------TASK 03------------------------------------
Design a band‐pass filter which allows only the frequencies between π/6 and 2π/3 to pass and
blocks the rest of frequencies. Design it for order 10 and 1000.
------------------------------------TASK 04------------------------------------
Design a band‐stop filter which stops the frequencies between π/3 and π/2 and allows the rest
of frequencies to pass. Design it for order 10 and 1000.
LAB NO. 10 :
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
This lab aims at the understanding of:
• Z‐Plane and Unit Circle
• Pole Zero Plots
• Implementation and Frequency Response of Running Sum Filter and its Pole Zero Plot
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
10.1 THE THREE DOMAINS
There are three domains in which a signal can be analyzed:
n‐Domain:
It deals with sequences, impulse response and difference equation.
Ŵ‐Domain:
Frequency domain deals with spectrum and frequency response.
Z‐Domain:
• This domain deals with the Z‐operator, poles and zeros.
• There are the issues of stability and it will eventually lead us to IIR filters.
• Frequency transform is also considered as a special case of z‐transform.
Poles:
These are the values of z on which the value of transform is undefined.
Zeros:
These are the value of z on which the value of transform is zero.
Example:
Consider the system function:
H(z) = 1‐ 2z‐1 + 2 z‐2 ‐ z‐3
Matlab Command:
zplane(b,a)
where ,b and a are row vectors containing transfer function polynomial coefficients
b = Coefficients of Numerator
a = Coefficients of Denominator
Matlab Command:
zplane(Z,P) Plots the zeros Z and poles P (in column vectors) with the unit circle for
reference
Where,
Z = Zeros of System Function
P = Poles of System Function
Example: Pole Zero Plot of a System Function with Coefficients Given By B
b = [1 ‐2 2 ‐1];
a = [1];
figure;
zplane(b,a);
title('Pole‐zero plot of H(z) = 1 ‐ 2z(‐1) + 2z(‐2) ‐z(‐3)');
A system is said to be stable if all the poles lie inside the unit circle. This can be determined by
pole‐zero plot of a filter.
Example
--------------------------------------TASK 02-------------------------------------
Check if the system with following filter coefficients is stable.
bk = {1, 3, 5, 3, 2, 2}.
LAB NO.11:
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
The objective of this lab is
To read a digital image
The functions like: imread(), imwrite(), imshow(), imfinfo(), mat2gray() and im2bw()
will be discussed
Arithmetic operations will also be discussed
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Digital Image: digital image is basically a two dimensional function f(x,y) where (x,y) are the
spatial co-ordinates.
>>Imread(filename.fmt): imread is the built-in command for matlab by which we read the
image. The name and path can be specified bye the filename where the fmt is the format of the
file which we want to read. This command supports the following file types.
Filename.tiff
Filename.jpeg or Filename.jpg
Filename.gif
Filename.bmp
Filename.png
Filename.xwd
Example imread(‘c:\programfiles\matlab\work\aug.jpg’);
>>[m,n]=size(filename): it displays the size of the image for example if we write the
command
Example : [m,n]=size(f)
m=
1024
n=
3840
>>imshow: imshow diplays the picture which one read by the imread command and displays the
command example is below.
imshow(f)
>>imwrite: imwrite is the built in command which helps us to write the image the desired
format. The image which we read in by the command ‘imread’ and then we can write that image
according to our requirement.
Example imwrite(f,’aug.bmp’) so it will convert the image from jpg format to bmp format.
>>imfinfo : gives us all the information about the picture example is in the following.
imfinfo('aug.jpg')
ans =
Filename: 'aug.jpg'
FileModDate: '02-Aug-2007 10:01:38'
FileSize: 130995
Format: 'jpg'
FormatVersion: ''
Width: 1280
Height: 1024
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
>>mat2gray : converts the matrix which one reads from the command ‘imread’ to intensity
image.
Example : f = imread('aug.jpg');
h = mat2gray(f);
figure, imshow(h)
>>rgb2gray: Convert RGB image or color map to grayscale. RGB2GRAY converts RGB
images to grayscale by eliminating the saturation information while retaining the luminance.
Imdivide(): this function is used to divide an image by other image or by some particular value
Imabsdiff : this function is used to find the absolute difference between images
Imcomplement (): this function is used to find the complement of an image
------------------------------------TASK 01-----------------------------------
Apply the following functions on an image .
imread(), imwrite(), imshow(), imfinfo(), mat2gray() , rgb2gray, im2bw() and imhist()