define N 1024 set x=1,$N erase window 1 1 1 1 limits 0 $N -.7 0.7 box ptype 1 1 # generate a lot of points to uniformly cover -0.5 to 0.5 # -and- at the same time do averages of 10 samples => pseudo-gaussian set y=x*0 do i=1,10 { set t=random($N)-0.5 set y=y+t } set z=x*0 do i=1,10 { set t=random($N)-0.5 set z=z+t } echo * Uniformly Distributed between -0.5 and 0.5 * toplabel * Uniformly Distributed between -0.5 and 0.5 * # use call to "cursor" in order to pause # cursor # prepare and plot the pseudo gaussian points set y[0]=0 set y[$($N-1)]=0 set y=y/10 set z[0]=0 set z[$($N-1)]=0 set z=z/10 set s=0.15*cos(6.2832*x*100/$N)*exp(-((x-450)/60)**2) set r=0.15*sin(6.2832*x*100/$N)*exp(-((x-450)/60)**2) set y=y+s set z=z+r # print data.5 {y z} set aa=sqrt(y*y*z*z) # FIRST PLOT is just the REAL PART (noise+signal) lweight 1 erase ctype default limits x y box connect x y # set s=abs(x-450)<40?.06:0 ctype blue # cursor lweight 3 # connect x s lweight 1 set ynew=y ctype 0 cursor # ADD to FIRST PLOT... the REAL SIGNAL (green) ctype green connect x s cursor # ADD to FIRST PLOT... the IMAGINARY SIGNAL (red) ctype red connect x r ctype 0 # ADD to FIRST PLOT... smoothed REAL SIGNAL (blue) smooth ynew ysmo 50 ctype blue connect x ysmo ctype 0 stats ysmo ave sig kur cursor # SECOND PLOT: Amplitude = sqrt(R**2+I**2) erase limits x aa box connect x aa # ADD smoothed Amplitude smooth aa asmo 60 ctype blue connect x asmo ctype 0 cursor # THIRD PLOT ... the FFT amplitude set yi=z *-1.0**int(x) set ynew=ynew*-1.0**int(x) fft 1 ynew yi re im set a=sqrt(re*re+im*im) limits x a erase box connect x a stats a ave sig kur echo ... echo stats a ave sig kur echo ave=$ave sigma=$sig echo ... echo vecminmax a mn mx vecminmax a mn mx echo min=$mn max=$mx echo # FOURTH PLOT: only + frequencies of FFT (amplitudes) cursor erase set x=1,1024 set x=x-513 limits 0 512 a box connect x a relocate (16000 23000) label Amplitude of FFT coefs # FIFTH PLOT: the POWER SPECTRUM cursor set amp=a*a erase vecminmax amp an ax limits 0 512 amp box 1 2 3 3 connect x amp relocate (18000 26000) label Power Spectrum # sixth plot filtered signal cursor ctype red set wgt=0*amp set wgt=x>91 &&x<108 ? 1:0 set re=re*wgt set im=im*wgt set wgt=wgt*$ax connect x wgt ctype 0 fft -1 re im yr yi set t=1,1024 set yr=yr*(-1)**t set yi=yi*(-1)**t vecminmax yr yn yx limits t $($yx-2.5*($yx-$yn)) $yx box 3 3 1 2 connect t yr ctype red cursor connect t yi ctype 0 cursor set wgt=exp(-((x-100)/7)**2) set re=re*wgt set im=im*wgt ctype blue set wgt=wgt*$ax limits 0 512 amp connect x wgt fft -1 re im yr yi set yr=yr*(-1)**t-($yx-$yn) set yi=yi*(-1)**t-($yx-$yn) limits t $($yx-2.5*($yx-$yn)) $yx connect t yr ctype green cursor connect t yi ctype 0