-
Notifications
You must be signed in to change notification settings - Fork 18
/
firwsord.m
87 lines (77 loc) · 2.88 KB
/
firwsord.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
% firwsord() - Estimate windowed sinc FIR filter order depending on
% window type and requested transition band width
%
% Usage:
% >> [m, dev] = firwsord(wtype, fs, df);
% >> m = firwsord('kaiser', fs, df, dev);
%
% Inputs:
% wtype - char array window type. 'rectangular', 'hann', 'hamming',
% 'blackman', or 'kaiser'
% fs - scalar sampling frequency
% df - scalar requested transition band width
% dev - scalar maximum passband deviation/ripple (Kaiser window
% only)
%
% Output:
% m - scalar estimated filter order
% dev - scalar maximum passband deviation/ripple
%
% References:
% [1] Smith, S. W. (1999). The scientist and engineer's guide to
% digital signal processing (2nd ed.). San Diego, CA: California
% Technical Publishing.
% [2] Proakis, J. G., & Manolakis, D. G. (1996). Digital Signal
% Processing: Principles, Algorithms, and Applications (3rd ed.).
% Englewood Cliffs, NJ: Prentice-Hall
% [3] Ifeachor E. C., & Jervis B. W. (1993). Digital Signal
% Processing: A Practical Approach. Wokingham, UK: Addison-Wesley
%
% Author: Andreas Widmann, University of Leipzig, 2005
%
% See also:
% pop_firwsord, firws, invfirwsord
%123456789012345678901234567890123456789012345678901234567890123456789012
% Copyright (C) 2005-2015 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%
% $Id$
function [ m, dev ] = firwsord(wintype, fs, df, dev)
winTypeArray = {'rectangular', 'hann', 'hamming', 'blackman', 'kaiser'};
winDfArray = [0.9 3.1 3.3 5.5];
winDevArray = [0.089 0.0063 0.0022 0.0002];
% Check arguments
if nargin < 3 || isempty(fs) || isempty(df) || isempty(wintype)
error('Not enough input arguments.')
end
% Window type
wintype = find(strcmp(wintype, winTypeArray));
if isempty(wintype)
error('Unknown window type.')
end
df = df / fs; % Normalize transition band width
if wintype == 5 % Kaiser window
if nargin < 4 || isempty(dev)
error('Not enough input arguments.')
end
devdb = -20 * log10(dev);
m = 1 + (devdb - 8) / (2.285 * 2 * pi * df);
else
m = winDfArray(wintype) / df;
dev = winDevArray(wintype);
end
m = ceil(m / 2) * 2; % Make filter order even (FIR type I)
end