%Matlab file used for class demo conducted during Session 2
%Shows how simple difference equation can remove a tone
%that's corrupting a speech utterance.
clf
clear all
set(0,'defaultaxesfontsize',16);

data=load('erf1s1t0')';
Fs=8192;
plot(data)
%end1=input('end1?')
%end2=input('end2?')
%datar=data(end1:end2);
datar=data;
dsize=length(datar);

input('Play back utterance at 12.5 KHz sampling rate...');
soundsc(datar,Fs)
input('Add tone at 3.125 KHz to utterance and play back...');
omega0=pi/2;
nc=1:dsize;
x=datar+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;

disp('Run tone corrupted speech through simple second');
input(' order difference equation...');
y=zeros(1,dsize);
for n=3:dsize
y(n)=c0r*y(n-1)-rs*y(n-2)+x(n)-c0*x(n-1)+x(n-2);
end
input('Play back output of difference equation...');
soundsc(y,Fs)

