MAT LAB CODING
Generation of a Unit Sample Sequence
In Put Out Put
clf;
n=-10:20;
%Generate a vector from -10 to 20
% Generate the unit sample sequence
% Plot the unit sample sequence
%Generate a vector from -10 to 20
% Generate the unit sample sequence
% Plot the unit sample sequence
u=[zeros(1,10) 1 zeros(1,20)];
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
Generation of a complex exponential sequence
Input
clf;
c=-(1/12)+(pi /6)*i;
K=2;
n=0:40;
x=K*exp(c*n);
subplot(2,1,2);
stem(n,real(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Real part');
subplot(2,1,1);
stem(n,imag(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Imaginary part');
Output
Generation of a real exponential sequence
Input
clf;
n=0:25;
a=1.2;
K=0.2;
x=K*a.^n;
stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
Output
Generation of a sinusoidal sequence
Input
n=0:40;
f=0.1;
phase=0;
A=2;
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 50 -3 2]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
Output
Study the CT (continuous time) and DT (discrete time) sine signal :
MATLAB command for continuous time sine signal:
A=4;
a=20*pi;
phi=pi/6;
t=0:.001:1;
sine=A*sin(a*t+phi);
plot(t,sine)
Out Put:
MATLAB command for discrete time sine signal:
Mat Lab Code:
A=1;
omega=2*pi/12; % angular frequency
n=-10:10;
y=A*sin(omega*n);
stem(n,y)
Out Put:
Study the CT (continuous time) and DT (discrete time) cosine signal
MATLAB command for continuous time cosine signal:
Mat Lad Code:
A=4;
a=20*pi;
phi=pi/6;
t=0:.001:1;
cosine=A*cos(a*t+phi);
plot(t,cosine)
Out Put:
MATLAB command for discrete time cosine signal:
Mat Lab Code:
A=1;
omega=2*pi/12; % angular frequency
n=-10:10;
y=A*cos(omega*n);
stem(n,y)
Out Put:
Generate periodic signals (square waves and triangular waves), exponential signals, sinusoidal signals, exponentially damped signals with MATLAB. To visualize the discrete time signal use stem command.
Periodic signal:
A periodic signal x (t) is a function of time that satisfies the condition –
x (t) =x (t + T) .............(1) for all t,
Where T is a constant. Clearly, if this condition is satisfied for T = T0 ,say, then it is also satisfied for T = 2T0, 3T0, 4T0,...... The smallest value of T that satisfies the eq-1 is called the fundamental period of x (t). Accordingly, the fundamental period T defines the duration of one complete cycle of x (t). The reciprocal of the fundamental period T is called the fundamental frequency of the periodic signal x (t); it describe how frequently the periodic signal x (t) repeats itsself. we thus formally write-
f = 1/T
The frequency f is measured in hertz or cycle per second. The angular frequency, measured in radians per second, is defined by-
ω = 2πf = 2π/T
Example of periodic signal:
Continuous time Square wave
MAT LA Bcommand:
>>A=2;
>>w = 10*pi;
>>rho = 0.5;
>>t = 0: .001: 1;
>>sq=A*square (w * t , rho );
>>plot (t , sq )
Description:
Here
A= Amplitude of the signal
w = Fundamental frequency (measured in radians/second)
rho = Duty cycle
t = 0 : .001 : 1
Time interval = 0 to 1 second
Sampling interval = .001 second
plot (t , sq ) is for to plot a continuous time signal
Discrete time square wave
MAT LAB command:
>>A =1;
>>0mega = pi/4;
>> n= -10:10;
>> x = A* square (omega * n);
>> stem (n , x )
Triangular wave
MAT LA Bcommand:
>>A = 1;
>>w0 =10*pi;
>>w =0.5;
>>t =0 : .001 : 1;
>>tri =A*sawtooth (w0*t ,w);
>>plot (t ,tri )
Discrete time triangular wave
MAT LA Bcommand:
>>A =1;
>>0mega = pi/18;
>> n= -20:20;
>> x = A* sawtooth (omega * n);
>> stem (n , x )
Exponential signal:
MAT LAB commands for decay exponential signal( x(t) = 5 e-at ):
>>B = 5;
>>a = 6;
>>t = 0 : .001 : 1;
>>x = B*exp (-a*t );
>>plot (t ,x )
MAT LA Bcommand for discrete time decay exponential signal:
>>B = 1;
>>r = 0.85;
>>n = -10 :10;
>>x = B*r. ^ n;
>>stem (n , x )
Note that , in this example , the base r is a scalar but the exponent is a vector. Hence the use of the symbol .^ to denote element by element power.
MAT LABcommand for growing exponential signal (x(t) = 5eat):
>>B = 1;
>>a = 5;
>>t =0 : .001 : 1;
>>x = B*exp( a*t );
>>plot( t ,x )
Here B and a are real parameters. The parameter B is the amplitude of the exponential signal measured at the time t = 0.
MAT LABcommand for discrete time growing exponential signal:
>>B = 1;
>>r = 0.85;
>>n = -10 :10;
>>x = B*r. ^ -n;