Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab Manual
Name: _________________________________________
Reg. No:___________ Section: _________ Group: ______
Prepared by:
Checked by:
Date:
Software Requirements
S.No
.
1
Software Title
Description
Matlab
Lab No.
Lab Title
Lab # 1
Lab # 4
11
Lab # 5
12
Lab # 6
Lab # 7
Lab # 8
Lab # 9
15
16
Lab # 10
Lab # 11
17
18
Lab
Lab
Lab
Lab
Lab
19
20
21
22
23
Lab # 2
Lab # 3
#
#
#
#
#
12
13
14
15
16
Experiment # 1
Lab Title:
Page
8
10
13
14
Learning
Objectives:
Equipment
Required:
Matlab
stepping increment and then the last value in the series. The
general form of a colon operator is
First: increment: last
For example
x=1:2:10
will generate x= 1 3 5 7 9
Try using angles=(0.01:0.01:1.00)*pi;
Transpose Operator():
This operator swaps the rows and columns of any array that it is
applied to.
For example try using:
F=[1:4]
And F=[1:4]
Initializing with Built-in functions:
Try using these:
A=zeros(2)
B=zeros(2,3)
C=[1 2; 3 4]
D=zeros(size(C))
E=ones(3)
Ones(3,1)
Eye(3)
Eye(3,2)
Length(C) //Generate the longest dimension of
the array.
Zeros can be used to create an all zero array of any desired size. If
function has a single square array; it will generate a square array
using the single argument as both the number of rows and columns.
size function returns two values containing the number of rows and
columns in an array.
Initializing variables with keyboard input:
Input function displays a prompt string in the command window and
then waits for the user to type in a response. For example , consider
the following statement:
My_val=input(enter an input value);
Multidimensioanl Array
Matlab allows us to create arrays as many dimensions as necessary
for any given problem. These arrays have one subscript for each
dimension and an individual element in the array will be the product
of the maximum value of each subscript. For example the following
two statements create a 2X2X3 array C:
C(:,:,1)=[1 2 3; 4 5 6];
C(:,:,2)=[7 8 9; 10 11 12];
Whos C
SubArrays
It is possible to select and use subsets of arrays as though they
were separate arrays. To select a portion of array, just include a list
of all of the elements to be selected in the parenthesis after the rray
name. For example:
Arr1=[1.1 2.2 3.3 4.4 5.5]
Try using Arr1(3)
And Arr1([1 4])
And also Arr1(1:2:5)
End Function:
It is very useful for creating array subscripts. When used in an array
subscript; end returns the highest value taken on by that subscript.
For example. Suppose that array arr3 is defined as follows:
Arr3=[ 1 2 3 4 5 6 7 8];
Then Arr1(5:end) would be the array [5 6 7 8] and array(end) would
generate 8.
The value returned by end is always the highest value of a given
subscript. Is end appears in different subscripts, it can return
different values within the same expression. For example, suppose
that the 3X4 array Arr4 is defined as follows:
Arr4=[1 2 3 4; 5 6 7 8; 9 10 11 12];
Then the expression
Arr4(2:end, 2:end)
would return the array.(Try this one).
TASKS
Question # 01:
This M-file calculates and plot the function sin(x) for 0<=x<=6
X=0:0.1:6;
Y=sin(X);
plot(X,Y);
plot(X,Y)
Question # 02:
The following Matlab statement plot the function y(x)=2e-0.2x for the
range 0<=x<=10
X=0:0.1:10;
Y=2*exp(0.2*X);
Plot(X,Y);
Question # 03:
suppose that u=1 and v=3. Evaluate the following expressions using
Matlab.
(a) 4u/3v
(b)2v-2/(u+v)2
(c) v3/v3-u3
(d)4/3 pi.v2
Question # 04:
Question # 05
Answer the following questions for the array shown below.
1.1 0.0 2.1 -3.5 6.0
0.0 1.1 -6.6 2.8 3.4
1.1 0.1 0.3 -0.4 1.3
-1.4 5.1 0.0 1.1 0.0
(a) what is the size of the array?
(b)What is the value of the array(4,1)?
(c) What is the size and value of array( : , 1 : 2 )?
(d)What is the size and Value of the (array[1 3],end)?
Question # 06
Are the following Matlab variable names legal or illegal? Why?
(a) dog1
(b)1dog
(c) Do_you_know_the_way__to_lahore
(d)_help
Question # 07
Determine the size and contents of the follwings arrays. Note that
the later arrays may depend on the definition of arrays defined
earlier in this exercise
(a) a=1:2:5
(b)b=[a a a]
(c) c=b(1:2:3,1:2:3);
(d)d=a+b(2,:);
(e) w=[zeros(1,3) ones(3,1) 3:5]
(f) b([1 3],2 )=b([3 1],2);
Question # 08
Assume that the array is defined as follows; determine the contents
of the following subarrays
1.1
0.0
2.1
1.4
0.0
1.1
0.1
5.1
(a) array(3,:)
(b)array(:,3)
(c) array(1:2:3,[3 3 4])
2.1
6.6
0.3
0.0
3.5 6.0
2.8 3.4
0.4 1.3
1.1 0.0
(d)array([1 1],:)
Experiment # 2
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Assume that value has been initialized to 10pi and determine what is
printed out by eah of the following statements:
(a) disp([value=num2str(value)]);
(b)disp([value=int2str(value)]);
(c) fprintf(value=%e\n,value);
(d)fprintf(value=%f\n,value);
(e) fprintf(value=%12.4f\n,value);
Question # 02:
Evaluate the following expressions
(a) 11/5+6
(b) (11/5)+6
(c) 11/(5+6)
(d) 3^2^3
(e) (3^2)^3
(f) 3^(2^3)
(g) round(-11/5)+6
(h) ceil(-11/5)+6
(i) floor(-11/5)+6
Question # 03:
Evaluate the following Matlab expressions
(a) 5.5>=5
(b)20>20
(c) xor(17-pi<15,pi<3)
(d)true>false
(e) ~~(35/17)==(35/17)
(f) (17<=8)==(3/2==1)
(g)17.5&&(3.3>2.)
Question # 04:
The following statements are intended to alert a user to dangerously
high oral thermometer readings(values are in degree Farenheit ). Are
they correct or incorrect? If they are incorrect, why and correct them
if temp<97.5
disp(Temperature below normal)
elseif temp>97.5
disp(temperature normal)
elseif temp>99.5
disp(temperature slightly high)
elseif temp>103.0
disp(temperature dangerously high)
end
Question # 05:
The cost of sending a packet by an express delivery service is $12.00
for the first two pounds and $4.50 for each pound or fraction thereof
over two pounds. If the package weighs more than 70 pounds, a $ 15.00
excess weight surcharge is added to cost. No package over 100 pounds
will be accepted. Write a program that accepts the weight of a package
in pounds and computes the cost of mailing the package. Be sure to
handle the case of overweight packages.
Question # 06:
Implement the following function f(x,y) as follows:
X+Y
for
X>=0 and Y>=0
X+Y2
for
X>=0 and Y<0
X2 + Y for
X<0 and Y>=0
X2+Y2 for
X<0 and Y<0
Question # 07:
Try these built-in functions in Matlab
Abs(x)
Acos(x)
Asin(x)
Atan(x)
Atan2(y,x)
Ceil(x)
Fix(x)
Floor(x)
Round(x)
Char(x)
Experiment # 3
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Implement unit impulse function in Matlab
Question # 02:
Experiment # 4
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Calculate factorial of a number
Question # 02:
Implement the equation y(x)=x2-3x+2 for all the values of x between
-1 and 3 with the increment of 0.1.
Question # 03:
Take a signal and scale it.
Experiment # 5
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Engineers often measure the ratio of two power measurements in
decibels or dB. The equation for the ratio of two power measurements
in decibel is
dB=10log10p2/p1
where p2 is the power level being measured and P1 is some reference
power level. Assume that the reference power level P1 is 1 Watt and
write a program that calculates the decibel level corresponding to
power levels between 1 and 20 watts in increment of 02 Watt steps.
Plot the dB-versus-power level on a log-linear scale.
Question # 02:
Write a matlab program that will accept an arbitrary number of
possible input values and calculate both the arithmetic mean and
geometric mean of the numbers. Use a While loop to get the input
values and terminate the inputs when the user inputs a negative value.
Question # 03:
Write a matlab program that will accept an arbitrary number of inputs
and caluculate the rms average of the numbers. Propmpt the user for
the number of values to be entered and use a FOR loop to read in the
numbers.
Question # 04:
Write a matlab program that will read an arbitrary number of possible
input values and caluculate the harmonic mean of the numbers. Use
any method you desire to read in the input values.
Question # 05:
Write a matlab program for the selection sort. The program should
accept 5 input values and sort them according to the criteria
Question # 06:
Modify the selection sort so that it accepts a second parameter which
may be UP or DOWN . if the input argement is UP, sort the values
in ascending order. If the argument is DOWN , sort the values in
descending order. If the argument is missing, the default case is to sort
the values in ascending order. (Be sure to handle the case of invalid
arguments, and be sure to include the proper help information in your
functon)
Experiment # 6
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Look for the Matlab commands
fft
Ifft
Conv
Question # 02:
Experiment # 7
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Verify following fourier transform properties in matlab
Linearity: a . x[n] + b . y[n]
a. X + b.Y
Shifting: x[n-nd]
exp(-jwnd)X
Inverting: x[-n]
X(exp(-jw))
Compute the LHS and take its Fourier Transform.
Compute the RHS.
Experiment # 8
Lab Title:
Learning
Objectives:
Convolution
Equipment
Required:
Matlab
Question # 01:
Convolution of any two rectangular pulses
Experiment # 9
Lab Title:
Learning
Objectives:
Generalized Convolution
Equipment
Required:
Matlab
Question # 01:
Make your own convolution code; perform convolution of two
rectangular pulses; show the step by step procedure (via flip and drag)
of convolution; compare your results with the built in Convolution
command.
Experiment # 10
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Find the Z-transform of
(1)
Impulse
(2)
Unit step
(3)
Delayed impulse by one unit to the right
(4)
Delayed Unit step by one unit to the right
(5)
anU(n)
(6)
Sin wn
(7)
Coswn
Question # 02:
Find the inverse Z-transform of all the answers collected from question
# 01 and verify the answer that what you got in question 1 was right
Question # 03:
Take any two vectors and find their roots
Question # 04:
Display the pole-zero plot of
A=[0 1 1]
B=[1 -2 3]
Question # 05:
Try to make your own matlab code for the Z-transform; (Bonus marks)
Experiment # 11
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
Create a signal x(t)=coswo(t). Generate the impulse train p(t) and
sample the signal using x(t)=x(t)p(t). Plot observed samples in Time
Domain.
Question # 02:
Now Plot spectra of x(t) & p(t) and convolve both spectras. Also obtain
spectra of sampled signal from question 1.
Question # 03:
Study Aliasing from question 2. Consider the following frequencies for
Sampling.
a)f0=fs/2
b)f0=3/2fs
Experiment # 12
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
With reference to the previous lab; Take any arbitrary signal; sample it;
Verify nyguist theorem.
Experiment # 13
Lab Title:
Learning
Objectives:
Equipment
Required:
Matlab
Question # 01:
The experiment implements a gui-based tutorial of the effect of
multiplying a cosine with a carrier frequency fc with a given signal.
And the effect are monitored both in time and frequency domain.
The parameters that the gui would take:
fc: the carrier frequency
fs: the sampling frequency
The gui would show the input signal as sampled
The resulted signal after multiplication with the carrier frequency
should be displayed.
Display frequency spectrum of both the original signal and the
modulated signal.
Experiment # 14
Lab Title:
Learning
Objectives:
Equipment
Required:
Multimedia
Question # 01:
If the sampling theorem is not satisfied then the resulting digital signal
will have aliasing. To ensure that the sampling theorem is satisfied, a
low-pass filter is used as an anti-aliasing filter to reduce the bandwidth
of the signal before the signal is downsampled.
Let M denote the downsampling factor.
1. Filter the signal to ensure that the sampling theorem is satisfied.
This filter should, theoretically, be the sinc filter with frequency
cutoff at pi/M. Let the filtered signal be denoted g(k).
2. Reduce the data by picking out every Mth sample: h(k) = g(Mk).
Data rate reduction occurs in this step.
Experiment # 15
Lab Title:
Learning
Objectives:
Equipment
Required:
Multimedia
Question # 01:
Implement Moving average filter in matlab
Experiment # 16
Lab Title:
Learning
Objectives:
Equipment
Required:
Multimedia
Question # 01:
Implementing a moving average filter and plotting the magnitude and
phase of its Fourier transform.