function WPDNOISE, x,D,QMF,bb,st
;+
; NAME:
;	 WPDNOISE
;
; PURPOSE:
;	This function De-Noises in an adaptively chosen WP basis 
;
; CATEGORY:
;	Wavelets.
;
; CALLING SEQUENCE:
;	clean = WPDNOISE(x,D,QMF,bb,st) 
;
; INPUTS:
;   x   =    1-d signal to be de-noised. 
;   D   =    maximum depth of basis tree 
;   QMF =    quadrature mirror filter for freq. splitting 
;
; OUTPUTS:
;   clean   cleaned signal 
;   bb      basistree naming basis in which de-noising was done 
;   st      stat tree: statistics driving basis search 
;
;
; NOTES 
;   1. Assumes noise level eq 1 
;   2. Uses Stein Unbiased Estimate of risk to evaluate basis 
;   3. Uses Coifman-Wickerhauser BestBasis algorithm to select 
;      best basis 
;
;
; MODIFICATION HISTORY:
; 	Written by:	Amara Graps		December, 1994
;Translated from MatLab Wavelab routine: wpdenoise.m
;-

n = WDYADLNG(x,J) 
thr = SQRT(2 * ALOG( n * J) ) 

;Find Best Basis for De-Noising  
wp = WPANALYS(x,D,QMF) 
st = WSTATREE(wp,'SURE',thr) 
bb = WBBASIS(st,D,vt) 


;Apply thresholding in Best Basis 
dirtycoef = WUPKCOEF(bb,wp) 
cleancoef = WHARDTHR(dirtycoef,thr) 

;Transform back to time domain 
cleanwp   = WPKBCOEF(bb,wp,cleancoef) 
clean     = WPSYNTH(bb,cleanwp,QMF)       
     
     
;    
; Algorithm Source:  WaveLab Version 0.600
; WaveLab WWW site: http://playfair.stanford.edu/ 
; WaveLab Questions? e-mail wavelab@playfair.stanford.edu
;    
     
 
RETURN, clean  
END  
;***************************************************