Digital Signal Processing Reference
In-Depth Information
% Ftype: the filter type
% 1. Lowpass filter
% 2. Highpass filter
% 3. Bandpass filter
% 4. Bandstop filter
% WnL: lower cutoff frequency in radians. Set WnL ¼ 0 for the highpass filter.
% WnH: upper cutoff frequency in radians. Set WnL ¼ 0 for the lowpass filter.
% Wtypw: window function type
% 1. Rectangular window
% 2. Triangular window
% 3. Hanning window
% 4. Hamming window
% 5. Balckman window
% Output:
% B: FIR filter coefficients.
M ¼ (N-1)/2;
hH ¼ sin(WnH*[-M:1:-1])./([-M:1:-1]*pi);
hH(M þ 1) ¼ WnH/pi;
hH(M þ 2:1:N) ¼ hH(M:-1:1);
hL ¼ sin(WnL*[-M:1:-1])./([-M:1:-1]*pi);
hL(M þ 1) ¼ WnL/pi;
hL(M þ 2:1:N) ¼ hL(M:-1:1);
if Ftype ¼¼ 1
h(1:N) ¼ hL(1:N);
end
if Ftype ¼¼ 2
h(1:N) ¼ -hH(1:N);
h(M þ 1) ¼ 1 þ h(M þ 1);
end
if Ftype ¼¼ 3
h(1:N) ¼ hH(1:N)-hL(1:N);
end
if Ftype
¼¼
4
h(1:N)
¼
hL(1:N)-hH(1:N);
h(M
þ
1)
¼
1
þ
h(M
þ
1);
end
% Window functions
if Wtype
1
w(1:N) ¼ ones(1,N);
¼¼
end
if Wtype ¼¼ 2
w ¼ 1-abs([-M:1:M])/M;
end
if Wtype ¼¼ 3
w ¼ 0.5 þ 0.5*cos([-M:1:M]*pi/M);
end
if Wtype ¼¼ 4
w ¼ 0.54 þ 0.46*cos([-M:1:M]*pi/M);
Search WWH ::




Custom Search