Experiment No.
5: Signal plotting functions and Fourier Transform
Objective
• To understand various signal plotting functions to plot and visualise different
periodic or aperiodic signals
• To understand and visualize Fourier transform, properties of sinc function,
parseval’s theorem and essential bandwidth along with their MATLAB
implementation.
Use of Inline Function:
Many simple functions are most conveniently represented by using MATLAB inline
objects. An inline object provides a symbolic representation of a function defined in
terms of MATLAB operators and functions. Look at the following examples:
clear all
close all
x = inline('exp(-t).*cos(2*pi*t)','t'); % exponentially damped sinusoid
t= 0:.01:10;
figure(1)
plot(t,x(t),'linewidth',2);
grid on
u = inline('(t>=0)','t'); % unit step function
t= -5:0.01:5;
figure(2)
plot(t,u(t),'linewidth',2)
grid on
figure(3)
plot(t,u(t-1),'linewidth',2)
grid on
Plotting periodic signal using MOD command:
Type ‘doc mod’ on your command window and try to fathom its insight.
clear all;
close all;
p=inline(['mod(t,1)*4.*(mod(t,1)<1/4) +', '((mod(t,1)*(-
4))+2).*((mod(t,1)>=1/4)&(mod(t,1)<3/4))+','((mod(t,1)*4)-
4).*((mod(t,1)>=3/4)&(mod(t,1)<1))'],'t');
t=0:.001:2;
plot(t,p(t),'linewidth',2)
grid on
Fourier Transform:
The sinc function:
The Sinc Function and the scaling property:
Matlab Code
At first write the following code to generate the function named sinc: Now write the
following codes in a new M file and try to observe the scaling property of the sinc
function:
function [y]= sinc(x)
y=ones(size(x));
i=find(x~=0);
y(i)=sin(x(i)*pi)./(x(i)*pi);
end
clear all;
close all;
X = @(omega,tau) tau*sinc(omega*tau/(2*pi));
omega=linspace(-4*pi,4*pi,200);
figure(1)
plot(omega,X(omega,1),'k-',omega,X(omega,.5),'k:',omega,X(omega,2),'k--');
grid on;
axis tight;
xlabel('\omega');
ylabel('X(j\omega)');
legend('Baseline(\tau = 1)','Compressed(\tau = 0.5)','Expanded(\tau = 2.0)');
Parseval’s theorem for Fourier Transform:
The Parseval relationships state that the energy or power in the time-domain representation of a
signal is equal to the energy or power in the frequency-domain representation. Now, according
to Parseval’s theorem we can write,
To verify Parseval’s theorem write down the following MATLAB codes:
clear all;
close all;
X_w = @(omega,tau) (1/(2*pi))*(tau*sinc(omega*tau/(2*pi))).^2;
integral(@(omega) X_w(omega,1),-1e4,1e4)
Measurement of Essential Bandwidth:
Essential Bandwidth:
The following program will find out the essential bandwidth W in radians per second, that
contains fraction of the energy of the square pulse x(t).
function [W,E_W] = BW(Etot,alpha,tol)
% input arguments :
% Etot = Total Energy
% alpha = Multiplying factor
% tol = Error tolerance
% output arguments:
% W = Essential bandwidth in radians per second
% E_W = % of Total Energy
W=0 ;
tau = Etot;
step=2*pi/tau;
X_w = @(omega,tau) (1/(2*pi))*(tau*sinc(omega*tau/(2*pi))).^2;
E= alpha*Etot;
relerr= (E-0)/E;
while(abs(relerr)> tol)
if(relerr > 0)
W = W+step;
elseif (relerr <0)
step = step/2;
W=W-step;
end
E_W = integral(@(omega) X_w(omega,tau),-W,W);
relerr = (E-E_W)/E;
end
E_W = (E_W/Etot)*100;
end
Assignment: