-
Notifications
You must be signed in to change notification settings - Fork 13
/
tst_ffio.m
99 lines (91 loc) · 1.86 KB
/
tst_ffio.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% test FIR filterbank analysis
function tst_ffio
tst_ffio_impulse(1)
tst_ffio_tone(3)
return
%===============================================================
function tst_ffio_impulse(fig)
load('test/ffio_impulse')
td=5;
t=1000*(0:(length(y)-1))/rate;
figure(fig);clf
plot(t,y)
title('FIRFB impulse response')
ymn=min(min(y));
ymx=max(max(y));
ymg=(ymx-ymn)/20;
y_lim=[ymn-ymg ymx+ymg];
t_lim=[-0.5 12.5];
axis([t_lim y_lim])
xlabel('time (ms)')
text(10, 0.9, sprintf('max=%.2f',max(y)))
% transfer function
figure(fig+1);clf
H=ffa(y)./ffa(x);
f=linspace(0,rate/2000,length(H))';
d=td*ones(size(f));
fm=max(f);
m_lim=[0.05 fm -5 5];
d_lim=[0.05 fm 0 8];
M=db(H);
D=gd(H,f);
subplot(2,1,1)
semilogx(f,M)
axis(m_lim)
xlabel('frequency (kHz)')
ylabel('magnitude (dB)')
title('FIRFB transfer function')
subplot(2,1,2)
semilogx(f,D,f,d,':k')
axis(d_lim)
xlabel('frequency (kHz)')
ylabel('delay (ms)')
drawnow
%------------------------------
dev='-depsc2';
for k=1:0
fig=sprintf('-f%d',k);
nam=sprintf('tst_io%d.eps',k);
print(dev,fig,nam);
end
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
%===============================================================
function tst_ffio_tone(fig)
load('test/ffio_tone')
t_lim=[-0.001 0.021];
p_lim=[-1 1]*1.5;
t=(0:(length(y)-1))/rate;
figure(fig);clf
subplot(2,1,1)
plot(t,x)
axis([t_lim p_lim])
subplot(2,1,2)
plot(t,y)
axis([t_lim p_lim])
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