Documente Academic
Documente Profesional
Documente Cultură
(MATLAB Programs)
Tejhas Kapoor
Batch: ECE-E
Theory: -
Some of the basic functions are as follows: -
1, =0
(t) =
0, 0
1, >0
u (t) =
0, <0
3. Ramp Signal
A continuous time ramp type signal is denoted by r(t). Its
value increases linearly with sample number n. mathematically it is defined as,
, 0
r (t) =
0, <0
4. Sinusoidal Signal
The sinusoidal signals include sine and cosine signals.
Mathematically they can be expressed as follows:
A sine signal: ( ) = ( ) = (2 )
A cosine signal: ( ) = ( ) = (2 )
5. Exponential Signal
A real exponential signal is defined as: -
( )=
The case a > 0 represents exponential growth. Some signals in unstable systems
exhibit exponential growth.
The case a < 0 represents exponential decay. Some signals in stable systems exhibit
exponential decay.
Code
t =-20:20;
t1 =-5:0.01:5;
t2 =-5:5;
unit_imp = [zeros(1,20),1,zeros(1,20)];
unit_step = [zeros(1,20),ones(1,21)];
i=1;
for k=-20:20
if (k>0)
ramp(i) = k;
else
ramp(i) = 0;
end
i = i+1;
end
expo = exp(-t2);
sinu = sin(t1);
subplot(3,2,1);
stem(t,unit_imp);
xlabel('Time');
ylabel('Unit Impulse signal');
grid on;
subplot(3,2,2);
stem(t,unit_step);
xlabel('Time');
ylabel('Unit Step signal');
grid on;
subplot(3,2,3);
plot(t,ramp);
xlabel('Time');
ylabel('Ramp signal');
grid on;
subplot(3,2,4);
plot(t2,expo);
xlabel('Time');
ylabel('Exponential signal') ;
grid on;
subplot(3,2,5)
plot(t1,sinu);
xlabel('Time');
ylabel('Sinusoidal Signal');
grid on;
Output
Experiment No. 2
Aim: Write a MATLAB code to perform arithmetic operations
for a signal such as addition, subtraction, multiplication and
division.
Theory:-
The theoretical results of various arithmetic operations such as
addition,multiplications, subtraction of two signals (say sine wave and ramp signal).
Let us consider two signals
x(t)=sin(wt)
y(t)-cos(wt)
Signal processing operation on dependent variable is of the following types:
1) Addition z(t)=x(t)+y(t) =sin(wt)+cos(wt)
2)Subtraction z(t) =x(t)-y(t) =sin(wt)-cos(wt)
3) Multiplication z(t)=x(t)*y(t) =sin(wt)*cos(wt)
4) Division z(t)=x(t)/y(t);y(t)0 =sin(wt)/cos(wt)
Code
t =-5:0.1:5;
x = sin(t);
y= cos(t);
x_addition = x+y;
x_division = x./y;
x_multiplication = x.*y;
x_subtraction = x-y;
grid on;
subplot(2,3,1);
plot(t,x); grid on;
xlabel('Time');
ylabel('Original Signal');
subplot(2,3,2);
plot(t,x_addition);
grid on;
xlabel('Time');
ylabel('Added Signal');
subplot(2,3,3);
plot(t,x_division);
grid on; xlabel('Time');
ylabel('Divided Signal');
subplot(2,3,4);
plot(t,x_multiplication);
grid on; xlabel('Time');
ylabel('Multiplied Signal');
subplot(2,3,5);
plot(t,x_subtraction);
grid on;
xlabel('Time');
ylabel('subtracted Signal');
Output
Experiment No. 3
Aim: Write a program to perform time shifting, scaling and
reversal operation on a sinusoidal signal
Theory:-
1. Time Shifting Operation
Time shifting of signals is probably the most important one, and
most widely used amongst all basic signal operations. Its generally used to fast-
forward or delay a signal, as is necessary in most practical circumstances.
Where, X(t) is the original signal, and t0 represents the shift in time.
For a signal X(t) if the position shifts t0> 0. Then the signal is said to be right shifted
or delayed.
In the same manner, if t0< 0, implies the signal is left shifted or fast forward.
Where, X(t) is the original signal, and is the scaling factor. If > 1 implies, the
signal is compressed. And < 1 implies, the signal is expanded.
3. Reversal Operation
Reversal of signal is a very interesting operation applicable
on both continuous and discrete signals. Here in this case the vertical axis acts as
the mirror, and the transformed image obtained is exactly the mirror image of the
parent signal.
The convolution of f and g is written fg, using an asterisk or star. It is defined as the
integral of the product of the two functions after one is reversed and shifted. As such,
it is a particular kind of integral transform:
y(t)=x(t)h(t)y(t)=x(t)h(t)
=x()h(t)d
(or)
=x(t)h()d
While the symbol t is used above, it need not represent the time domain.
Discrete Convolution
y(n)=x(n)h(n)y(n)=x(n)h(n)
=k=x(k)h(nk)=k=x(k)h(nk)
(or)
=k=x(nk)h(k)=k=x(nk)h(k)
By using convolution we can find zero state response of the system.
Code
x=[1 2 3];
h=[4 5 6];
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y
stem(Y);
ylabel('Y[n]');
xlabel('----->n');
title('Convolution of Two Signals without conv function');
Output
Experiment No. 5
Theory:-
LTI stands for Linear Time Invariant system. As the name suggests this type of system
is Linear as well as Time Invariant. It investigates the response of a linear and time-
invariant system to an arbitrary input signal. A continuous-time LTI system is usually
illustrated like this:
In general, the system HH maps its input signal x(t)x(t) to a corresponding output
signal y(t)y(t). The system is linear, so it obeys the principle of superposition. That is,
if x1(t) maps to an output of y1(t) and x2(t) maps to an output of y2(t)y2(t), then for all
values of a1 and a2,
The system is time-invariant, so its characteristics do not change with time. If you add
a delay to the input signal, then you simply add the same delay to the output. For an
input signal x(t) that maps to an output signal y(t), then for all values of ,
H{x(t)} = y(t)
The impulse that is referred to in the term impulse response is generally a short-
duration time-domain signal. A system's impulse response (often annotated
as h(t)h(t) for continuous-time systems or h[n]h[n] for discrete-time systems) is defined
as the output signal that results when an impulse is applied to the system input.
Code
t = 0:0.01:10;
x = sin(t);
h = [ones(1,1001)];
Lx =length(x);
Lh = length(h);
Ly = Lx + Lh-1;
for p=1:Ly
sum=0;
for k=1:p
if(k<=Lx && k>=(p+1-Lh))
sum = sum + x(k).*h(p+1-k);
end
end
y(p) = sum;
end
t1 = 0:0.01:(Ly-1)*0.01;
subplot(2,2,1);
plot(t,x);
title('Input Signal');
xlabel('Time');
ylabel('Amplitude of the signal');
grid on;
subplot(2,2,2);
plot(t,h);
title('Impulse Response');
xlabel('Time');
ylabel('Amplitude of the signal');
grid on;
subplot(2,2,[3:4]);
plot(t1,y);
title('Output of the LTI System');
xlabel('Time');
ylabel('Amplitude of the signal');
grid on;
Output
Experiment No. 6
Aim: Write a MATLAB code to generate Fourier transform of a
given Input signal and plot its Magnitude and Phase spectra.
Theory:-
X(t) = Fourier transform of a signal can be obtained by using FFT function in MATLAB.
The plot of X(W) vs. w is called as magnitude spectra And angle of X(W) vs. w is known
as phase spectra.
Code
t=0:0.1:2;
y=sin(t);
X=fft(y,21);
magx=abs(X);
phasex=angle(X)*(180/pi);
subplot(2,1,1);
stem(t,magx);
title('magnitude spectra')
ylabel('magnitude');
xlabel('n');
grid on;
subplot(2,1,2);
stem(t,phasex);
title('phase spectra');
ylabel('angle in degrees');
xlabel('n');
grid on;
Output
Experiment No. 7
AIM: Write a MATLAB code to generate frequency spectrum of a
periodic signal.
Theory:-
The plot of X(W) vs. w is called as magnitude spectra And angle of X(W) vs. w is known
as phase spectra. These two spectra together are knows as the frequency spectra,
where X(W) = Fourier Transform of periodic signal x(t).
Code
t=0:0.1:2;
y=sin(t);
X=fft(y,21);
magx=abs(X);
phasex=angle(X)*(180/pi);
subplot(2,1,1);
stem(t,magx);
title('magnitude spectra')
ylabel('magnitude');
xlabel('n');
grid on;
subplot(2,1,2);
stem(t,phasex);
title('phase spectra');
ylabel('angle in degrees');
xlabel('n');
grid on;
Output