6/06/18 9:16 PM C:/Users/Dhruv/Onedrive/Docu... /Lab3.M 1 of 3
6/06/18 9:16 PM C:/Users/Dhruv/Onedrive/Docu... /Lab3.M 1 of 3
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