Signals are the physical quantity that varies with time. Some standard signals are very important to know behaviour of the system those signals are:
- Unit Impulse.
- Unit Step.
- Ramp.
- Sinusoidal.
- Sinc.
- Signum.
In this blog we are going to create above mentioned signals creating anonymous function of each of them. These signals are also helpful for control system.
For more detail about anonymous function visit: https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html
Here we are creating time axis from -1 to 1 with the step size equal to 1/(sampling frequency). Higher is the sampling frequency better is the signal (but don’t keep sampling frequency too higher because large number of samples requires large amount of processing power so it might take long time to process results) according to nyquist theorem.
Here we are plotting continuous time signal using plot() function. But in case Discrete time plot is needed one can use stem() function instead of plot() in the code. Also here I have used subplot so that all signals are visible on single sheet. One can also plot each function individually using “figure” and “plot();”.
close all;
clc;
clear all;
% Sampling Frequency and defining time axes
fs=1000;
t=-1:1/fs:1-(1/fs);
f=1;
% General Variables
w=2*pi*f;
% Functions
d=@(t) t==0; %Impulse.
u=@(t) t>=0; %Unit step.
x=@(t) u(t+0.5)-u(t-0.5); %Rect using unit step.
sn=@(t) sin(2*pi*f*t); %SineWave.
cs=@(t) cos(2*pi*f*t); %CosineWave.
tn=@(t) tan(2*pi*f*t); %TanWave.
rt=@(t) t; %ramp.
syn=@(t) sinc(2*pi*f*t); %Sinc.
sng=@(t) 2*u(t)-1; %Signum.
%ploting
r=3; %subplot rows
c=4; %subplot column
subplot(r,c,1)
plot(t,u(t));
title('unit step');
subplot(r,c,2)
plot(t,sn(t));
title('sine');
subplot(r,c,3)
plot(t,cs(t));
title('cosine');
subplot(r,c,4)
plot(t,tn(t));
title('tan');
subplot(r,c,5)
plot(t,rt(t));
title('ramp');
subplot(r,c,6)
plot(t,syn(t));
title('sinc');
subplot(r,c,7)
plot(t,d(t));
title('impulse');
subplot(r,c,8)
plot(t,sng(t));
title('signum');
subplot(r,c,[10,11])
plot(t,x(t));
title('rect using unit step');
The output of the code after execution is shown in the figure below:-
