%Part a Solution
clc;
clear all;
close all;
a=4;
F=50;
t = 0:1/F:10-1/F; %time instant
signal_1=exp(-a.*t);%signal 1
signal_2=exp(-a*(abs(t)));%signal 2
signal_3=t.*exp(-a.*t);%signal 3
Ts=mean(diff(t));
Fs=1/Ts;
%%Choose the signal
signal=signal_1;
a = fft(signal); %fourier transform of signal 1
freq = (0:length(a)-1)*50/length(a); %frequency
l = length(signal);
fshift = (-l/2:l/2-1)*(50/l);
yshift = fftshift(a);%for two sided spectrum
plot(fshift,abs(yshift))
title('Magnitude')
power = abs(yshift).^2/l;
plot(fshift,power)
title('Power')
phase=angle(yshift); %phase
%%Part b Solution
y_squared=abs(yshift);
Et=sum(y_squared)*Fs/l;%total energy
Eg=0.9*(Et);% 90 % of the total energy
df = Fs/l; % frequency increment
for i=1:500
E(i)=sum(y_squared(1:i))*Fs/l;
end
for i=1:500
if E(i)<=Eg;
out = i;
end
end
freq_Hz=(50/500)*out;%frequency in Hz.
%%Part c Solution
To design a simple low pass filter with a specified cut off
frequency based on the total energy criterian alone we
will  choose the third signal because the impulse
response of third signal has the highest cut-off frequency