k-Wave Toolbox |

# spectrum

Compute the single sided amplitude and phase spectrums

## Syntax

    func_as = spectrum(func, Fs)
    func_as = spectrum(func, Fs, ...)
    [f, func_as] = spectrum(func, Fs)
    [f, func_as] = spectrum(func, Fs, ...)
    [f, func_as, func_ps] = spectrum(func, Fs)
    [f, func_as, func_ps] = spectrum(func, Fs, ...)

## Description

`spectrum` computes the single sided amplitude and phase spectrums of an abritrary one-dimensional input signal. For example, running the commands

    Fs = 10e6;          % [Hz]
    dt = 1/Fs;          % [s]
    t = 0:dt:1000*dt;   % [s]
    signal = 10*sin(0.5e6*2*pi*t) + 5*sin(1e6*2*pi*t) + 2*sin(2.5e6*2*pi*t);
    spectrum(signal, Fs, 'Plot', [true false]);

will produce the following amplitude spectrum.

## Inputs

`func` | signal to analyse
`Fs` | sampling frequency [Hz]

## Optional Inputs

Optional 'string', value pairs that may be used to modify the default computational settings.

Input | Valid Settings | Default | Description
--- | --- | --- | ---
`'FFTLength'` | (integer scalar) | signal length | Length of the FFT. If the set length is larger than the signal length, the signal is zero padded. If the set length is smaller than the signal length, the default value is used instead.
`'PowerTwo'` | (Boolean scalar) | `false` | Boolean controlling whether the FFT length is forced to be the next highest power of 2.
`'Plot'` | (Boolean scalar or two element vector) | `false` | Boolean controlling whether the amplitude and phase spectrums are plotted. Can be given as a two element array to control the display of the amplitude and phase spectrums, respectively.
`'Unwrap'` | (Boolean scalar) | `false` | Boolean controlling whether the phase spectum is unwrapped.
`'Window'` | (string) | `'Rectangular'` | Parameter string controlling the window type used to filter the signal before the FFT is taken. Any valid input types for `getWin` may be used.

## Outputs

`f` | frequency array
`func_as` | single sided amplitude spectrum
`func_ps` | single sided phase spectrum

## Examples

- Defining A Gaussian Sensor Frequency Response
- The Doppler Effect
- Filtering A Delta Function Input Signal
- Image Reconstruction With Compensation For Acoustic Absorption
- Source Smoothing
- Filtering A Delta Function Input Signal
- Modelling Power Law Absorption

## See Also

`smooth`, `filterTimeSeries`

© 2009, 2010 Bradley Treeby and Ben Cox.