up [pdf]
from rsf.proj import *
from math import pi

# Make synthetic signal

Flow('s1', None,'math n1=1124 d1=0.01 o1=-1 output="0.3*cos(%g*x1)" | cut min1=6' % (10*pi))
Flow('s21',None,'math n1=1124 d1=0.01 o1=-1 output="0.8*cos(%g*x1)" | cut min1=6' % (30*pi))
Flow('s22',None,'math n1=1124 d1=0.01 o1=-1 output="0.7*cos(%g*x1+sin(%g*x1))" | cut max1=6' % (20*pi,pi))
Flow('s2','s21 s22','add ${SOURCES[1]}')
Flow('s3','s1','math output="0.4*cos(%g*x1+sin(%g*x1))" | cut max1=4 | cut min1=7.8' % (66*pi,2*pi))

Flow('s','s1 s2 s3','add ${SOURCES[1:3]} | put label1=Time unit1=s')

sigs = []
for s in range(3):
    sig = 's%d' % (s+1)
    Plot(sig,'graph title="Signal %d" min2=-1 max2=1 label2=Amplitude' % (s+1))
    sigs.append(sig)
Result('sig','s3 s2 s1','OverUnderAniso')

Plot('s',
     '''
     window min1=0 max1=10 | 
     graph wanttitle=n min2=-1.5 max2=1.5  pad=n
     label2=Amplitude
     ''')
Result('msig','s','Overlay')


## Plot instaneous frequency

Flow('s1f', None,'math n1=1124 d1=0.01 o1=-1 output="%g" | window max1=6' % (5))
Flow('s2f1', None,'math n1=1124 d1=0.01 o1=-1 output="%g" | window max1=6' % (15))
Flow('s2f2',None,'math n1=1124 d1=0.01 o1=-1 output="%g+cos(%g*x1)/%g" | window min1=6' % (10,2*pi,2*pi))
Flow('s2f','s2f1 s2f2','cat axis=1 ${SOURCES[1]}')
Flow('s3f','s1','math output="%g+cos(%g*x1)/%g" | window min1=4 max1=7.8' % (33,2*pi,2*pi))

Plot('s1f',
       '''
       graph title=Frequencies yreverse=y pad=n wanttitle=n scalebar=n bartype=v
       plotfat=3 grid=y label2=Frequency unit2=Hz label1=Time unit1=s 
       min2=0 max2=40 min1=0 max1=10 plotcol=1 plotfat=20      ''')
Plot('s2f',
       '''
       graph title=Frequencies yreverse=y pad=n wanttitle=n scalebar=n bartype=v
       plotfat=3 grid=n label2=Frequency unit2=Hz label1=Time unit1=s 
       min2=0 max2=40 min1=0 max1=10 plotcol=2 plotfat=20      ''')
Plot('s3f',
       '''
       graph title=Frequencies yreverse=y pad=n wanttitle=n scalebar=n bartype=v
       plotfat=3 grid=n label2=Frequency unit2=Hz label1=Time unit1=s 
       min2=0 max2=40 min1=0 max1=10 plotcol=4 plotfat=20      ''')
Result('sf','s1f s2f s3f','Overlay')

Result('s-sf','s Fig/sf.vpl','OverUnderAniso')

## EMD
Flow('semd','s','emd')

imfs=[]
for i in range(3):
    imf='imf-'+str(i)
    Flow(imf,'semd','window n2=1 f2=%d'%i)
    Plot(imf,'graph wanttitle=n min2=-1.5 max2=1.5 min1=0 max1=10 pad=n label2=Amplitude screenratio=0.8')
    imfs.append(imf)

Flow('res','semd','window f2=3 | stack axis=2')
Plot('res','graph wanttitle=n min2=-1.5 max2=1.5 min1=0 max1=10  pad=n label2=Amplitude screenratio=0.8')
imfs.append('res')
Result('Imf',imfs,'OverUnderAniso')


End()

sfmath
sfcut
sfadd
sfput
sfgraph
sfwindow
sfcat
sfemd
sfstack