# SbSmooth

## Overview

Subband smoothing across frequency bins

## Discussion

This module performs smoothing across frequency bins. Smoothing is done by averaging multiple bins to the left and right of a particular frequency sample. The smoothing only operates on real data. To smooth complex data it must first be decomposed into real and imaginary components.

The module supports two different forms of smoothing. In linear smoothing (type = 0), N bins to the left and N bins to the right of each bin are averaged, where N is a fixed number. The number of bins N is specified by the parameter .width, and .width is specified in Hz. If a bin is centered at frequency F, then the bins in the range [F-width F+width] are averaged.

In logarithmic smoothing (type = 1), M samples to the left and N samples to the right are averaged. .width then equals the number of octaves to the left and right that are averaged. If a bin is centered at frequency F, then the bins in the range [F*2^(-width) F*2^(width)] are averaged.

The module also checks to make sure that all of the bins to average are within the valid range. That is, the lower bin index is never less than 0 and the upper bin index never exceeds blockSize - 1.

Internally, the module uses a cumulative sum of values to reduce computation time. With this approach, the execution time is always a fixed constant independent of the smoothing width. Several hidden arrays are computed by the set function and used by the process function. startIndex[] and endIndex[] specify the starting and ending index of the cumulative sum to use. oneOverN[k] = 1 / (endIndex[k] - startIndex[k] + 1) and is used to speed up calculation of the average without requiring a divide. The module's process function computes (cumSum[endIndex[k]] - cumSum[startIndex[k]]) * oneOverN[k].

The module also supports a custom smoothing (type = 2). When custom smoothing is engaged, you have to manually set the 3 arrays startIndex[], endIndex[], and oneOverN[].

The parameter .startFreq allows you to specify that certain low frequency bins should not be smoothed. Only bins above .startFreq Hz are smoothed.

The module is designed to work with the wola_analysis_subsystem.m and the sample rate specified equals the decimated subband sample rate.

## Type Definition

CODE
``````typedef struct _ModuleSbSmooth
{
ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
INT32 type;                                   // Determines which type of smoothing is applied: Linear=0, Logarithmic=1, Custom=2
FLOAT32 startFreq;                            // Starting frequency for the smoothing operation
FLOAT32 width;                                // Amount of smoothing
INT32* startIndex;                            // Starting index for the averaging process.
INT32* endIndex;                              // Ending index for the averaging process.
FLOAT32* oneOverN;                            // Precomputed 1/N for averaging.
FLOAT32* cumSum;                              // Cumulative sum of values from the start of the buffer.
} ModuleSbSmoothClass;``````

## Variables

### Properties

 Name Type Usage isHidden Default value Range Units type int parameter 0 1 0:2 startFreq float parameter 0 0 0:3072000 Hz width float parameter 0 0.1667 0:2400 startIndex int* derived 1 [257 x 1] Unrestricted endIndex int* derived 1 [257 x 1] Unrestricted oneOverN float* derived 1 [257 x 1] Unrestricted cumSum float* state 1 [258 x 1] Unrestricted

### Pins

#### Input Pins

Name: in

Description: audio input

Data type: float

Channel range: 1

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

#### Output Pins

Name: out

Description: audio output

Data type: float

## MATLAB Usage

File Name: sb_smooth_module.m

CODE
`````` M=sb_smooth_module(NAME, BLOCKSIZE, SAMPLERATE)
Subband smoothing module which performs averaging across frequency
bands.  The module supports linear or logarithmic smoothing across
bands.  Arguments:
NAME - name of the module.
BLOCKSIZE - initial BLOCKSIZE (the final BLOCKSIZE is taken from the
input wire).
SAMPLERATE - sample rate of the corresponding time domain signal.  If
this is empty (the default), then the module assumes that
it is being used with 2x oversampling WOLA filterbank.
You can manually override this time setting this, for
example, to 16000.