pro WDOSCEG ;+ ; NAME: ; WDOSCEG ; ; PURPOSE: ; This procedure generates a scalegram and plots it. The scalegram is ; the wavelet analog of the power spectrum. It is just the (squared) ; wavelet coefficient averaged over all location index values at a ; fixed value of the scale index. The sums of squares --> scalegram ; flat if input = white noise ; ; CATEGORY: ; Wavelets. ; ; CALLING SEQUENCE: ; ; WDOSCEG ; ; INPUTS: (via COMMON) ; X_work: 1-d signal array ; QMF: Quadrature Mirror Filter ; ; OUTPUTS: ; The scalegram plotted to the screen. ; ; COMMON BLOCKS: ; COMMON WWB_COMMON, $ ; TEXT_ANNOUNCE, wd, sig, len, st, noise_type, noise_lev, $ ; QMF, LD, shrinkage_type, WaveType, ParVal ; COMMON Wave_color, $ ; max_color, max_image, $ ; white, yellow, lavender, aqua, pink, green, red, orange, blue, $ ; lt_gray, med_green, brown, olive, purple, dk_gray, black ; ; SEE ALSO: ; wintwave (necessary for this procedure) ; ; EXAMPLE: ; Truncate sig array appropriately and get QMF ; IDL> WINTWAVE, sig, WaveType, ParVal, QMF, LD ; Call scalegram ; IDL> WDOSCEG ; ; NOTES ; We prefer to use the Haar wavelet because: ; 1. it is the only one that you can use down to the "finest ; scale" ... i.e., width of wavelet = 2 X sampling interval. ; 2. No worries about end-effects (i.e. no wavelet sticking out ; over the ends of the data!) ; 3. The correction of the resulting scalegram has a very simple ; form ( = mean counting rate) for Poisson statistics in the data. ; ; For noisy data, the discontinuity and nondifferentiability ; of the Haar wavelet don't seem to be important deficiencies. ; ; MODIFICATION HISTORY: ; Written by: Amara Graps August 1995 - January 1996 ;Translated from MatLab Wavelab routine: do_scalegram.m ;- COMMON Wave_color, $ max_color, max_image, $ white, yellow, lavender, aqua, pink, green, red, orange, blue, $ lt_gray, med_green, brown, olive, purple, dk_gray, black COMMON WWB_COMMON, $ TEXT_ANNOUNCE, wd, sig, len, st, noise_type, noise_lev, $ QMF, LD, shrinkage_type, WaveType, ParVal x_work = sig TT = WSIGTYPE(x_work, olen, error) ;Color of text strings IF !p.background EQ 0 THEN cl = 255 ELSE cl = 0 CASE error OF 1: BEGIN ;Valid array or matrix CASE TT OF 'I': BEGIN ;Image- Not implemented yet WIDGET_CONTROL, TEXT_ANNOUNCE, SET_VALUE='Scalegram Not Implemented for 2D Data.' END ;image 'S': BEGIN ;Signal- Implmented, but works only for Haar ;If QMF not Haar, make it Haar ;Load basic color table and set the Wave_color common variables WVLOADCT, 2 nQ = n_elements(QMF) CASE nQ OF 2: BEGIN ;Haar caseHaar = 'True' END else: BEGIN ;Make it Haar oldQMF = QMF caseHaar = 'False' QMF = WMKOFILT('Haar', 1) print, ' ' PRINT, 'Good results only for the Haar wavelet.' PRINT, 'Will switch to your wavelet of choice after this calculation.' END ENDCASE sgt='Power Spectrum (Red) and Scalegram (Green) of '+st ;Signal title ndum = WDYADLNG(QMF,L) ;Get dyadic L from Quadrature Mirror Filter nx = WDYADLNG(x_work,J) ;Get dyadic J from signal array sg = FLTARR(J-1) ;Initialize scalegram array L_use = L - 1 IF ( L_use lt 1) THEN L_use = 1 ;Calculate Periodized Orthononormal Fast Wavelet Transform wc = WFWTPO( x_work, L_use, QMF ) FOR i = L, J-1 DO BEGIN sg(i-L) = WMEAN( (wc(WDYAD(i)-1))^2) ;place the wavelet coeffs into sg END nsp = N_ELEMENTS( x_work )/2 ;number of spectral elements sp = WSPECTRM( x_work, nsp ) ;sp = power spectrum sg = REVERSE( sg ) sp = REVERSE( sp )/SQRT(nx) tsg = L + INDGEN(J-L) - 1 tsp = 1 + INDGEN(nsp) tsp = ALOG(tsp) / ALOG(2) ymin = ALOG10(MIN([sp, sg])) ymax = ALOG10(MAX([sp,sg])) !c = 0 ;reset system cursor that min/max automatically sets ;Set up the plot window ;dummy values pt = '' & d = fltarr(2) WPLOTIT, pt, 3, d ;Plot, handling colors correctly. First, draw axes ;and title using default colors, then draw data points ;using the common variable colors PLOT, tsp, ALOG10(sp), /nodata, title=sgt, $ xtitle='log_2(time scale)', ytitle='log10(Power)', $ yrange=[ymin,ymax], color = cl, ystyle = 1, xstyle = 1 OPLOT, tsp, ALOG10(sp), linestyle=0, color=red OPLOT, tsg, ALOG10(sg), linestyle=0, color=green, psym = -7 IF caseHaar EQ 'False' then QMF = oldQMF END ;signal/data array ENDCASE ;TT END ;valid array or matrix ELSE: PRINT, 'Not valid data/signal array or matrix!' ENDCASE ;error ; Algorithm Source: WaveLab Version 0.600 ; WaveLab WWW site: http://playfair.stanford.edu/ ; WaveLab Questions? e-mail wavelab@playfair.stanford.edu END ;of pro WDOSCEG ;***************************************************