%Project 2, Part B

clear all;
close all;

Fs=11025;
f0=180;

%Total # of samples in one pulse
N0=round(1/f0*Fs);

%This gives the 4:1 ratio and 50% duty cycle
N1=round(.4*N0);
N2=round(1/4*N1);

pulse =[.5*(1-cos(pi*(1:N1)/N1)),cos(pi*((N1:N1+N2)-N1)/(2*N2)),zeros(1,N0-(N1+N2)-1)];

%Get 6 periods of the pulse
periodicPulse = repmat(pulse,1,6);

t = linspace(0,length(periodicPulse)/Fs,length(periodicPulse));

figure(1)
plot(t,periodicPulse)
title('Glottal Pulse with a Fundamental Frequency of 180 Hz');
xlabel('Time (sec)'),ylabel('Amplitude'), grid on, axis tight;

[P,w]=freqz(periodicPulse,1,512);

figure(2)
plot(w/pi,db(abs(P)))
title('Glottal Pulse Magnitude Spectrum'),grid on, axis tight;
xlabel('Normalized Frequency \omega/\pi'), ylabel('Magnitude (dB)')