1
% Attempts to diagnose AEC problems from recorded samples
3
% out = echo_diagnostic(rec_file, play_file, out_file, tail_length)
5
% Computes the full matrix inversion to cancel echo from the
6
% recording 'rec_file' using the far end signal 'play_file' using
7
% a filter length of 'tail_length'. The output is saved to 'out_file'.
8
function out = echo_diagnostic(rec_file, play_file, out_file, tail_length)
10
F=fopen(rec_file,'rb');
11
rec=fread(F,Inf,'short');
13
F=fopen(play_file,'rb');
14
play=fread(F,Inf,'short');
17
rec = [rec; zeros(1024,1)];
18
play = [play; zeros(1024,1)];
21
corr = real(ifft(fft(rec).*conj(fft(play))));
22
acorr = real(ifft(fft(play).*conj(fft(play))));
29
printf ("Far end to near end delay is %d samples\n", b);
30
if (b > .3*tail_length)
31
printf ('This is too much delay, try delaying the far-end signal a bit\n');
33
printf ('You have a negative delay, the echo canceller has no chance to cancel anything!\n');
35
printf ('Delay looks OK.\n');
40
corr1 = real(ifft(fft(rec(1:N2)).*conj(fft(play(1:N2)))));
41
corr2 = real(ifft(fft(rec(N2+1:end)).*conj(fft(play(N2+1:end)))));
52
printf ('Drift estimate is %f%% (%d samples)\n', 100*drift, b1-b2);
54
printf ('A drift of a few (+-10) samples is normal.\n');
57
printf ('There may be (not sure) excessive clock drift. Is the capture and playback done on the same soundcard?\n');
59
printf ('Your clock is drifting! No way the AEC will be able to do anything with that. Most likely, you''re doing capture and playback from two different cards.\n');
63
acorr(1) = .001+1.00001*acorr(1);
64
AtA = toeplitz(acorr(1:tail_length));
65
bb = corr(1:tail_length);
68
out = (rec - filter(h, 1, play));
70
F=fopen(out_file,'w');
71
fwrite(F,out,'short');