-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirrtdfan.m
63 lines (55 loc) · 2.55 KB
/
firrtdfan.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
function h = firrtdfan(size,B,T,theta,alpha,win)
% FIRRTDFAN is used to design 2D FIR fan filters based on the second method
% (rotated fan filter) presented in "Pei1994". The finite-extent impulse
% response is obtained by employing a 2D window function.
% Reference -
% S.-C. Pei and S.-B. Jaw, “Two-dimensional general fan-type FIR digital
% filter design,” Signal Process., vol. 37, no. 2, pp. 265–-274, 1994.
% Inputs
% size - vector containing the size of the filter (should be odd x odd)
% B - bandwidth of the filter
% T - width of the transition band
% theta - half-fan angle
% alpha - angle of rotation with respect to the first dimension
% win - string containing the window function (should be "rec" or "ham")
% Output
% h - finite-extent impulse response of the filter
%
% Author - Chamira Edussooriya
% Edited by - Sanduni U. Premaratne
% Date - Jul 05, 2015
% Last modified - Jul 06, 2015
a = tand(theta); % parameter that determines the impulse response
b = T/cosd(theta); % parameter that determines the impulse response
M1 = size(1); % length for the first dimension
M2 = size(2); % length for the second dimension
[m1,m2] = ndgrid(-(M1-1)/2:(M1-1)/2, -(M2-1)/2:(M2-1)/2);
n1 = m1*cosd(alpha) + m2*sind(alpha); % ## rotated coordinate
n2 = m2*cosd(alpha) - m1*sind(alpha); % system ##
temp1 = (cos(b*n2)-cos(B*n1+a*B*n2+b*n2)) ./ (n1+a*n2);
temp2 = (cos(b*n2)-cos(B*n1-a*B*n2-b*n2)) ./ (n1-a*n2);
h = (temp1-temp2) ./ (4*pi^2*n2);
% for n2 ~= 0, n1+a*n2 ~= 0 and n1-a*n2 ~= 0
ind = (n2==0);
temp1 = a*(cos(B*n1(ind))-1) ./ n1(ind);
h(ind) = ((a*B+b)*sin(B*n1(ind))+temp1) ./ (2*pi^2*n1(ind));
% for n2 = 0, n1+a*n2 ~= 0 and n1-a*n2 ~= 0
ind = (n1+a*n2==0);
temp1 = (cos(b*n2(ind))-cos(B*n1(ind)-a*B*n2(ind)-b*n2(ind))) ./...
(n1(ind)-a*n2(ind));
h(ind) = (B*sin(b*n2(ind))-temp1) ./ (4*pi^2*n2(ind));
% for n2 ~= 0, n1+a*n2 = 0 and n1-a*n2 ~= 0
ind = (n1-a*n2==0);
temp1 = (cos(b*n2(ind))-cos(B*n1(ind)+a*B*n2(ind)+b*n2(ind))) ./...
(n1(ind)+a*n2(ind));
h(ind) = (B*sin(b*n2(ind))+temp1) ./ (4*pi^2*n2(ind));
% for n2 ~= 0, n1+a*n2 ~= 0 and n1-a*n2 = 0
h((M1+1)/2,(M2+1)/2) = B*(a*B+2*b) / (4*pi^2);
% n1 = n2 = 0
if strcmp(win,'rec') == 1 % determine the window function
win2d = ones(M1,M2);
elseif strcmp(win,'ham') == 1
win2d = hamming(M1) * hamming(M2)';
end
h = h .* win2d; % multiply with the 2D window
h = h / sum(h(:)); % make magnitude at origin is unity