pyyeti.psd.interp

pyyeti.psd.interp(spec, freq, linear=False)[source]

Interpolate values on a PSD specification (or analysis curve).

Parameters:
  • spec (2d ndarray or 2-element tuple/list) – If ndarray, its columns are [Freq, PSD1, PSD2, ... PSDn]. Otherwise, it must be a 2-element tuple or list, eg: (Freq, PSD) where PSD is: [PSD1, PSD2, ... PSDn]. In the second usage, PSD can be 1d; in the first usage, PSD is always considered 2d. The frequency vector must be monotonically increasing.

  • freq (1d array) – Vector of frequencies to interpolate the specification to.

  • linear (bool) – If True, use linear interpolation to expand spec to the frequencies in freq. If False, spec is expanded via interpolation in log space. In other words:

    Use:

    When:

    linear=False

    spec is an actual PSD test specification – that is, it uses constant db/octave slopes

    linear=True

    spec doesn’t use constant db/octave slopes (eg, an analysis curve)

Returns:

psdfull (1d or 2d array) – Matrix of the interpolated PSD values. If 2d, has “n” columns (which will be one less than spec in the first usage above because the frequency column is not included). Will be 1d if PSD was 1d on input.

Notes

For PSD data that is defined on a center-band frequency scale, use rescale() instead.

Zeros are used to fill in PSD values for frequencies outside the specification(s).

Any NaNs in the specification frequency are deleted (along with the corresponding PSD values) before interpolation. This is done by the routine proc_psd_spec().

See also

rescale()

Examples

>>> import numpy as np
>>> from pyyeti import psd
>>> spec = np.array([[20, .0053],
...                  [150, .04],
...                  [600, .04],
...                  [2000, .0036]])
>>> freq = [100, 200, 600, 1200]
>>> np.set_printoptions(precision=3)
>>> psd.interp(spec, freq).ravel()
array([ 0.027,  0.04 ,  0.04 ,  0.01 ])
>>> psd.interp(spec, freq, linear=True).ravel()
array([ 0.027,  0.04 ,  0.04 ,  0.024])

Using the second form of the spec input:

>>> spec = ([   20, 150, 600,  2000],
...         [.0053, .04, .04, .0036])
>>> psd.interp(spec, freq, linear=True)
array([ 0.027,  0.04 ,  0.04 ,  0.024])