# otnodes

Order terminal nodes of binary wavelet packet tree

## Syntax

``[Tn_Pal,Tn_Seq] = otnodes(WPT)``
``[Tn_Pal,Tn_Seq,I,J] = otnodes(WPT)``
``[DP_Pal,DP_Seq] = otnodes(WPT,'dp')``

## Description

example

````[Tn_Pal,Tn_Seq] = otnodes(WPT)` returns the terminal nodes of the binary wavelet packet tree, `WPT`, in Paley (natural) ordering, `Tn_Pal`, and sequency (frequency) ordering, `Tn_Seq`.```

example

````[Tn_Pal,Tn_Seq,I,J] = otnodes(WPT)` returns the permutations of the terminal node indices such that ```Tn_Seq = Tn_Pal(I)``` and `Tn_Pal = Tn_Seq(J)`.```

example

````[DP_Pal,DP_Seq] = otnodes(WPT,'dp')` returns the Paley- and frequency-ordered terminal nodes in node depth-position format.```

## Examples

collapse all

Order terminal nodes with Paley and frequency ordering.

```x = randn(8,1); wpt = wpdec(x,2,'haar'); [Tn_Pal,Tn_Seq] = otnodes(wpt)```
```Tn_Pal = 4×1 3 4 5 6 ```
```Tn_Seq = 4×1 3 4 6 5 ```

Return permutations for Paley and frequency ordering.

```load noisdopp; wpt = wpdec(noisdopp,6,'sym4'); [Tn_Pal,Tn_Seq,I,J] = otnodes(wpt); isequal(Tn_Seq(J),Tn_Pal)```
```ans = logical 1 ```
`isequal(Tn_Seq,Tn_Pal(I))`
```ans = logical 1 ```

Order terminal nodes by depth and position.

```x = randn(8,1); wpt = wpdec(x,2,'haar'); [DP_Pal,DP_Seq] = otnodes(wpt,'dp')```
```DP_Pal = 4×2 2 0 2 1 2 2 2 3 ```
```DP_Seq = 4×2 2 0 2 1 2 3 2 2 ```

Order terminal nodes from a modified wavelet packet tree.

```t = wptree(2,2,rand(1,512),'haar'); t = wpsplt(t,4); t = wpsplt(t,5); t = wpsplt(t,10); plot(t);``` ` [tn_Pal,tn_Seq,I,J] = otnodes(t)`
```tn_Pal = 7×1 3 9 21 22 11 12 6 ```
```tn_Seq = 7×1 3 21 22 9 6 12 11 ```
```I = 7×1 1 3 4 2 7 6 5 ```
```J = 7×1 1 4 2 3 7 6 5 ```

## Input Arguments

collapse all

Binary wavelet packet tree, specified as a `wptree` object. You can use `treeord` to determine the order of your wavelet packet tree.

## Output Arguments

collapse all

Terminal nodes in Paley (natural) ordering, returned as a N-by-1 column vector, where N is the number of terminal nodes.

Terminal nodes in sequency ordering, returned as a N-by-1 column vector, where N is the number of terminal nodes.

Permutations of Paley-ordered terminal node indices, returned as a N-by-1 column vector, where N is the number of terminal nodes. The permutations are such that ```Tn_Seq = Tn_Pal(I)```.

Permutations of sequency-ordered terminal node indices, returned as a N-by-1 column vector, where N is the number of terminal nodes. The permutations are such that ```Tn_Pal = Tn_Seq(J)```.

Paley-ordered terminal nodes in depth-position format, returned as a N-by-2 matrix, where N is the number of terminal nodes. The first column contains the depth index, and the second column contains the position index.

Sequency-ordered terminal nodes in depth-position format, returned as a N-by-2 matrix, where N is the number of terminal nodes. The first column contains the depth index, and the second column contains the position index. 