code: public static void denoise(double[] t, Wavelet wavelet, boolean soft) {
          wavelet.transform(t);
  
          int n = t.length;
          int nh = t.length >> 1;
  
          double[] wc = new double[nh];
          System.arraycopy(t, nh, wc, 0, nh);
          double error = Math.mad(wc) / 0.6745;
  
          double lambda = error * Math.sqrt(2 * Math.log(n));
  
          if (soft) {
              for (int i = 2; i < n; i++) {
                  t[i] = Math.signum(t[i]) * Math.max(Math.abs(t[i]) - lambda, 0.0);
              }
          } else {
              for (int i = 2; i < n; i++) {
                  if (Math.abs(t[i]) < lambda) {
                      t[i] = 0.0;
                  }
              }
          }
          
          wavelet.inverse(t);
      }
docs: Adaptive denoising a time series with given wavelet.
  
  @param t the time series array. The size should be a power of 2. For time
  series of size no power of 2, 0 padding can be applied.
  @param wavelet the wavelet to transform the time series.
  @param soft true if apply soft thresholding.