; This batch file creates a plot of the power spectrum of ; the simulated signal used in the example from Chapter 13, ; "Signal Processing", of _Using IDL_, after a Hanning window ; has been applied. ; compute time data sequence u N = 1024 delt = 0.02 u = -0.3 $ + 1.0 * SIN(2 * !DPI * 2.8d * delt * DINDGEN(N)) $ + 1.0 * SIN(2 * !DPI * 6.25d * delt * DINDGEN(N)) $ + 1.0 * SIN(2 * !DPI * 11.0d * delt * DINDGEN(N)) time = DINDGEN(N)*delt hanWindow = HANNING(n, /DOUBLE) ; freq = [0.0, 1.0/(N*delt), ... , 1.0/(2.0*delt)]: freq = FINDGEN(N/2+1) / (N*delt) ; Fourier power spectrum with Hanning. v_n = FFT(hanWindow*U) powerV = ABS(v_n[0:N/2])^2 ; Fourier power spectrum without Hanning. fftU = FFT(U) powerU = ABS(fftU[0:N/2])^2 PRINT, 'Variance ratio = ', TOTAL(ABS(v_n)^2)/TOTAL(ABS(fftU)^2) !P.MULTI = [0,1,2] PLOT, time, hanWindow*u, $ TITLE='Time Series u(k) multiplied by Hanning window', $ XTITLE='Time (seconds)', YTITLE='u(k)', $ XSTYLE=1, YRANGE=[-4,4] OPLOT, time, hanWindow OPLOT, time, -hanWindow ; Create log-log plot of power spectrum: PLOT, freq, powerV, YTITLE='Power Spectrum', $ /YLOG, YRANGE=[1.0e-12,1.0], YSTYLE=1, YMARGIN=[4,4], $ XTITLE='Frequency in cycles / second', $ /XLOG, XRANGE=[1.0,1.0/(2.0*delt)], XSTYLE=1, $ TITLE='Power Spectrum of u(k) with Hanning window (solid)' $ +' and without (dashed)' ; Overplot without window: OPLOT, freq, powerU, LINESTYLE=2 !P.MULTI = 0