-
Notifications
You must be signed in to change notification settings - Fork 1
/
wavelet_filters.m
170 lines (125 loc) · 4.54 KB
/
wavelet_filters.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
% filter coefficients for orthogonal and bi-orthogonal filters
% Input:
% choice: choice of filters, example: 'bio1'
% Output:
% h0, f0, h1, f1: filter coefficients for low-pass and high-pass
% signals
% Author:
% Junyu Chen ([email protected])
% Johns Hopkins University
function [h0, f0, h1, f1]=wavelet_filters(choice)
%% Half-band filter
p = 1/2048*[-5 0 49 0 -245 0 1225 2048 1225 0 -245 0 49 0 -5];
% plot coefficients:
%figure;
%stem(p) %
%title('Halfband filter P_0(z)')
% plot half-band filter's frequency response:
%figure; plot(abs(fft(p,1024)))
% find roots of the polynomial:
%roots(p)
% force some roots to -1:
b = poly(-ones(1,8)); % converts from roots to poly, b is coefficients;
q = deconv(p,b);
zq = roots(q);
zp = [zq; -ones(1,8)'];
disp(roots(p))
disp(zp)
% zplane
%figure;
%zplane(zp)
%title('Pole-Zero plot')
%% choice
if strcmp(choice, 'o1')
% Real - coeffiecient and Orthogonality
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) must be separated! ........ Orthogonality
% split zeros into two polynomials: f0 is the inverst
h0 = poly([zp(4:6);-1;-1;-1;-1]);
f0 = poly([zp(1:3);-1;-1;-1;-1]);
% normalize h0 and f0:
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);%#conv(h0,f0)
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1 -1];
f1 = h0.*[-1 1 -1 1 -1 1 -1 1];
elseif strcmp(choice, 'o2')
% Real - coeffiecient and Orthogonality
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) must be separated! ........ Orthogonality
h0 = poly([zp(1); zp(4:5);-1;-1;-1;-1]);
f0 = poly([zp(6); zp(2:3);-1;-1;-1;-1]);
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1 -1];
f1 = h0.*[-1 1 -1 1 -1 1 -1 1];
elseif strcmp(choice, 'bio1')
% Real - coeffiecient and symmetry
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) stay as a unit! ........ Symmetry
h0 = poly([zp(1); zp(6);-1;-1;-1]);
f0 = poly([zp(2:5);-1;-1;-1;-1;-1]);
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1 -1 1 -1];
f1 = h0.*[-1 1 -1 1 -1 1];
elseif strcmp(choice, 'bio2')
% Real - coeffiecient and symmetry
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) stay as a unit! ........ Symmetry
h0 = poly([zp(1);zp(6);-1;-1;-1;-1;-1;-1]);
f0 = poly([zp(2:5);-1;-1]);
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1];
f1 = h0.*[-1 1 -1 1 -1 1 -1 1 -1];
elseif strcmp(choice, 'bio3')
% Real - coeffiecient and Symmetry
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) stay as a unit! ........ Symmetry
h0 = poly([zp(2:5);-1;-1;-1]);
f0 = poly([zp(1);zp(6);-1;-1;-1;-1;-1]);
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1 -1];
f1 = h0.*[-1 1 -1 1 -1 1 -1 1];
elseif strcmp(choice, 'bio4')
% Real - coeffiecient and symmetry
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) stay as a unit! ........ Symmetry
% split zeros into two polynomials: f0 is the inverst
h0 = poly([zp(2:5);-1;-1;-1;-1]);
f0 = poly([zp(1);zp(6);-1;-1;-1;-1]);
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1];
f1 = h0.*[-1 1 -1 1 -1 1 -1 1 -1];
elseif strcmp(choice, 'bio5')
% Real - coeffiecient and symmetry
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) stay as a unit! ........ Symmetry
h0 = poly([-1;-1;-1;-1;-1]);
f0 = poly([zp(1:6);-1;-1;-1]);
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1 -1 1 -1];
f1 = h0.*[-1 1 -1 1 -1 1];
elseif strcmp(choice, 'bio6')
% Real - coeffiecient and symmetry
% 1. (zi, zi^*) stay as a unit! ........ Real - coeffiecient
% 2. (zi, zi^-1) stay as a unit! ........ Symmetry
h0 = poly([zp(2:5);-1]);
f0 = poly([zp(1);zp(6);-1*ones(7,1)]);
% normalize h0 and f0:
f0 = sqrt(2).*f0./sum(f0);
h0 = sqrt(2).*h0./sum(h0);%#conv(h0,f0)
% flip
h1 = f0.*[1 -1 1 -1 1 -1 1 -1 1 -1];
f1 = h0.*[-1 1 -1 1 -1 1];
end