File: ffilt.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (68 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (2)
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
function [x]=ffilt(ft,n,fl,fh)
//x=ffilt(ft,n,fl,fh)
//Get n coefficients of a 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
//!
//author: C. Bunks  date: 12 March 1988
// Copyright INRIA

//Pre-calculation
 
no2=(n-1)/2;
ino2=int(no2);
 
//Calculate n samples of the sinc function
 
//Low pass filter
 
if ft=='lp' then
  [x]=sinc(n,fl)
end
 
//High pass filter
 
if ft=='hp' then
   x=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=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=sinc(n,fl)
   y=2*cos(wc*(-no2:no2));
   x=-x.*y;
   x(no2+1)=1+x(no2+1);
end