%Matlab file used for class demo conducted during Session 8
%Shows how simple difference equation can remove a tone
%that's corrupting a speech utterance.
clf
clear all
set(0,'defaultaxesfontsize',20);
%these commands read in the speech file
fp=fopen('enf1s1t0.wav','r','b');
[data,length]=fread(fp,[1,1024],'char');
[data,length]=fread(fp,[1,inf],'short');
fclose(fp)
Fs=12500;
%you could plot the speech file if you wanted: plot(data)
input('play back utterance at 12.5 KHz sampling rate');
soundsc(data,Fs)
input('add tone at 3.125 KHz to utterance and play back');
omega0=pi/2;
nc=1:dsize;
x=data+500*cos(omega0*nc);
%plot(x)
soundsc(x,Fs)
%define coefficients for second-order notch filter
r=0.95; c0=2*cos(omega0); rs=r^2; c0r=r*c0;
y(1)=0; y(2)=0;
end1=max(size(x));
for n=3:end1,
y(n)=c0r*y(n-1)-rs*y(n-2)+x(n)-c0*x(n-1)+x(n-2);
end
input('run tone corrupted speech through simple second order difference equation and play back');
soundsc(y,Fs)