matlab lab manual.doc



Comments



Description

Signals And SystemsLab 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 0] [1.4] [1.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. The colon operator specifies a whole series of values by specifying the first vales in the series. Initializing with shortcut expressions Matlab provides a special shortcut notation for these circumstances using the COLON operator. 4. 4. the . Size of array is specified by the number of rows and the number of columns in the array. then the earlier elements are automatically created and initialized to zero. 2.0. The total number of elements in the array will be the product of the number of rows and the number of columns. 6] [1. 5. 5. An Array is a collection of data values organized into rows and columns and known by a single name. the statement C(2. Try using these values: [3. Then the statement d(4)=4 will produce d=[1 2 0 4]. 2. with the number of rows mentioned first. if c is not previously defined. If a specific array element is defined and onwe or more of the elements before it are not. 6] [] Not all the elements of an array need to be defined when it is created.0 3.0] [1. 3. 3.0. 2. While the term MATRIX is usually used to describe an array with two or more dimensions. 3. Arrays can be classified as either vectors or matrices.0 2. For example.3)=5 Will produce matrix 0 0 0 005 Similarly the array d=[1 2]. The term VECTOR is usually used to describe an array with only one dimension. 01:0. consider the following statement: My_val=input(‘enter an input value’). 4 5 6].:.00)*pi.stepping increment and then the last value in the series. size function returns two values containing the number of rows and columns in an array. 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. it will generate a square array using the single argument as both the number of rows and columns.2) Length(C) //Generate the longest dimension of the array. For example . C(:. 10 11 12].01:1.1)=[1 2 3. 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. Multidimensioanl Array Matlab allows us to create arrays as many dimensions as necessary for any given problem. Whos C .1) Eye(3) Eye(3.2)=[7 8 9. Zeros can be used to create an all zero array of any desired size. If function has a single square array.:.3) C=[1 2. 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. 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. 3 4] D=zeros(size(C)) E=ones(3) Ones(3. Transpose Operator(‘): This operator swaps the rows and columns of any array that it is applied to. For example the following two statements create a 2X2X3 array C: C(:. 5 6 7 8.4 5. plot(X. end returns the highest value taken on by that subscript. Plot(X.(Try this one).3 4. To select a portion of array. Question # 03: suppose that u=1 and v=3. Y=2*exp(0. Then Arr1(5:end) would be the array [5 6 7 8] and array(end) would generate 8. TASKS Question # 01: This M-file calculates and plot the function sin(x) for 0<=x<=6 X=0:0. just include a list of all of the elements to be selected in the parenthesis after the rray name. For example. (a) 4u/3v (b)2v-2/(u+v)2 (c) v3/v3-u3 (d)4/3 pi.SubArrays It is possible to select and use subsets of arrays as though they were separate arrays. suppose that the 3X4 array Arr4 is defined as follows: Arr4=[1 2 3 4. 2:end) would return the array. Evaluate the following expressions using Matlab. 9 10 11 12]. For example: Arr1=[1. Y=sin(X). For example. plot(X. Then the expression Arr4(2:end. When used in an array subscript.2x for the range 0<=x<=10 X=0:0. Suppose that array arr3 is defined as follows: Arr3=[ 1 2 3 4 5 6 7 8]. it can return different values within the same expression.2*X).Y) Question # 02: The following Matlab statement plot the function y(x)=2e-0.1 2. Is end appears in different subscripts.1:6.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.Y).1:10. The value returned by end is always the highest value of a given subscript.v2 Question # 04: .Y).2 3. 1 -3.1 0.1 0.3) (c) array(1:2:3.:) (b)array(:.1 0.0 1.2). 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.0 0.3 -1.:). (d)d=a+b(2.0 1. 1.0 2. (e) w=[zeros(1.0 1.0 (a) what is the size of the array? (b)What is the value of the array(4.4 0.0 3.1 0.[3 3 4]) 2.3 -0.2 )=b([3 1].3 0.0 2.3 1.8 3. determine the contents of the following subarrays 1.1 1.1 0.6 2. Question # 08 Assume that the array is defined as follows.1)’ 3:5’] (f) b([1 3].8 3.4 1.(a) Generate a 6X6 Matrix.0 2.6 0.0 .5 6.1 (a) array(3.1 -6.1 5. 1 : 2 )? (d)What is the size and Value of the (array[1 3].1)? (c) What is the size and value of array( : .3) ones(3.1 0.1 0.4 0.1:2: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.5 6.4 1. (b)Generate a 6X1 Matrix (c) Generate a 3X4 Matrix Question # 05 Answer the following questions for the array shown below.4 1.4 5.1 6.1 0. :) 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: .(d)array([1 1]. 5>=5 (b)20>20 (c) xor(17-pi<15.4f\n’.5 disp(‘Temperature below normal’) elseif temp>97. Are they correct or incorrect? If they are incorrect. (d)fprintf(‘value=%f\n’.value).5 disp(‘temperature slightly high) elseif temp>103. (b)disp([‘value=’int2str(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.) Question # 04: The following statements are intended to alert a user to dangerously high oral thermometer readings(values are in degree Farenheit ).value).3>2.value). (c) fprintf(‘value=%e\n’. why and correct them if temp<97. (e) fprintf(‘value=%12.5&&(3.5 disp(‘temperature normal’) elseif temp>99.pi<3) (d)true>false (e) ~~(35/17)==(35/17) (f) (17<=8)==(3/2==1) (g)17.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)]).0 disp(‘temperature dangerously high’) end . Question # 06: Implement the following function f(x.50 for each pound or fraction thereof over two pounds. Be sure to handle the case of overweight packages. No package over 100 pounds will be accepted.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.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.00 for the first two pounds and $4.00 excess weight surcharge is added to cost. If the package weighs more than 70 pounds. a $ 15. 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. . Question # 03: Take a signal and scale it. . 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. 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. (Be sure to handle the case of invalid arguments. Question # 05: Write a matlab program for the selection sort. the default case is to sort the values in ascending order. 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” . Propmpt the user for the number of values to be entered and use a FOR loop to read in the numbers. Question # 03: Write a matlab program that will accept an arbitrary number of inputs and caluculate the rms average of the numbers. if the input argement is UP. If the argument is “DOWN” . sort the values in ascending order. sort the values in descending order.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. 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: . Question # 04: Write a matlab program that will read an arbitrary number of possible input values and caluculate the harmonic mean of the numbers. If the argument is missing. Use any method you desire to read in the input values. Use fft to find the Fourier transform. y[n]  a.” Question # 05: Prove that FT of sinc is gate & ifft of gate is sinc.Y Shifting: x[n-nd]  exp(-jwnd)X Inverting: x[-n]  X(exp(-jw)) Compute the LHS and take its Fourier Transform. x[n] + b . Question # 03: Calculate Fourier transform of e^-at u(t). 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 .Plot original signal.Generate a signal as sum of two sinusoidal of frequency f1=400Hz and f2=800Hz. .1 Question # 04: Convolve the signals x1(t)=e^at and x2(t)=sint for 100 samples. Compute the RHS. Verify that “convolution in time domain equals multiplication in frequency domain. X + b. magnitude and phase of its Fourier transform and verify it from text book example#4. Experiment # 8 Lab Title: Basic Matlab Tutorial Learning Objectives: Convolution Equipment Required: Matlab Question # 01: Convolution of any two rectangular pulses .Compare the two: both results should be equal. compare your results with the built in Convolution command. perform convolution of two rectangular pulses. show the step by step procedure (via flip and drag) of convolution. .Experiment # 9 Lab Title: Basic Matlab Tutorial Learning Objectives: Generalized Convolution Equipment Required: Matlab Question # 01: Make your own convolution code. 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 . 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. Question # 02: Now Plot spectra of x(t) & p(t) and convolve both spectras. Also obtain spectra of sampled signal from question 1. a)f0=fs/2 b)f0=3/2fs . Question # 03: Study Aliasing from question 2. Consider the following frequencies for Sampling. (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). Generate the impulse train p(t) and sample the signal using x(t)=x(t)p(t). Plot observed samples in Time Domain. Verify nyguist theorem. . sample it. 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. Display frequency spectrum of both the original signal and the modulated signal. 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. And the effect are monitored both in time and frequency domain.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. . This is usually done to reduce the data rate or the size of the data. Downsampling (or "subsampling") is the process of reducing the sampling rate of a signal. Let L denote the upsampling factor. Filter with a low-pass filter which. Consider a discrete signal f(k) on a radian frequency digital frequency range. .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. The upsampled signal satisfies the Nyquist-Shannon sampling theorem if the original signal does. Or. theoretically. 1. equivalently define 2. should be the sinc filter with frequency cut off at pi/L. Add L-1 zeros between each sample in f(k). Filter the signal to ensure that the sampling theorem is satisfied. 1. be the sinc filter with frequency cutoff at pi/M. To ensure that the sampling theorem is satisfied. Let M denote the downsampling factor.If the sampling theorem is not satisfied then the resulting digital signal will have aliasing. 2. 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 . This filter should. a low-pass filter is used as an anti-aliasing filter to reduce the bandwidth of the signal before the signal is downsampled. theoretically. Let the filtered signal be denoted g(k). Data rate reduction occurs in this step. Reduce the data by picking out every Mth sample: h(k) = g(Mk). 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.
Copyright © 2024 DOKUMEN.SITE Inc.