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
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA - 1988 - C. Bunks
// Copyright (C) INRIA - 2002 - S Steer
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
function x=ffilt(ft,n,fl,fh)
//x=ffilt(ft,n,fl,fh)
//Get n coefficients of an FIR low-pass,
//high-pass, band-pass, or stop-band filter
// ft :Filter type where ft can take the values
// : 'lp' for low-pass filter
// : 'hp' for high-pass filter
// : 'bp' for band-pass filter
// : 'sb' for stop-band filter
// n :Number of filter samples desired
// fl :Low frequency cut-off
// fh :High frequency cut-off
// :For low and high-pass filters one cut-off
// :frequency must be specified whose value is
// :given in fl. For band-pass and stop-band
// :filters two cut-off frequencies must be
// :specified for which the lower value is in
// :fl and the higher value is in fh.
// x :Filter coefficients
//Pre-calculation
no2 = (n-1)/2;
ino2 = int(no2);
//Calculate n samples of the sinc function
//Low pass filter
if ft=="lp" then
[x]=filt_sinc(n,fl)
end
//High pass filter
if ft=="hp" then
x=filt_sinc(n,fl)
x=-x;
x(no2+1)=1+x(no2+1);
end
//Band pass filter
if ft=="bp" then
wc=%pi*(fh+fl);
fl=(fh-fl)/2;
x=filt_sinc(n,fl)
y=2*cos(wc*(-no2:no2));
x=x.*y;
end
//Stop band filter
if ft=="sb" then
wc=%pi*(fh+fl);
fl=(fh-fl)/2;
x=filt_sinc(n,fl)
y=2*cos(wc*(-no2:no2));
x=-x.*y;
x(no2+1)=1+x(no2+1);
end
endfunction
|