forked from BoysTownOrg/chapro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtst_iffb.m
More file actions
71 lines (71 loc) · 1.98 KB
/
Copy pathtst_iffb.m
File metadata and controls
71 lines (71 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% tst_iffb - CHAPRO demonstration of GHA processing
function tst_iffb
pfn='test/tst_iffb.mat'; % AFC results produced by tst_iffb
play_audio=1;
gn=0.317858; % audioread scale factor
load(pfn)
x=audioread(ifn)*gn;
y=wave;
gn=sqrt(mean(y.^2))/sqrt(mean(x.^2));
fprintf('tst_iffb: ifn=%s; gn=%.1f\n',ifn, gn);
% plot input/output
figure(1); clf
nx=length(x);
ny=length(y);
tx=linspace(0,(nx - 1) / rate, nx);
ty=linspace(0,(ny - 1) / rate, ny);
my=(max(ty)-min(ty))/20;
tlim=[min(ty)-my max(ty)+my];
plot(ty,y,'r',tx,x,'b')
xlabel('time (s)')
xylim=[min(min(x),min(y)) max(max(x),max(y))]*1.05;
axis([tlim xylim])
legend('output','input')
title('CHAPRO demonstration of AFC processing')
if (exist('sfbp','var'))
% plot feedback path
figure(2);clf
ny=length(sfbp);
ty=linspace(0,(ny - 1) / rate, ny)*1000;
my=(max(ty)-min(ty))/20;
tlim=[min(ty)-my max(ty)+my];
plot(ty,sfbp,ty,efbp)
xlim(tlim)
xlabel('time (ms)')
title('fedback path')
legend('simulated','estimated')
grid on
drawnow
% plot quality metrics
figure(3); clf
ny=length(merr);
ty=linspace(0,(ny - 1) / rate, ny);
my=(max(ty)-min(ty))/20;
tlim=[min(ty)-my max(ty)+my];
lmerr=10*log10(merr);
plot(ty,lmerr);
axis([tlim -25 5])
ylabel('dB')
xlabel('time (s)')
title('misalignment error')
amae=10*log10(mean(merr(rate:ny))); % skip first second
fmae=10*log10(sum((efbp-sfbp).^2)/sum(sfbp.^2));
fprintf('average misalignment error = %.2f\n',amae);
fprintf(' final misalignment error = %.2f\n',fmae);
drawnow
end
[x,fs]=audioread(ifn);
ii=(rate*2):ny;
id=0*fs;
amsc=mean(mscohere(x(ii),wave(ii-id)));
fprintf(' mean-squared coherence = %.3f\n',amsc);
pause(1)
if play_audio
fprintf(' Original signal: %s\n',ifn);
p = audioplayer(x, fs);
playblocking(p)
fprintf('AFC-processed signal: %s\n',pfn);
p = audioplayer(wave, rate);
playblocking(p)
end
return