% M-file program that reads the two voices of 'test1' and 'test2' and computes % their average fourier transform function z=meanvoice y1=wavread('test1'); y2=wavread('test2'); x1=fft(y1,60000); x2=fft(y2,60000); z1=x1(1:2500); z2=x2(1:2500); z1(1:500)=zeros(500,1); z2(1:500)=zeros(500,1); n1=sqrt(sum(abs(z1).^2)); n2=sqrt(sum(abs(z2).^2)); z1=z1/n1; z2=z2/n2; z=(z1+z2)/2; n=sqrt(sum(abs(z).^2)); z=z/n;By typing
Z=meanvoiceOne obtains the average Fourier Trans form. The next tests a third voice against this average;
%A MATLAB fuction which tests the voice against %a reference. function test(Z) name=input('filename? ','s'); y=wavread(name); %x is the Fourier transform of y x=fft(y,60000); z=x(1:2500); z(1:500)=zeros(500,1); s=sqrt(sum(abs(z-Z).^2)); if s< 1 'OK' else 'IMPOSTOR!' endTyping
test(Z)the program will use the average computed before and prompt the user to give the name of a WAV-file which contains the voice to be tested. It then performs the necessary operations and tests this voice against the average Z.