Sei sulla pagina 1di 6

Text Book : Basic Simulation Lab with MATLAB Authors : Dr Bhanu Bhaskara, Siddhartha Bhaskara Publisher : Tata McGrawHill,

1st Edition, July 2010

Chapter 3: Generation of Signals and Sequences


S.No MATLAB Code 1. t = 0 : 0.001 : 1; Explanation Generate a vector of 1001 samples for t with a value between 0 & 1 with an increment of 0.001 Generate a linear ramp with a slope of 0.5 Plot the graph Label the X-axis Label the Y-axis Add an appropriate title to the graph

2. y = 0.5 * t; 3. plot( t , y ); 4. xlabel ('Time Index t (sec.)'); 5. ylabel ('Amplitude'); 6. title ('Ramp Signal Sequence');

Table 3.1 : MATLAB code for Ramp Signal Generation

S.No MATLAB Code 1. t = 0 : 0.0001 : 0.1;

2. y = square ( 2 * pi * 50 * t);

3. plot (t , y); axis ( [ 0 0.1 -2 2 ] );

4. xlabel ('Time Index t (sec.)'); ylabel ('Amplitude'); 5. title ('Square Wave Signal Sequence');

Explanation Generate a vector of 10001 samples for t with a value between 0 & 0.1 with an increment of 0.0001 Generate a square wave of frequency 50 Hz, by calling the MATLAB inbuilt function square. Plot the graph. Adjust the X and Y coordinates to view a few cycles of the square wave. Label the X and Y axes

Add an appropriate title to the graph

Table 3.2 : MATLAB code for Square Wave Signal Generation

Text Book : Basic Simulation Lab with MATLAB Authors : Dr Bhanu Bhaskara, Siddhartha Bhaskara Publisher : Tata McGrawHill, 1st Edition, July 2010

S.No 1. fs = 10000;

MATLAB Code

2. t = 0 : 1/fs : 1.5;

3. x = sawtooth (2 * pi * 100 * t);

4. plot( t , x ); axis ( [ 0 0.05 -1 1 ] );

5. xlabel ('Time Index t (sec.)'); ylabel ('Amplitude'); 6. title ('Sawtooth Wave Signal Sequence');

Explanation Set the sampling frequency fs as 10000. Generate a vector of 15001 samples for t with a value between 0 & 1.5 with an increment of 0.0001 Generate a Saw Tooth wave of frequency 100 Hz, by calling the MATLAB built-in function sawtooth. Plot the graph. Adjust the X and Y coordinates to view a few cycles of the Saw Tooth wave. Label the X and Y axes

Add an appropriate title to the graph

Table 3.3 : MATLAB code for Saw Tooth Wave Generation

Text Book : Basic Simulation Lab with MATLAB Authors : Dr Bhanu Bhaskara, Siddhartha Bhaskara Publisher : Tata McGrawHill, 1st Edition, July 2010

S.No MATLAB Code 1. fs = 10000; 2. t = 0 : 1/fs : 1.5;

3. x = sawtooth (2 * pi * 50 * t , 0.5);

4. plot(t,x); axis ( [ 0 0.1 -1 1 ] );

5. xlabel ('Time Index t (sec.)'); ylabel ('Amplitude'); 6. title ('Triangular Wave Signal Sequence');

Explanation Set the sampling frequency fs as 10000. Generate a vector of 15001 samples for t with a value between 0 & 1.5 with an increment of 0.0001 Generate a Triangular wave of frequency 50 Hz, by calling the MATLAB built-in function sawtooth with 0.5 as the duty cycle parameter. Plot the graph. Adjust the X and Y coordinates to view a few cycles of the triangular wave. Label the X and Y axes

Add an appropriate title to the graph

Table 3.4 : MATLAB Code for Triangular Wave Generation

Text Book : Basic Simulation Lab with MATLAB Authors : Dr Bhanu Bhaskara, Siddhartha Bhaskara Publisher : Tata McGrawHill, 1st Edition, July 2010

S.No 1. N=20;

MATLAB Code

2. t = -N : .0001 : N;

3. theta = input('The phase angle is '); 4. x = sin (2 * pi * 50 * t + theta);

5. plot( t , x ); axis( [-.04 .04 -1 1] );

6. grid;

7. xlabel ('Time Index t (sec.)'); ylabel ('Amplitude'); 8. title ('Sinusoidal Signal of Frequency 50 Hz and Desired Phase');

Explanation Set a limit 20 for X-axis coordinate time. Generate a vector of 400001 samples for t with a value between -20 & 20 with a step size of 0.0001. The Xaxis range is from -20 to +20. Input the desired Phase Angle for the variable called theta Generate a Sine Wave of frequency 50 Hz and desired phase angle theta, by calling the MATLAB built-in function sin. Plot the graph. Adjust the X and Y coordinates to view a few cycles of the Sine wave. Insert horizontal and vertical grid in the graph for easy measurement of parameters. Label the X and Y axes

Add an appropriate title to the graph

Table 3.5 : MATLAB Code for Sine Wave Signal Generation

S.No MATLAB Code 1. t = linspace(-5 , 5);

2. y = sinc(t);

3. plot( t , y ); 4. xlabel ('Time Index t (sec.)'); ylabel ('Amplitude'); 5. title ('Sinc Signal Sequence');

Explanation Generate a vector of 100 linearly spaced samples for t with a value between -5 & 5 Call the built-in 'Sinc' function to generate the Sinc signal of 100 samples Plot the graph. Label the X and Y axes Add an appropriate title to the graph

Table 3.6 : MATLAB Code for Sinc Signal Generation

Text Book : Basic Simulation Lab with MATLAB Authors : Dr Bhanu Bhaskara, Siddhartha Bhaskara Publisher : Tata McGrawHill, 1st Edition, July 2010

S.No 1. clc; 2. clear all;

MATLAB Code

3. m1 = input ( ' Please input a NEGATIVE number for m1 '); 4. m2 = input ( ' Please input a POSITIVE number for m2 '); 5. m = [m1 : m2]; 6. x = zeros(1,m2-m1+1); 7. m0 = input ( ' Type 0 for Unit Impulse, negative/ positive no. for delayed/ advanced signal '); 8. x(m0-m1+1) = 1; 9. stem( m , x ); axis( [ m1 m2 -1.5 1.5 ] );

Explanation Clear Command Window for a clean view Clear all the previously defined variables Set a limit for negative X-axis Set a limit for positive X-axis Define the range for X-axis Create a row vector of zeros Define the place of the single unit impulse on the X-axis Set the amplitude of the unit impulse as 1 at the defined place Plot the graph as stems. Adjust the X and Y coordinates to view a nice graph. Label the X and Y axes Add an appropriate title to the graph

10. xlabel ('Time Index m (sec.)'); ylabel ('Amplitude'); 11. title ('Unit Impulse Signal Sequence');

Table 3.7 : MATLAB Code for Unit Impulse Signal Generation

Text Book : Basic Simulation Lab with MATLAB Authors : Dr Bhanu Bhaskara, Siddhartha Bhaskara Publisher : Tata McGrawHill, 1st Edition, July 2010

S.No MATLAB Code 1. clc; clear all;

2. k1 = input ( ' Please input a NEGATIVE number for k1 '); 3. k2 = input ( ' Please input a POSITIVE number for k2 '); 4. k0 = input ( ' Type 0 for normal Unit Step, a negative or positive no. for a shifted one '); 5. k = [k1 : k2]; 6. x = zeros(1,k2-k1+1); 7. x( k0-k1+1 : end ) = 1;

Explanation Clear Command Window and all the previously defined variables for a clean view Set a limit for negative X-axis Set a limit for positive X-axis Decide on the type of Unit Step desired and accordingly feed an input Define the range for X-axis Create a row vector of zeros Set the amplitude of the unit step as 1 from the place of starting until end. Plot the graph as stems. Adjust the X and Y coordinates to view a decent looking graph. Label the X and Y axes Add an appropriate title to the graph

8. stem( k , x ); axis ( [ k1 k2 -1.5 1.5 ] ); 9. xlabel ('Time Index k (sec.)'); ylabel ('Amplitude'); 10. title ('Unit Step Signal Sequence');

Table 3.8 : MATLAB Code for Unit Step Signal Generation

Potrebbero piacerti anche