%Demo done during Session 18 demonstrating
%efficacy of FIR Differentiator designed
%via Remez Exchange Algorithm (Parks-McClellan)
clf
set(0,'defaultaxesfontsize',20);
ML=51;
N=256;
hd=remez(ML,[0 1],[0 pi],'differentiator');
hdfft=fftshift(fft(hd,N));
subplot(211)
hdmag=(abs(hdfft));
%hdang=angle(hdfft);
freqomega=linspace(-pi,pi-2*pi/N,N);
Mdel=ML/2;
hdang=angle(exp(j*Mdel*freqomega).*hdfft);
hdrmag=sign(freqomega).*hdmag;
plot(freqomega,hdrmag,'LineWidth',4);
axis([-pi pi -pi pi]);
title('Derivative Response'),...
xlabel('Omega'), ylabel('Magnitude'), grid
subplot(212)
plot(freqomega,hdang,'LineWidth',4);
axis([-pi pi -pi pi]);
title('Hilbert Transform Response')
pause
data = getspeech('enf1s1t0.wav');
Fs=12500;
clf
plot(data)
end1=10000; end2=12000;
end1=input('end1?')
end2=input('end2?')
%del=end2-end1;
datar=data(end1:end2);
yh=conv(datar,hd);
delta=zeros(1,ML);
delta((ML+1)/2)=1;
yd=conv(datar,delta);
e1=800; e2=820;
plot((e1:e2),yh(e1:e2),(e1:e2),yd(e1:e2),'LineWidth',4);
hold on
plot([e1 e2],[0 0],'k','Linewidth',2)
hold off
legend('Derivative','Speech')

