Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

%Essential_BW_Ex2 % Plot ESD and calculate essential bandwidth of a signal, x(t)

ID: 2290974 • Letter: #

Question

%Essential_BW_Ex2
% Plot ESD and calculate essential bandwidth of a signal, x(t), sampled at
% intervals of dt;
%The example done here is for a signal, x(t) = exp(-2t), but it can be
%easiloy modified for any arbitrary signal, or converted into a function call
%for an arbitrary signal
clc;close all;

%Create sampled x(t)=exp(-t)u(t);
dt=0.01;Fs=1/dt;
t = [0:dt:5];
x = exp(-2*t);

%Compute and plot ESD
Nfft = 2^(nextpow2(length(x))+2); %Choose a FFT size, N = (Nearest power of 2) greater than length of x(t)
Xf = (1/sqrt(Nfft))*fft(x,Nfft); %Note: Normalization by sqrt(N) is necessary to satisfy Parseval's relation for DFT
Xf2 = abs(Xf).^2; %Xf2 = Energy spectral density of x(t)
freq = [0:(Nfft/2)-1]*Fs/Nfft; %This creates a vector of fequency points
EXf = sum(Xf2); %Exf = Energy using freq-domain integration of ESD
figure(1)
subplot(211)
plot(freq,Xf2(1:Nfft/2));title('Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')
subplot(212)
plot(freq(1:1000),Xf2(1:1000));title('Low frequency section of Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')

%Compute and print Essential BW of a desired percentage
p = input('Enter desired percentage of Essential Bandwidth = ');
pEXf = (p/100)*EXf;
PartialSum_Xf2=0;
for k = 1:Nfft/2
if (k==1)
PartialSum_Xf2 = PartialSum_Xf2 + Xf2(k); %Note: k=1 represents zero frequency or DC value
else
PartialSum_Xf2 = PartialSum_Xf2 + 2*Xf2(k); %Note: ESD is a symmetric function of frequency
end
if (PartialSum_Xf2 >= pEXf)
break
end
end
Essential_BW_in_Hz = freq(k)

Attached find a Matlab program, Essential_BW_Ex2, that uses Matlab's Fast Fourier Transform (fft) function to compute the energy spectral density (ESD) and Essential Bandwidth (of desired percentage) for a signal, x(t)- e2u(t). Please run it and enter a percentage (such as, 90) from the keyboard to see how it works. Then do the following parts a) Modify this program to find the 90% Essential BW of a rectangular pulse, x(t)-u(A)-?(t-4), or equivalently, rect(t-3.5). Next repeat it for x(t)- u(t-3)-u(t-3.25). Do the results match what you would expect from theory? b) Modify it to find the 90% Essential BW of a triangular pulse, x(t) ?(t-3.5). Note: This Matlab function has been posted on Moodle and emailed to you]

Explanation / Answer

code for x(t) = u(t-3)-u(t-4)

----------------------------------------------

%Essential_BW_Ex2
% Plot ESD and calculate essential bandwidth of a signal, x(t), sampled at
% intervals of dt;
%The example done here is for a signal, x(t) = exp(-2t), but it can be
%easiloy modified for any arbitrary signal, or converted into a function call
%for an arbitrary signal
clc;close all;
syms t
%Create sampled x(t)=exp(-t)u(t);
dt=0.01;Fs=1/dt;
t = [0:dt:5];
x = heaviside(t-3)-heaviside(t-4);

%Compute and plot ESD
Nfft = 2^(nextpow2(length(x))+2); %Choose a FFT size, N = (Nearest power of 2) greater than length of x(t)
Xf = (1/sqrt(Nfft))*fft(x,Nfft); %Note: Normalization by sqrt(N) is necessary to satisfy Parseval's relation for DFT
Xf2 = abs(Xf).^2; %Xf2 = Energy spectral density of x(t)
freq = [0:(Nfft/2)-1]*Fs/Nfft; %This creates a vector of fequency points
EXf = sum(Xf2); %Exf = Energy using freq-domain integration of ESD
figure(1)
subplot(211)
plot(freq,Xf2(1:Nfft/2));title('Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')
subplot(212)
plot(freq(1:1000),Xf2(1:1000));title('Low frequency section of Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')

%Compute and print Essential BW of a desired percentage
p = input('Enter desired percentage of Essential Bandwidth = ');
pEXf = (p/100)*EXf;
PartialSum_Xf2=0;
for k = 1:Nfft/2
if (k==1)
PartialSum_Xf2 = PartialSum_Xf2 + Xf2(k); %Note: k=1 represents zero frequency or DC value
else
PartialSum_Xf2 = PartialSum_Xf2 + 2*Xf2(k); %Note: ESD is a symmetric function of frequency
end
if (PartialSum_Xf2 >= pEXf)
break
end
end
Essential_BW_in_Hz = freq(k)

----------------------------------------------------------------

command Window:

Enter desired percentage of Essential Bandwidth = 90

Essential_BW_in_Hz =

0.7813

------------------------------------------------------------------------------------

code for x(t) =u(t-3)-u(t-3.25)

----------------------------------------------------------------

%Essential_BW_Ex2
% Plot ESD and calculate essential bandwidth of a signal, x(t), sampled at
% intervals of dt;
%The example done here is for a signal, x(t) = exp(-2t), but it can be
%easiloy modified for any arbitrary signal, or converted into a function call
%for an arbitrary signal
clc;close all;
syms t
%Create sampled x(t)=exp(-t)u(t);
dt=0.01;Fs=1/dt;
t = [0:dt:5];
x = heaviside(t-3)-heaviside(t-3.25);

%Compute and plot ESD
Nfft = 2^(nextpow2(length(x))+2); %Choose a FFT size, N = (Nearest power of 2) greater than length of x(t)
Xf = (1/sqrt(Nfft))*fft(x,Nfft); %Note: Normalization by sqrt(N) is necessary to satisfy Parseval's relation for DFT
Xf2 = abs(Xf).^2; %Xf2 = Energy spectral density of x(t)
freq = [0:(Nfft/2)-1]*Fs/Nfft; %This creates a vector of fequency points
EXf = sum(Xf2); %Exf = Energy using freq-domain integration of ESD
figure(1)
subplot(211)
plot(freq,Xf2(1:Nfft/2));title('Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')
subplot(212)
plot(freq(1:1000),Xf2(1:1000));title('Low frequency section of Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')

%Compute and print Essential BW of a desired percentage
p = input('Enter desired percentage of Essential Bandwidth = ');
pEXf = (p/100)*EXf;
PartialSum_Xf2=0;
for k = 1:Nfft/2
if (k==1)
PartialSum_Xf2 = PartialSum_Xf2 + Xf2(k); %Note: k=1 represents zero frequency or DC value
else
PartialSum_Xf2 = PartialSum_Xf2 + 2*Xf2(k); %Note: ESD is a symmetric function of frequency
end
if (PartialSum_Xf2 >= pEXf)
break
end
end
Essential_BW_in_Hz = freq(k)

------------------------------------------------------------------------------------

command Window:

Enter desired percentage of Essential Bandwidth = 9

Essential_BW_in_Hz =

0.1953

-----------------------------------------------------------------------------

for x(t) = triangle(t-3.5)

--------------------------------------------------------------------------------

%Essential_BW_Ex2
% Plot ESD and calculate essential bandwidth of a signal, x(t), sampled at
% intervals of dt;
%The example done here is for a signal, x(t) = exp(-2t), but it can be
%easiloy modified for any arbitrary signal, or converted into a function call
%for an arbitrary signal
clc;close all;
syms t
%Create sampled x(t)=exp(-t)u(t);
dt=0.01;Fs=1/dt;
t = [0:dt:5];
x = sawtooth(t-3.5);
%Compute and plot ESD
Nfft = 2^(nextpow2(length(x))+2); %Choose a FFT size, N = (Nearest power of 2) greater than length of x(t)
Xf = (1/sqrt(Nfft))*fft(x,Nfft); %Note: Normalization by sqrt(N) is necessary to satisfy Parseval's relation for DFT
Xf2 = abs(Xf).^2; %Xf2 = Energy spectral density of x(t)
freq = [0:(Nfft/2)-1]*Fs/Nfft; %This creates a vector of fequency points
EXf = sum(Xf2); %Exf = Energy using freq-domain integration of ESD
figure(1)
subplot(211)
plot(freq,Xf2(1:Nfft/2));title('Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')
subplot(212)
plot(freq(1:1000),Xf2(1:1000));title('Low frequency section of Energy spectral density (ESD) of x(t) ')
xlabel('frequency in Hz ');
ylabel('ESD of exp(-2t) ')

%Compute and print Essential BW of a desired percentage
p = input('Enter desired percentage of Essential Bandwidth = ');
pEXf = (p/100)*EXf;
PartialSum_Xf2=0;
for k = 1:Nfft/2
if (k==1)
PartialSum_Xf2 = PartialSum_Xf2 + Xf2(k); %Note: k=1 represents zero frequency or DC value
else
PartialSum_Xf2 = PartialSum_Xf2 + 2*Xf2(k); %Note: ESD is a symmetric function of frequency
end
if (PartialSum_Xf2 >= pEXf)
break
end
end
Essential_BW_in_Hz = freq(k)

-----------------------------------------------------------

command Window

--------------------------------------------------------------

Enter desired percentage of Essential Bandwidth = 9

Essential_BW_in_Hz =

0.0977

------------------------------------------------------------------------