6/06/18 9:16 PM C:\Users\dhruv\OneDrive\Docu...\lab3.
m 1 of 3
clear all
%setting variables
Fs = 100e3;
Ts = 1/Fs;
N = 1024;
T = N*Ts;
fo = 1/T;
t = 0:Ts:T-Ts;
f = -Fs/2:fo:Fs/2-fo;
freq1=725;
freq2=10500;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%s(t) square wave, f=725Hz [Time Domain]
st = square(2*pi*freq1*t);
figure(1)
subplot(211)
plot(t,st)
xlabel('Time (sec)')
ylabel('Amplitude')
title('Square Wave 725Hz s(t) [Time Domain] ')
axis([0e-3 10e-3 -4 4])
grid
%s(f) square wave, f=725Hz [Frequency Domain]
sf=fftshift(fft(st))/length(t);
figure(1)
subplot(212)
plot(f,20*log10(abs(sf)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
title('Square Wave 725Hz s(f) [Frequency Domain]' )
axis([0 25000 -80 0])
grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%g(t) - output of square wave through a 3kHz Low Pass Filter (LPF) [Time Domain]
[b,a]=ellip(5,0.1,50,3000/(Fs/2));
gt=[filter(b,a,st)];
figure(2)
subplot(211)
plot(t,gt)
xlabel('Time (sec)')
ylabel('Amplitude')
title('Filtered Square Wave g(t) [Time Domain]')
axis([0e-3 10e-3 -4 4])
grid
%g(f) - output of square wave through a 3kHz Low Pass Filter (LPF) [Frequency
Domain]
gf=fftshift(fft(gt))/length(t);
figure(2)
subplot(212)
plot(f,20*log10(abs(gf)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
title('Filtered Square Wave g(f) [Frequency Domain]' )
6/06/18 9:16 PM C:\Users\dhruv\OneDrive\Docu...\lab3.m 2 of 3
axis([0 25000 -80 0])
grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%gam(t) - output of g(t) x l1(t) [Time Domain]
gamt=[2*cos(2*pi*freq2*t)].*gt*0.5;
figure(3)
subplot(211)
plot(t,gamt)
xlabel('Time (sec)')
ylabel('Amplitude')
title('Multiplied Signal - gam(t) x l1(t) [Time Domain]' )
axis([0e-3 10e-3 -4 4])
grid
%gam(f) - output of g(t) x l1(t) [Frequency Domain]
gamf=fftshift(fft(gamt))/length(t);
figure(3)
subplot(212)
plot(f,20*log10(abs(gamf)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
title('Multiplied Signal - gam(f) x l1(f) [Frequency Domain]' )
axis([0 25000 -80 0])
grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%gam2(t) - output of gam(t) x l2(t) [Time Domain]
gam2t=[2*cos(2*pi*freq2*t)].*gamt*0.5;
figure(4)
subplot(211)
plot(t,gam2t)
xlabel('Time (sec)')
ylabel('Amplitude')
title('Multiplied Signal – gam2(t) x l2(t) [Time Domain]' )
axis([0e-3 10e-3 -4 4])
grid
%gam2(f) - output of g(f) x l1(f) [Frequency Domain]
gam2f=fftshift(fft(gam2t))/length(t);
figure(4)
subplot(212)
plot(f,20*log10(abs(gam2f)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
title('Multiplied Signal – gam2(f) x l2(f) [Frequency Domain]' )
axis([0 25000 -80 0])
grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%gn(t) - Reconstructed Signal gn(t) [Time Domain]
[b,a]=ellip(5,0.1,50,5000/(Fs/2));
gnt=[filter(b,a,gam2t)];
figure(5)
subplot(211)
plot(t,gt)
xlabel('Time (sec)')
ylabel('Amplitude')
6/06/18 9:16 PM C:\Users\dhruv\OneDrive\Docu...\lab3.m 3 of 3
title('Reconstructed Signal gn(t) [Time Domain]')
axis([0e-3 10e-3 -4 4])
grid
%gn(f) - Reconstructed Signal gn(f) [Frequency Domain]
gnf=fftshift(fft(gnt))/length(t);
figure(5)
subplot(212)
plot(f,20*log10(abs(gnf)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
title('Reconstructed Signal gn(f) [Frequency Domain]' )
axis([0 25000 -80 0])
grid