Professional Documents
Culture Documents
0;t0
0; t<0
IV exponential function
0 ; t<0
There can be different cases in which a value differences.
Program 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);
subplot(3,2,2);
stem(t,unit_step);
xlabel('Time');
ylabel('Unit Step signal');
grid on;
subplot(3,2,3);
stem(t,ramp);
xlabel('Time');
ylabel('Ramp signal');
grid on;
subplot(3,2,4);
stem(t2,expo);
xlabel('Time');
ylabel('Exponential signal')
grid on;
Observation/Plot
subplot(2,3,1);
plot(t,x);
grid on;
xlabel('Time');
ylabel('Original Signal');
subplot(2,3,2);
plot(t,x_addition);
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');
Observation/Plot
OBJECTIVE: -Write a MATLAB code to perform signal processing operations time scaling
time shifting time inversion.
Hardware/Software required:-
1) MATLAB version7.6
2) Computer
3) Printer
Theory:-
Various signal processing operation that can be performed on a signal are:-
x(t)=
0 3
Time inversion: -if x (t) is the original signal then x (-t) is the time inverted signal.
-3 0
Time scaling: - if x (t) is a given signal then x(t) is time scaled by a is given below;
0 1
Time shifting:- if x(t) is a given signal then x(t) is time shifted by t 0 can be obtained
Delayed x(t-t0 )
0 t0 3-to
t0+2 0 1
%Time Scaling
k = input('Enter the value by which you want to scale the signal (compress or elongate) -> ');
Xsc = sin(k*w*t);
%Time Shifting
t1 = input('Enter the value of time by which you want to advance (enter positive value) OR delay
(enter negative value) the signal ->');
Xsh = sin(w*(t-t1));
%Time Inversion
Xin = sin(-w*t);
Or
Program Code:
a=[1 2 3];
b=[4 5 6];
i=length(a);
j=length(b);
A=[a,zeros(1,i)];
B=[b,zeros(1,j)];
for k=1:i+j-1
y(k)=0;
for l=1:i
if (k-l+1>0)
y(k)=y(k)+A(l)*B(k-l+1);
else
end
end
end;
stem (y);
ylabel('Y[k]');
xlabel('----->n');
title('convolution of two signals');
OBJECTIVE:-Write a matlab code to determine the LTI response of a given Input signal.
Hardware/Software required:-
2) Computer
3) Printer
m=length (x); n=length (h) the vector y is of length m+n-1, where kth element is
t = 0:0.01:10;
x = exp(-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);
%Input Signal
subplot(2,2,1);
plot(t,x);
title('Input Signal');
xlabel('Time'); ylabel('Amplitude of the signal');
%Impulse Response
subplot(2,2,2);
plot(t,h);
title('Impulse Response');
xlabel('Time'); ylabel('Amplitude of the signal');
Observation/Plot
OBJECTIVE:- Write a matlab code to generate Fourier transform of a given Input signal and
plot its Magnitude and Phase spectra.
Hardware required/software required:-
1) MATLAB version 7.6
2) Computer
3) Printer
Theory:-Fourier transform is divided into 2 parts
Continuous time Fourier transform
This is applicable for aperiodic function and periodic functions
x =[1,1,1,1,zeros(1,4)];
n=8;
X= fft(x,n);
magx= abs(X);
phase=angle(X)*180/pi;
subplot(2,2,1);
plot(x,'k');
xlabel('n');
ylabel('Signal');
title('Input signal');
Observation/Plot
The fundamental period T0 of x (t) is the smallest positive value of T for which equation (1) is
not satisfied and 1/t0=f0 is referred as fundamental frequency.
Two basic example of periodic signal are the real sinusoidal signal
The complex exponential Fourier series representation of a periodic signal x(t) with To as
fundamental period
wo=2/To
Where are the complex Fourier Coefficients
t = 0:0.01:10;
%Train of Pulses
x = [ones(1,201),zeros(1,99),ones(1,201),zeros(1,99),ones(1,201),zeros(1,99),ones(1,101)];
T = 3;
w = 2*pi/T;
exp_part = exp(-j*w*k*tau)*dtau;
sum = sum + exp_part.*x(i);
i=i+1;
end
a(k+11) = sum;
end
for i=1:21
mag(i) = abs(a(i));
phase(i) = angle(a(i));
end
k=-10:10;
%Original Signal
subplot(2,2,[1:2]);
plot(t,x);
title('Input Signal (A Pulse Train)');
xlabel('Time');
ylabel('Amplitude of the signal');
%Magnitude Spectra
subplot(2,2,3);
stem(k,mag);
title('Magnitude Spectra');
xlabel('k \rightarrow');
ylabel('Magnitude');
%Phase Spectra
subplot(2,2,4);
stem(k,phase,'Linewidth',1.2)
title('Phase spectra');
xlabel('k \rightarrow');
ylabel('Phase');
Hardware/Software Requirements:
1) MATLAB version 7.6
2) Computer/Laptop
2) Printer
Theory:- Inverse Fourier transform is used to convert a signal in frequency domain to a signal in
time domain.
If X(w) is the Fourier transform of a signal then, the original signal x(t) or inverse Fourier
transform of X(w) is given by:-
In MATLAB, we can use a direct command to evaluate the inverse Fourier transform i.e.
d=ifft(x);
Program Code: (Example)
w=-100:.1:100;
X = 1./(1+w.^2)
dw = 0.1;
m=1;
for t=0:0.01:10
i=1;
sum=0;
for w=-100:dw:100
sum = sum + X(i)*exp(j*w*t)*dw;
i=i+1;
end
x(m) = sum;
m=m+1;
end
w=-100:.1:100;
t=0:.01:10;
%given signal
subplot(2,1,1);
plot(w,X);
title('Given signal in Frequency domain');
xlabel('Frequency \rightarrow');
ylabel('X(w)');
grid on;
Observation/Plot
OBJECTIVE:-Write a Matlab code to perform and plot the Frequency response and Phase
response of FIR system.
Hardware/Software Required:-
1) MATLAB version 7.6
2) Computer
3) Printer
Theory:- [h,p]=-freqz(ba,a,w) returns the frequency response vector h and the corresponding
angular frequency vector for the digital filter whose transfer function is determined by the (real
or complex) numerator and denominator polynomial represented by the vector b and a
respectively. The vector h and p are both of length w has values ranging from 0 to pi per sample.
Observation/Plot
OBJECTIVE:-Write a Matlab code to perform and plot the frequency response and phase
response of IIR system.
Hardware/Software Required:-
1) MATLAB version 7.6
2) Computer
3) Printer
Theory:- a system whose impulse response or no. of non zero values of the output is infinite is
called infinite impulse response IIR system.
Let x (t) be the input signal. Let h(t) be the impulse response &Let y(t) be the response of the
system.
Taking Fourier transform, of the three. We get X (w), Y(w) &h(w)
Y (t)=x(t)*h(t)
Taking Fourier transform
Y(w)=X(w)H(w)
H (w)=Y(w)/X(w)
H (w) is called frequency response of system.
Program Code: (Example)
h1=(0.5)^n;
a=[1,-0.5];
b=[1];
w=-pi:.01:pi;
[h,p]=freqz(b,a,h);
Observation/Plot
OBJECTIVE:-Write a Matlab code to plot poles &zeros of the given Z transform of signal.
Hardware/Software Required:-
1) MATLAB version 7.6
2) Computer
3) Printer
THEORY:- A pole-zero plot shows the location in the complex plane of the poles and zeros of
the transfer function of a dynamic system, such as a controller, compensator, sensor, equalizer,
filter, or communications channel. By convention, the poles of the system are indicated in the
plot by an X while the zeroes are indicated by a circle or O.A pole-zero plot can represent either
a continuous-time (CT) or a discrete-time (DT) system. For a CT system, the plane in which the
poles and zeros appear is the s plane of the Laplace transform. In this context, the
parameter s represents the complex angular frequency, which is the domain of the CT transfer
function. For a DT system, the plane is the z plane, where z represents the domain of the Z-
transform. This function displays the poles and zeros of discrete-time systems.
zplane(b,a) where b and a are row vectors, first uses roots to find the zeros and poles of the
transfer function represented by numerator coefficients b and denominator coefficients a. The
transfer function is defined in terms of z-1:
Zplane (b,a) plots the zeros specified in column vector b and the poles specified in column vector
a in the current figure window. The symbol 'o' represents a zero and the symbol 'x' represents a
pole. The plot includes the unit circle for reference. If z and p are arrays, zplane plots the poles
and zeros in the columns of z and p in different colors.
Program Code: (Example)
b= [1 0 0 -8];
a= [1 0 -1];
Zplane (b, a);
Observation/Plot