## Univariate Wavelet Regression

This section takes you through the features of 1-D wavelet regression estimation using one of the Wavelet Toolbox™ specialized tools. The toolbox provides a Wavelet Analyzer app to explore some denoising schemes for equally or unequally sampled data.

For the examples in this section, switch the extension mode to symmetric padding, using the command

```dwtmode('sym') ```

### Regression for Equally-Spaced Observations

1. Start the Regression Estimation 1-D Tool.

From the MATLAB® prompt, type `waveletAnalyzer`.

The Wavelet Analyzer appears.

Click the Regression Estimation 1-D menu item. The discrete wavelet analysis tool for 1-D regression estimation appears.

At the MATLAB command prompt, type

`load blocregdata;`

In the Regression Estimation 1-D tool, select File > Import from Workspace. When the Import from Workspace dialog box appears, select the `blocregdata` data. Click OK to import the data. The loaded data and processed data obtained after a binning are displayed.

3. Choose the processed data.

The default value for the number of bins is 256 for this example. Enter 64 in the Nb bins (number of bins) edit box, or use the slider to adjust the value. The new binned data to be processed appears.

The binned data appears to be very smoothed. Select 1000 from the Nb bins edit and press Enter or use the slider. The new data to be processed appears.

The binned data appears to be very close to the initial data, since `noisbloc` is of length 1024.

4. Perform a Wavelet Decomposition of the processed data.

Select the `haar` wavelet from the Wavelet menu and select 5 from the Level menu, and then click the Decompose button. After a pause for computation, the tool displays the detail coefficients of the decomposition.

5. Perform a regression estimation.

While a number of options are available for fine-tuning the estimation algorithm, we'll accept the defaults of fixed form soft thresholding and unscaled white noise. The sliders located to the right of the window control the level dependent thresholds, indicated by yellow dotted lines running horizontally through the graphs on the left part of the window.

Continue by clicking the Estimate button.

You can see that the process removed the noise and that the blocks are well reconstructed. The regression estimate (in yellow) is the sum of the signals located below it: the approximation a5 and the reconstructed details after coefficient thresholding.

You can experiment with the various predefined thresholding strategies by selecting the appropriate options from the menu located on the right part of the window or directly by dragging the yellow horizontal lines with the left mouse button.

Let us now illustrate the regression estimation using the Wavelet Analyzer app for randomly or irregularly spaced observations, focusing on the differences from the previous situation.

### Regression for Randomly-Spaced Observations

1. From the File menu, choose the Load > Data for Stochastic Design Regression option. When the Load data for Stochastic Design Regression dialog box appears, select the MAT-file `ex1nsto.mat`, which should reside in the MATLAB folder `toolbox/wavelet/wavelet`. Click the OK button. This short set of data (of size 500) is loaded into the Regression Estimation 1-D -- Stochastic Design tool.

The loaded data denoted (X,Y), the histogram of X, and the processed data obtained after a binning are displayed. The histogram is interesting, because the values of X are randomly distributed. The binning step is essential since it transforms a problem of regression estimation for irregularly spaced X data into a classical fixed design scheme for which fast wavelet transform can be used.

2. Select the `sym4` wavelet from the Wavelet menu, select 5 from the Level menu, and enter 125 in the Nb bins edit box. Click the Decompose button. The tool displays the detail coefficients of the decomposition.

3. From the Select thresholding method menu, select the item Penalize low and click the Estimate button.

4. Check Overlay Estimated Function to validate the fit of the original data.

### Importing and Exporting Information from the Wavelet Analyzer App

#### Saving Function

This tool lets you save the estimated function to disk. The toolbox creates a MAT-file in the current folder with a name you choose.

To save the estimated function from the present estimation, use the menu option File > Save Estimated Function. A dialog box appears that lets you specify a folder and filename for storing the function. Type the name `fex1nsto`. After saving the function data to the file `fex1nsto.mat`, load the variables into your workspace:

```load fex1nsto whos ```
NameSizeBytesClass
`thrParams``1x5``580``cell array`
`wname``1x4``8``char array`
`xdata``1x125``1000``double array`
`ydata``1x125``1000``double array`

The estimated function is given by `xdata` and `ydata`. The length of these vectors is equal to the number of bins you choose in step 2. In addition, the parameters of the estimation process are given by the wavelet name contained in `wname`:

```wname wname = sym4 ```

and the level dependent thresholds contained in `thrParams`, which is a cell array of length 5 (the level of the decomposition). For `i` from 1 to 5, `thrParams{i}` contains the lower and upper bounds of the interval of thresholding and the threshold value (since interval dependent thresholds are allowed). For more information, see 1-D Adaptive Thresholding of Wavelet Coefficients in the Wavelet Toolbox User's Guide.

For example, for level 1,

```thrParams{1} ans = -0.4987 0.4997 1.0395 ```

To load data for regression estimation, your data must be in the form of a structure array with exactly two fields. The fields must be named `xdata` and `ydata`, and must be the same length.

For example, load the file containing the data considered in the previous example:

```clear load ex1nsto whos ```
NameSizeBytesClass
`xdata``1x500``4000``double array`
`ydata``1x500``4000``double array`

At the end of this section, turn back the extension mode to zero padding using the command

```dwtmode('zpd') ```

Get trial now