-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtst_cifio.m
81 lines (77 loc) · 1.45 KB
/
tst_cifio.m
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
72
73
74
75
76
77
78
79
80
81
% test gammatone filterbank input/output
function tst_cifio
load('test/cifio_impulse')
p_lim=[-0.1 1.1];
t_lim=[-1 30];
t=1000*(0:(length(y)-1))/rate;
figure(1);clf
subplot(1,2,1)
plot(t,x)
title('input')
axis([t_lim p_lim])
xlabel('time (ms)')
subplot(1,2,2)
plot(t,y)
title('output')
axis([t_lim p_lim])
xlabel('time (ms)')
% transfer function
figure(2);clf
dc=2.96; % desired group delay (ms)
H=ffa(y)./ffa(x);
f=linspace(0,rate/2000,length(H))';
fm=max(f);
m_lim=[0.05 fm -5 5];
d_lim=[0.05 fm 1 9];
M=db(H);
D=gd(H,f);
d=dc*ones(size(f));
subplot(2,1,1)
semilogx(f,M)
axis(m_lim)
xlabel('frequency (kHz)')
ylabel('magnitude (dB)')
subplot(2,1,2)
semilogx(f,d,':',f,D)
axis(d_lim)
xlabel('frequency (kHz)')
ylabel('delay (ms)')
load('test/cifio_tone')
p_lim=[-2 2];
figure(3);clf
subplot(2,1,1)
plot(t,x)
title('input')
axis([t_lim p_lim])
subplot(2,1,2)
plot(t,y)
title('output')
axis([t_lim p_lim])
xlabel('time (ms)')
return
function y=db(x)
y=20*log10(max(eps,abs(x)));
return
function d=gd(x,f)
p=unwrap(angle(x))/(2*pi);
d=-cdif(p)./cdif(f);
return
function dx=cdif(x)
n=length(x);
dx=zeros(size(x));
dx(1)=x(2)-x(1);
dx(2:(n-1))=(x(3:n)-x(1:(n-2)))/2;
dx(n)=x(n)-x(n-1);
return
% ffa - fast Fourier analyze real signal
% usage: H=ffa(h)
% h - impulse response
% H - transfer function
function H=ffa(h)
H=fft(real(h));
n=length(H);
m=1+n/2; % assume n is even
H(1,:)=real(H(1,:));
H(m,:)=real(H(m,:));
H((m+1):n,:)=[]; % remove upper frequencies
return