# noisepsd

Power spectral density of filter output due to roundoff noise

## Syntax

``noisepsdOut = noisepsd(sysobj,L)``
``noisepsdOut = noisepsd(___,Name,Value)``
``noisepsdOut = noisepsd(sysobj,L,opts)``
``noisepsdOut = noisepsd(sysobj,'Arithmetic',arithType)``
``noisepsd(sysobj,___)``

## Description

````noisepsdOut = noisepsd(sysobj,L)` computes the power spectral density (PSD) of filter output occurring because of roundoff noise. The roundoff noise is produced by quantization errors within the filter. The PSD is computed as an average over the `L` trials.```
````noisepsdOut = noisepsd(___,Name,Value)` specifies options using one or more name-value pair arguments in addition to the input arguments in the previous syntax.```
````noisepsdOut = noisepsd(sysobj,L,opts)` uses an options object to specify the optional input parameters in lieu of specifying name-value pairs.```

example

````noisepsdOut = noisepsd(sysobj,'Arithmetic',arithType)` analyzes the filter System object™ based on the arithmetic specified in the `arithType` input.```
````noisepsd(sysobj,___)` with no output argument launches FVTool and shows the noise PSD estimate of the filter System object.```

## Examples

collapse all

Compute the PSD of the output noise caused by the quantization processes in a fixed-point, direct-form FIR filter. The input signal has fixed-point data type. The `noisepsd` function performs the analysis based on the data type of the locked input.

```b = firgr(27,[0 .4 .6 1],[1 1 0 0]); firfilt = dsp.FIRFilter('Numerator',b); % Create the filter object. data = fi(randn(15,16),1,16,3); output = firfilt(data);```

Quantize the filter to fixed-point. Plot the `hpsd` data. This is the data resulting from the noise PSD calculation. You can review the data in `hpsd.data`.

```hpsd = noisepsd(firfilt,'Arithmetic','fixed'); plot(hpsd)``` ## Input Arguments

collapse all

Number of trials used to compute the average, specified as a positive integer. The larger you specify L, the more accurate is the estimate of power spectral density but at the expense of longer computation time. When you do not specify `L`, the function sets L to the default value of 10 trials.

Data Types: `single` | `double`

Options object to specify the optional input parameters in lieu of specifying name-value pairs.

Create an `opts` object with

`opts = noisepsdopts(sysobj);`

`opts` then takes the `noisepsd` settings from `sysobj`.

Because `opts` is an object, use the `set` function to change the parameter values in `opts` before using it with the `noisepsd` function. For example, you could specify a new sample rate with

`set(opts,'NormalizedFrequency',false,'Fs',48e3);`

Arithmetic used in the analysis, specified as `'double'`, `'single'`, or `'Fixed'`. You cannot use the `'Arithmetic'` argument unless you know the data type of the input. If you do not specify the `'Arithmetic'` argument, that is, you use the syntax `noisepsdOut = noisepsd(sysobj)`, then the `noisepsd` function applies these rules:

• If the System object is `Unlocked` — The `noisepsd` function performs double-precision analysis.

• If the System object is `Locked` — The `noisepsd` function performs the analysis based on the data type of the locked input.

If you do specify the `'Arithmetic'` argument, that is, you use the syntax ```noisepsdOut = noisepsd(sysobj,'Arithmetic',arithType)```, the `noisepsd` function applies these rules depending on the value you set for `arithType`.

`Value`System Object StateRule
`arithType` = `'double'``Unlocked``noisepsd` performs double-precision analysis.
`Locked``noisepsd` performs double-precision analysis.
`arithType` = `'single'``Unlocked``noisepsd` performs single-precision analysis.
`Locked``noisepsd` performs single-precision analysis.
`arithType` = `'fixed'``Unlocked``noisepsd` produces an error because data type of the fixed-point input is unknown.
`Locked`When the input data type is double or single, then ```noisepsd ```produces an error because data type of the fixed-point input is unknown.
When the input data is of fixed-point type, `noisepsd` performs analysis based on the data type of the locked input.

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: ```b = firgr(27,[0 .4 .6 1],[1 1 0 0]); firfilt = dsp.FIRFilter('Numerator',b); noisepsdOut = noisepsd(firfilt);```

Number of FFT points used in calculating the PSD, specified as a positive integer. This value determines the length of the PSD data vector shown in the `Data` field of the `noisepsdOut` structure. When `'NFFT'` is set to an:

• Odd integer –– The length of the PSD data is given by (NFFT+1)/2.

• Even integer –– The length of the PSD data is given by (NFFT/2)+1.

When not specified, `NFFT` defaults to `512`.

Note

If the spectrum data you specify is calculated over half the Nyquist interval and you do not specify a corresponding frequency vector, the default frequency vector assumes that the number of points in the whole FFT is even. Also, the plot option to convert to a whole or two-sided spectrum assumes the original whole FFT length is even.

Data Types: `single` | `double`

Indicate whether to use normalized frequency or linear frequency, specified as either:

• `true` –– Use normalized frequency. When not specified, the function defaults to `true`.

• `false` –– Use linear frequency. When you specify `false`, you must supply the sampling frequency `Fs`.

Sampling frequency to be specified in Hz when `'NormalizedFrequency'` is set to `false`. When `'NormalizedFrequency'` is set to `true`, `'Fs'` is set to `'Normalized'`.

Data Types: `single` | `double`

Spectrum type of the generated PSD data, specified as:

• `'Onesided'` –– Converts the type to a spectrum that is calculated over half the Nyquist interval. All properties affected by the new frequency range are adjusted automatically.

• `'Twosided'` –– Converts the type to a spectrum that is calculated over the whole Nyquist interval. All properties affected by the new frequency range are adjusted automatically. If you choose a two-sided computation, you can also choose `'CenterDC'` as `true`. Otherwise, `'CenterDC'` must be `false`.

Shift the zero-frequency component to the center of a two-sided spectrum.

• When you set `'SpectrumType'` to `'Onesided'`, it is changed to `'Twosided'` and the data is converted to a two-sided spectrum.

• Setting `'CenterDC'` to `false` shifts the data and the frequency values in the object so that DC is in the left edge of the spectrum. This operation does not affect the `'SpectrumType'` property setting.

## Output Arguments

collapse all

Data object containing the PSD data, returned as a `psd` object. To extract the PSD vector from `noisepsdOut`, enter the following in the MATLAB® command prompt:

`get(noisepsdOut,'data')`

Plot the PSD data with `plot(noisepsdOut)`. The average power of the output noise (the integral of the PSD) can be computed with `avgpower`, a method of `dspdata` objects:

`avgpwr = avgpower(hpsd)`

 McClellan, James H., editor. Computer-Based Exercises for Signal Processing Using MATLAB 5. Prentice-Hall, 1998.

Watch now