Change Eclipse configuration
[jabaws.git] / website / archive / binaries / mac / src / disembl / Tisean_3.0.1 / source_f / notch.f
1 c===========================================================================
2 c
3 c   This file is part of TISEAN
4
5 c   Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
6
7 c   TISEAN is free software; you can redistribute it and/or modify
8 c   it under the terms of the GNU General Public License as published by
9 c   the Free Software Foundation; either version 2 of the License, or
10 c   (at your option) any later version.
11 c
12 c   TISEAN is distributed in the hope that it will be useful,
13 c   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 c   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 c   GNU General Public License for more details.
16 c
17 c   You should have received a copy of the GNU General Public License
18 c   along with TISEAN; if not, write to the Free Software
19 c   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 c
21 c===========================================================================
22 c   notch filter in the time domain
23 c   author T. Schreiber
24 c===========================================================================
25
26       parameter(nx=1000000)
27       dimension x(nx), y(nx)
28       character*72 file, fout
29       data h/1./, w/0.01/, pi/3.1415926/
30       data iverb/1/
31
32       call whatido("notch filter",iverb)
33       f=fmust("X")
34       h=fcan("f",h)
35       w=fcan("w",w)
36       fw=tan(pi*f/h)
37       nmaxx=ican("l",nx)
38       nexcl=ican("x",0)
39       jcol=ican("c",0)
40       isout=igetout(fout,iverb)
41
42       do 10 ifi=1,nstrings()
43          call nthstring(ifi,file)
44          nmax=nmaxx
45          call readfile(nmax,x,nexcl,jcol,file,iverb)
46          if(file.eq."-") file="stdin"
47          d=fnotch(nmax,x,y,fw,w)
48          if(isout.eq.1) call addsuff(fout,file,"_notch")
49  10      call writefile(nmax,y,fout,iverb)
50       end
51
52       function fnotch(nmax,x,y,fw,w)
53       dimension x(nmax), y(nmax)
54
55       a=(1+w*fw)**2+fw**2
56       c0=   (1+fw**2)/a
57       c1=-2*(1-fw**2)/a
58       c2=c0
59       d1= 2*(1-w**2*fw**2-fw**2)/a
60       d2=  -((1-w*fw)**2+fw**2)/a
61
62       y(1)=c0*x(1)
63       y(2)=c0*x(2)+c1*x(1)+d1*y(1)
64       do 10 n=3,nmax
65  10      y(n)=c0*x(n)+c1*x(n-1)+c2*x(n-2)+d1*y(n-1)+d2*y(n-2)
66       fnotch=0
67       do 20 n=1,nmax
68  20      fnotch=fnotch+(x(n)-y(n))**2
69       fnotch=sqrt(fnotch/nmax)
70       end
71
72       subroutine usage()
73 c usage message
74
75       call whatineed(
76      .   "-X# [-f# -w# -o outfile -l# -x# -c# -V# -h] file(s)")
77       call popt("X","frequency to be cancelled")
78       call popt("f","sampling rate of data (1)")
79       call popt("w","width of filter (f/100)")
80       call popt("l","number of values to be read (all)")
81       call popt("x","number of values to be skipped (0)")
82       call popt("c","column to be read (1 or file,#)")
83       call pout("file_notch")
84       call pall()
85       stop
86       end