from rsf.proj import *
import math, string
f0 = 1/(2*math.pi)
f1 = 0.2/(2*math.pi)
Flow('tatrace',None,
'''
math n1=128 d1=1 o1=1 type=complex
output="2.5*exp(I*(%g*x1+%g))+5*exp(I*(%g*x1+%g))" |
dd type=float | noise var=0.05 seed=1234 | dd type=complex
''' % (2*math.pi*f0,2*math.pi*f0,
2*math.pi*f1,0))
Result('tatrace',
'imag | dots label1=Sample unit1= title="Synthetic Mixed Sinusoidal Signal"')
nf = 2
Flow('freq2',None,'spike n1=2 nsp=2 k1=1,2 mag=%g,%g' % (f0,f1))
Flow('troots','tatrace','cpef nf=%d | roots niter=20' % (nf+1))
Result('troots','graph symbol=x title=Roots')
Flow('taft','tatrace troots',
'''
freqlet freq=${SOURCES[1]} type=b ncycle=50 perc=95
''')
Result('taft',
'''
math output="abs(input)" | real |
dots label1=Scale unit1= title="1-D Seislet Frame"
labels=First:Second yreverse=y
''')
Flow('zero','troots','window n1=1 | math output=1')
Flow('tdwt','tatrace zero',
'''
freqlet freq=${SOURCES[1]} type=b
''')
Result('tdwt',
'''
math output="abs(input)" | real |
dots label1=Scale unit1= title="1-D Wavelet Transform"
''')
Flow('fourier','tatrace','fft3 axis=1')
Result('fourier',
'''
math output="abs(input)" | real |
dots label1=Scale unit1= title="1-D Fourier Transform"
n1=64 d1=0.5 o1=1
''')
Flow('taft0','taft','window n2=1 f2=0')
Flow('taft1','taft','window n2=1 f2=1')
n1 = 128
n2 = 128*nf
p = 25.0
Flow('logtaft','taft0 taft1',
'''
cat axis=1 ${SOURCES[1]} |
math output="abs(input)" |
real |
scale axis=1 |
sort |
math output="%g*log(input)" |
window n1=%d j1=%d |
put o1=0 d1=%g
''' % (10/math.log(10),n2*p/(nf*100),(nf-1),p/(n2*p/100-1)))
for case in ('tdwt','fourier'):
Flow('log'+case,case,
'''
math output="abs(input)" |
real |
scale axis=1 |
sort |
math output="%g*log(input)" |
window n1=%d |
put o1=0 d1=%g
''' % (10/math.log(10),n1*p/100,p/(n1*p/100-1)))
Plot('dwt-fourier-aft','logtdwt logfourier logtaft',
'''
cat axis=2 ${SOURCES[1:3]} |
graph dash=1,2,0 title="Compression Ratio"
label1="Percentage (%)" unit1=
label2="a\_\s75 n \s100 (dB)" plotcol=7,7,7
''' )
box = '''
box x0=%g y0=%g label="%s" xt=%g yt=%g
'''
Plot('ldwt',None,box % (6.55,4.5,"Seislet Frame",-1,-0.5))
Plot('lfourier',None,box % (6,7.85,"Fourier Transform",-1,-0.5))
Plot('laft',None,box % (7.04,8.1,"Wavelet Transform",1,0.5))
Result('tlog','dwt-fourier-aft ldwt laft lfourier','Overlay')
Flow('trecon','taft troots tatrace',
'freqlet freq=${SOURCES[1]} inv=y type=b | cat axis=2 ${SOURCES[2]}')
Result('trecon','real | graph title=Reconstruction')
for freq in range(nf):
root = 'troot%d' % freq
inv = 'tinv%d' % freq
Flow(root,'troots','window n1=1 f1=%d' % freq)
Flow(inv,['taft',root],
'''
window n2=1 f2=%d |
freqlet freq=${SOURCES[1]} inv=y type=b
''' % freq)
Result(inv,'real | graph title="Frequency %d" ' % (freq+1))
for case in range(3):
recon = 'trecon%d' % case
pclip = (5,10,50)[case]
Flow(recon,'taft troots tatrace',
'''
threshold pclip=%g |
freqlet freq=${SOURCES[1]} inv=y type=b |
cat axis=2 ${SOURCES[2]}
''' % pclip)
Result(recon,'real | graph title="2 Sinusoid Reconstruction (%d%%)"' % pclip)
End() |