You are on page 1of 22

Signals And Systems

Lab Manual

Name: _________________________________________
Reg. No:___________ Section: _________ Group: ______

University of Engineering & Technology, Taxila

Prepared by:
Checked by:
Date:

Software Requirements
S.No
.
1

Software Title

Description

Matlab

Computing mathematics laboratory
Table of Contents

Lab No.

Lab Title

Lab # 1

Familiarize with the Matlab environment and
running some basic Matlab commnds in Matlab
Writing mathematical expressions and familiarizing
with some more advanced matlab commands
Understanding loops implementation in matlab

4

Lab # 4

Implementing complex algorithm in matlab using
loops

11

Lab # 5

12

Lab # 6
Lab # 7

Implementing (1) Decibel (2) Taking input from the
user (3) Root mean square (4) Harmonic mean (5)
Selection sort
Implementing Fourier transform in matlab
Verifying Fourier transform properties in matlab

Lab # 8
Lab # 9

Convolution of two rectangular pulses
Convolution of any two arbitrary inputs

15
16

Lab # 10
Lab # 11

Implementing Z-tranform in Matlab
Implementing Sampling in matlab

17
18

Lab
Lab
Lab
Lab
Lab

Verfiying Nyguist theorem
Modulating a signal based on carrier frequency
Upsampling and downsampling of signal
Implementing a moving average filter
Implementing a moving average filter and plotting
the magnitude and phase of its fourier transform.

19
20
21
22
23

Lab # 2
Lab # 3

#
#
#
#
#

12
13
14
15
16

Experiment # 1
Lab Title:

Basic Matlab Tutorial

Page

8
10

13
14

Try using these values: [3. Arrays can be classified as either vectors or matrices. Size of array is specified by the number of rows and the number of columns in the array.3)=5 Will produce matrix 0 0 0 005 Similarly the array d=[1 2].Learning Objectives: Familiarize with the Matlab environment and running some basic Matlab commnds in Matlab Equipment Required: Matlab Variables and Arrays The functional unit of data in any Matlab program is array.0. 3. Initializing with shortcut expressions Matlab provides a special shortcut notation for these circumstances using the COLON operator. 3. 2. 5. 4. the statement C(2.0] [1. The colon operator specifies a whole series of values by specifying the first vales in the series.4] [1. 6] [] Not all the elements of an array need to be defined when it is created. 5.0. 2. For example. with the number of rows mentioned first. 2. Then the statement d(4)=4 will produce d=[1 2 0 4]. 4. If a specific array element is defined and onwe or more of the elements before it are not.0] [1. The total number of elements in the array will be the product of the number of rows and the number of columns.0 3. if c is not previously defined. 3. The term VECTOR is usually used to describe an array with only one dimension. 6] [1. the . While the term MATRIX is usually used to describe an array with two or more dimensions.0 2. then the earlier elements are automatically created and initialized to zero. An Array is a collection of data values organized into rows and columns and known by a single name.

For example .2) Length(C) //Generate the longest dimension of the array. 3 4] D=zeros(size(C)) E=ones(3) Ones(3. 10 11 12]. it will generate a square array using the single argument as both the number of rows and columns.2)=[7 8 9. Zeros can be used to create an all zero array of any desired size. Multidimensioanl Array Matlab allows us to create arrays as many dimensions as necessary for any given problem. 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. C(:.1)=[1 2 3.:.:. Transpose Operator(‘): This operator swaps the rows and columns of any array that it is applied to.stepping increment and then the last value in the series. consider the following statement: My_val=input(‘enter an input value’).00)*pi. If function has a single square array. For example the following two statements create a 2X2X3 array C: C(:.1) Eye(3) Eye(3. 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. 4 5 6]. Whos C .3) C=[1 2.01:1. size function returns two values containing the number of rows and columns in an array.01:0. 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. 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.

Y).1 2. (a) 4u/3v (b)2v-2/(u+v)2 (c) v3/v3-u3 (d)4/3 pi. suppose that the 3X4 array Arr4 is defined as follows: Arr4=[1 2 3 4. Y=sin(X). Suppose that array arr3 is defined as follows: Arr3=[ 1 2 3 4 5 6 7 8].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. For example. For example: Arr1=[1. When used in an array subscript. The value returned by end is always the highest value of a given subscript. Then Arr1(5:end) would be the array [5 6 7 8] and array(end) would generate 8. For example. 5 6 7 8.SubArrays It is possible to select and use subsets of arrays as though they were separate arrays. plot(X.1:10. Then the expression Arr4(2:end. it can return different values within the same expression. plot(X. Evaluate the following expressions using Matlab.Y).2x for the range 0<=x<=10 X=0:0.v2 Question # 04: . Plot(X. Question # 03: suppose that u=1 and v=3. just include a list of all of the elements to be selected in the parenthesis after the rray name.2*X).2 3.1:6. 2:end) would return the array.(Try this one).3 4. TASKS Question # 01: This M-file calculates and plot the function sin(x) for 0<=x<=6 X=0:0. Y=2*exp(0. Is end appears in different subscripts.Y) Question # 02: The following Matlab statement plot the function y(x)=2e-0. 9 10 11 12]. To select a portion of array. end returns the highest value taken on by that subscript.

5 6.1 0.1 1.8 3.3) (c) array(1:2:3.1 0.0 2.0 1. determine the contents of the following subarrays 1.4 0.4 1.1:2:3).1 0.(a) Generate a 6X6 Matrix.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.0 0.1 0.:).3) ones(3. 1 : 2 )? (d)What is the size and Value of the (array[1 3].0 1.:) (b)array(:.4 1.4 5.1)’ 3:5’] (f) b([1 3].1 0.0 2. (b)Generate a 6X1 Matrix (c) Generate a 3X4 Matrix Question # 05 Answer the following questions for the array shown below.8 3.3 1.4 0.0 1.2 )=b([3 1].1)? (c) What is the size and value of array( : . Question # 08 Assume that the array is defined as follows.0 (a) what is the size of the array? (b)What is the value of the array(4.1 0.4 1.1 -3.1 -6.6 2.3 0.3 -1.1 (a) array(3.0 .1 0.1 6.2). 1. (e) w=[zeros(1.6 0.0 3.1 0. 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 5.5 6. (d)d=a+b(2.[3 3 4]) 2.0 2.3 -0.

(d)array([1 1].:) Experiment # 2 Lab Title: Basic Matlab Tutorial Learning Objectives: Writing mathematical expressions and familiarizing with some more advanced matlab commands Equipment Required: Matlab Question # 01: .

pi<3) (d)true>false (e) ~~(35/17)==(35/17) (f) (17<=8)==(3/2==1) (g)17.3>2.) Question # 04: The following statements are intended to alert a user to dangerously high oral thermometer readings(values are in degree Farenheit ). (d)fprintf(‘value=%f\n’.5 disp(‘Temperature below normal’) elseif temp>97. (c) fprintf(‘value=%e\n’.5 disp(‘temperature normal’) elseif temp>99. (b)disp([‘value=’int2str(value)]).value).value).5&&(3. Are they correct or incorrect? If they are incorrect.0 disp(‘temperature dangerously high’) end . why and correct them if temp<97.5>=5 (b)20>20 (c) xor(17-pi<15.4f\n’. 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.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)]).5 disp(‘temperature slightly high) elseif temp>103.value). (e) fprintf(‘value=%12.

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. If the package weighs more than 70 pounds. Question # 06: Implement the following function f(x. No package over 100 pounds will be accepted. Be sure to handle the case of overweight packages.50 for each pound or fraction thereof over two pounds. a $ 15.00 excess weight surcharge is added to cost.00 for the first two pounds and $4.Question # 05: The cost of sending a packet by an express delivery service is $12.x) Ceil(x) Fix(x) Floor(x) Round(x) Char(x) Experiment # 3 Lab Title: Basic Matlab Tutorial Learning Objectives: Understanding loops implementation in matlab Equipment Required: Matlab Question # 01: Implement unit impulse function in Matlab Question # 02: . Write a program that accepts the weight of a package in pounds and computes the cost of mailing the package.

Question # 03: Take a signal and scale it.1. .Implement Unit step function in matlab Question # 03: Classify signal as even or odd in Matlab Experiment # 4 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing complex algorithms in matlab using loops 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.

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. 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. Plot the dB-versus-power level on a log-linear scale.Experiment # 5 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing (1) Decibel (2) Taking input from the user (3) Root mean square (4) Harmonic mean (5) Selection sort Equipment Required: Matlab Question # 01: Engineers often measure the ratio of two power measurements in decibels or dB. .

Propmpt the user for the number of values to be entered and use a FOR loop to read in the numbers. sort the values in ascending order. if the input argement is UP. If the argument is “DOWN” . the default case is to sort the values in ascending order. Use any method you desire to read in the input values. Question # 04: Write a matlab program that will read an arbitrary number of possible input values and caluculate the harmonic mean of the numbers. 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” . Question # 05: Write a matlab program for the selection sort. If the argument is missing. and be sure to include the proper help information in your functon) Experiment # 6 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing Fourier transform in matlab Equipment Required: Matlab Question # 01: Look for the Matlab commands fft Ifft Conv Question # 02: . sort the values in descending order. Use a While loop to get the input values and terminate the inputs when the user inputs a negative value. (Be sure to handle the case of invalid arguments. Question # 03: Write a matlab program that will accept an arbitrary number of inputs and caluculate the rms average of the numbers.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.

Experiment # 7 Lab Title: Basic Matlab Tutorial Learning Objectives: Verifying fourier transform properties. Equipment Required: Matlab Question # 01: Verify following fourier transform properties in matlab Linearity: a .Use fft to find the Fourier transform. magnitude and phase of its Fourier transform and verify it from text book example#4.Generate a signal as sum of two sinusoidal of frequency f1=400Hz and f2=800Hz. Question # 03: Calculate Fourier transform of e^-at u(t).Y Shifting: x[n-nd]  exp(-jwnd)X Inverting: x[-n]  X(exp(-jw)) Compute the LHS and take its Fourier Transform. . Verify that “convolution in time domain equals multiplication in frequency domain. Compute the RHS.Plot original signal. x[n] + b .” Question # 05: Prove that FT of sinc is gate & ifft of gate is sinc.1 Question # 04: Convolve the signals x1(t)=e^at and x2(t)=sint for 100 samples. X + b. y[n]  a.

Compare the two: both results should be equal. Experiment # 8 Lab Title: Basic Matlab Tutorial Learning Objectives: Convolution Equipment Required: Matlab Question # 01: Convolution of any two rectangular pulses .

compare your results with the built in Convolution command.Experiment # 9 Lab Title: Basic Matlab Tutorial 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.

Experiment # 10 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing Z-Tranform in matlab 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 .

Generate the impulse train p(t) and sample the signal using x(t)=x(t)p(t). Consider the following frequencies for Sampling. Question # 02: Now Plot spectra of x(t) & p(t) and convolve both spectras. (Bonus marks) Experiment # 11 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing sampling in matlab Equipment Required: Matlab Question # 01: Create a signal x(t)=coswo(t).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. a)f0=fs/2 b)f0=3/2fs . Also obtain spectra of sampled signal from question 1. Plot observed samples in Time Domain. Question # 03: Study Aliasing from question 2.

Take any arbitrary signal.Experiment # 12 Lab Title: Basic Matlab Tutorial Learning Objectives: Verifying nyguist theorm Equipment Required: Matlab Question # 01: With reference to the previous lab. . Verify nyguist theorem. sample it.

Experiment # 13 Lab Title: Basic Matlab Tutorial Learning Objectives: Modulating a signal based on carrier frequency 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.

Filter with a low-pass filter which. equivalently define 2. theoretically. Or. Downsampling (or "subsampling") is the process of reducing the sampling rate of a signal.Experiment # 14 Lab Title: Basic Matlab Tutorial Learning Objectives: Upsampling and downsampling of signal Equipment Required: Multimedia Question # 01: Upsampling is the process of increasing the sampling rate of a signal. This is usually done to reduce the data rate or the size of the data. should be the sinc filter with frequency cut off at pi/L. Add L-1 zeros between each sample in f(k). . Let L denote the upsampling factor. The upsampled signal satisfies the Nyquist-Shannon sampling theorem if the original signal does. Consider a discrete signal f(k) on a radian frequency digital frequency range. 1.

To ensure that the sampling theorem is satisfied. Let the filtered signal be denoted g(k). 1. Reduce the data by picking out every Mth sample: h(k) = g(Mk). 2. 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. Experiment # 15 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing a moving average filter Equipment Required: Multimedia Question # 01: Implement Moving average filter in matlab . theoretically. Filter the signal to ensure that the sampling theorem is satisfied. This filter should.If the sampling theorem is not satisfied then the resulting digital signal will have aliasing. be the sinc filter with frequency cutoff at pi/M. Data rate reduction occurs in this step.

Equipment Required: Multimedia Question # 01: Implementing a moving average filter and plotting the magnitude and phase of its Fourier transform. .Experiment # 16 Lab Title: Basic Matlab Tutorial Learning Objectives: Implementing a moving average filter and plotting the magnitude and phase of its fourier transform.