You are on page 1of 15

Experiment no.

2
Aim:
To write a “MATLAB “program is generate various signals and
sequence such as unit impulse , unit step , unit impulse , unit ramp ,
sinusoidal , square , sawtooth , triangular , sine signals .

SOFTWARE REQUIRED :
1. MATLAB R2010a
2. Window XPSP2
THEORY :
To generate various signals and sequences such as unit impulse, unit step, unit
ramp, sinusoidal, square, sawtooth, triangular, and sine signals using MATLAB,
we need to understand the basic theory of signals and systems. Here are some
definitions and their working:
● UNIT IMPULSE FUNCTION:-The unit impulse function or Dirac delta
function, denoted δ(t), Is usually taken to mean a rectangular pulse of unit
area, and in the limit the width of the pulse tends to zero whilst its
magnitude tends to infinity.The impulse function is very short pulse used to
evaluate system dynamics. In the real world, an impulse function is a pulse
that is much shorter than the time response of the system. The system’s
response to an impulse can be used to determine the output of a system to
any input using the time-slicing technique called convolution.
● UNIT STEP FUNCTION:-The unit step function,u(t), is defined as that
is, u is a function of time t, and u has value zero when time is negative
(before we flip switch ); and value one when time is positive (from when we
flip the switch the unit step function,u(t),is defined as
● UNIT RAMP FUNCTION:-A ramp function or ramp signal is a type of
standard signal which starts at t=0 and increases linearly with time. The
unit ramp function has unit slop. The continuous- time unit ramp signal is
that function which starts at t=0 and increases linearly with time. It is
denoted by r(t). Mathematically, the continuous-time unit ramp signal is
defined as follow
● SINUSOIDAL SIGNAL GENERATION:-A sine wave, sinusoidal wave,
or sinusoid, is a periodic wave whose waveform (shape) is the trigonometric
sinc function. As a physical motion over time, this is simple harmonic
motion, the one dimensional projection of uniform circular motion.When
any two sine waves of the same frequency(but arbitrary phase) are linearly
combined, the results is another sine wave of the same frequency; this
property is unique among periodic waves. Conversely if some phase is
chosen as a zero reference, a sinc wave of arbitrary phase can be written as
the linear combination of two sine waves with phases of zero reference, a
sinc wave of arbitrary phase can be written as the linear combination of two
sine waves with phases of zero and a quarter cycle the sine and cosine
components respectively.
● SAWTOOTH FUNCTION:-Sawtooth is similar to the sine function but
creates a sawtooth wave with peaks of -1 and 1. The sawtooth wave is
defined to be -1 at multiples of 2π and to increase linearly with time with a
slope of 1/π at all other times.A waveform is a shape that represents
changes in amplitude with respect to time. A periodic waveform includes a
sine wave, square wave, triangular wave, sawtooth wave. On the x-axis, it
indicates the time and on the y-axis it indicates amplitude. Many people
frequently get confused between the triangular wave generator is one kind
of linear, non sinusoidal waveform and the shape of this waveform is a
triangular shape in which the fall time and rise time are different. The
sawtooth waveform can also be names an asymmetric triangular wave.
● TRIANGULAR FUNCTION:-A triangular function (also known as a
triangle function, hat function, or tent function) is a function whose graph
takes the shape of a triangle. Often this is an isosceles triangle if height 1
and base 2 in which case it is referred to as the triangular
function.Triangular function are useful in signal processing and
communication systems engineering a representation of idealize signals
and the triangular function from which more realistic signals can be
derived for example in kernel density estimation. It also has application in
pulse code modulation as a pulse shape for transmitting digital signals and
as a matched filter for receiving the signals. It is also used to define the
triangular window sometimes called the bartlett window.
● SINC FUNCTION:-
The sinc function sinc (x), also called the “sampling function”, is a function that
arises frequently in signal processing and the theory of fourier transforms. The
full name of the function is “sine cardinal”, but it is commonly referred to by its
abbreviation,”sinc.” There are two definitions in common use. The one adopted
in this work defines..
The only difference between the two definitions is in the scaling of the
independent variable.The unit step function,u(t), is defined as that is, u is a
function of time t, and u has value zero when time is negative (before we flip
switch ); and value one when time is positive (from when we flip the switch the
unit step function,u(t),is defined as

To generate these signals and sequences in MATLAB, we can use various built-in
functions and variables. For example, we can use the dirac function to generate
a unit impulse, the heaviside function to generate a unit step, the t variable to
generate a unit ramp, and the sin, square, sawtooth, and sawtooth
functions to generate sinusoidal, square, sawtooth, and triangular waves,
respectively.

PROCEDURE :
★Open MATLAB.

★ Open new M-file.

★Type the program.

★Save in current directory.

★ Compile and Run the program.

★For the output see command window\ Figure window.

PROGRAM :

%unit impulse function%


clc;
close all;
clear all;
t=-10:1:10;
x=(t==0);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('unit impulse function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit impulse discrete function');

%unit step function%


clc;
close all;
clear all;
t=-10:1:10;
x=(t==0);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('unit step function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit step discrete function')

%unit ramp function%


clc;
close all;
clear all;
t=0:20;
x=t;
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('unit ramp function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit ramp discrete function')

%sinusodial function %
clc;
close all;
clear all;
t=0:0.01:2;
x=sin(2*pi*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('sinusodial function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sinusodial sequence');

%square function%
clc;
clear all ;
close all ;
t = 0:0.01:2;
x=square(2*pi*t);
subplot(2,1,1);
plot(t,x,'g'):
xlabel('time');
ylabel('amplitude');
title('square signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('square sequence');

%traingular function %
clc;
close all;
clear all;
t=0:0.01:2;
x=sawtooth(2*pi*5*t,0.5);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('square function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('square sequence');
%sawtoothed function %
clc;
close all;
clear all;
t=0:0.01:2;
x=square(2*pi*5*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('square function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('square sequence');

%sinc function %
clc;
close all;
clear all;
t=linspace(-5,5);
x=sinc(t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('sinc function')
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sin sequence']);
OUTPUT:
RESULT :
Generation of various signals and sequence such as unit
impulse , unit step , unit impulse , unit ramp , sinusoidal , square ,
sawtooth , triangular , sine signals using a program in MATLAB is
shown.

You might also like