In [1]:
import DSP
using PyPlot
In [2]:
include("../juwvid.jl")
Out[2]:
In [3]:
## sin FM
nsample=4096;
xs,ys,iws,ynorms=sampledata.genfm(nsample,2*pi,2*pi/365,1.0,365.0);
z=DSP.Util.hilbert(ys);
PyPlot.plot(xs,ys)
Out[3]:
In [4]:
tfrpf=cohenclass.tfrpwv(z,NaN,NaN,NaN,NaN,NaN,0);
In [5]:
fig=PyPlot.figure()
ax = fig[:add_subplot](1,2,1)
a=juwplot.tfrshow(abs.(tfrpf),xs[2]-xs[1],xs[1],xs[end],NaN,NaN,0.7,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.ylabel("frequency [1/day]")
PyPlot.title("Pseudo WV")
ax = fig[:add_subplot](1,2,2)
a=juwplot.tfrshow(abs.(tfrpf),xs[2]-xs[1],xs[1],xs[end],NaN,NaN,0.7*130,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("Zoom-up")
PyPlot.ylim(0.98,1.02)
Out[5]:
In [6]:
# extracting the IF
indf=extif.maxif(abs.(tfrpf));
dx=xs[2]-xs[1]
fx=juwutils.index_to_frequency(indf,NaN,dx,nsample);
In [7]:
# We extract frequency indices of 0.98 and 1.02 [1/day] because we want to know the signal around 1.
nnufft=1024
js,je=juwutils.frequency_to_index([0.98,1.02], xs[2]-xs[1], nsample,nnufft)
Out[7]:
In [8]:
Nz=100
tfrpfz=cohenclass.tfrpwv(z,NaN,NaN,[js,je],NaN,NaN,0,"zeropad",4,Nz);
In [9]:
fig=PyPlot.figure()
ax = fig[:add_subplot](1,2,1)
a=juwplot.tfrshow(abs.(tfrpf),xs[2]-xs[1],xs[1],xs[end],NaN,NaN,0.7*130,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("Zoom-up (FFT)")
PyPlot.ylim(0.985,1.02)
ax = fig[:add_subplot](1,2,2)
a=juwplot.tfrshow(abs.(tfrpfz),xs[2]-xs[1],xs[1],xs[end],round(Int,js),round(Int,je),0.7,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("zero-padding")
PyPlot.ylim(0.985,1.02)
Out[9]:
In [10]:
indfz=extif.maxif(abs.(tfrpfz));
fz=juwutils.index_to_frequency(indfz,NaN,xs[2]-xs[1],nsample,NaN,je,js,Nz);
PyPlot.title("no noise")
PyPlot.xlabel("time")
PyPlot.ylabel("instantaneous frequency")
PyPlot.ylim(0.995,1.005)
PyPlot.plot(xs,fx, color="gray",lw=3)
PyPlot.plot(xs,fz, color="C0",lw=3)
PyPlot.plot(xs,iws/(2*pi), color="C3", ls="dashed",lw=3)
PyPlot.legend(["IF from PWV (FFT)","IF from PWV (zeropad)","Input IF"])
Out[10]:
In [11]:
fin=collect(linspace(js,je,nnufft));
tfrpfn=cohenclass.tfrpwv(z,NaN,NaN,fin,NaN,NaN,0,"nufft");
In [12]:
fig=PyPlot.figure()
ax = fig[:add_subplot](1,2,1)
a=juwplot.tfrshow(abs.(tfrpf),xs[2]-xs[1],xs[1],xs[end],NaN,NaN,0.7*130,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("Zoom-up (FFT)")
PyPlot.ylim(0.98,1.02)
ax = fig[:add_subplot](1,2,2)
a=juwplot.tfrshow(abs.(tfrpfn),xs[2]-xs[1],xs[1],xs[end],fin[1],fin[end],0.7,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("NuFFT")
Out[12]:
In [13]:
indfn=extif.maxif(abs.(tfrpfn));
fn=juwutils.index_to_frequency(indfn, fin,xs[2]-xs[1],nsample,nnufft);
In [14]:
PyPlot.title("no noise")
PyPlot.xlabel("time")
PyPlot.ylabel("instantaneous frequency")
PyPlot.ylim(0.995,1.005)
PyPlot.plot(xs,fx, color="gray",lw=3)
PyPlot.plot(xs,fn, color="C0",lw=3)
PyPlot.plot(xs,iws/(2*pi), color="C3", ls="dashed",lw=3)
PyPlot.legend(["IF from PWV (FFT)","IF from PWV (NUFFT)","Input IF"])
Out[14]:
In [15]:
# using one in 20 time grids
nthin=20
itc=collect(1:nthin:nsample);
tfrpfi=cohenclass.tfrpwv(z,NaN,NaN,fin,itc,NaN,0,"nufft");
In [16]:
fig=PyPlot.figure()
ax = fig[:add_subplot](1,2,1)
a=juwplot.tfrshow(abs.(tfrpfn),xs[2]-xs[1],xs[1],xs[end],fin[1],fin[end],0.7,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("NuFFT")
ax = fig[:add_subplot](1,2,2)
a=juwplot.tfrshow(abs.(tfrpfi),(xs[2]-xs[1])*nthin,xs[1],xs[end],fin[1],fin[end],0.7,"Spectral")
PyPlot.xlabel("time [day]")
PyPlot.title("NuFFT & thinning")
Out[16]:
this technique is useful for large dataset
In [ ]: