spec

Functions

int main(int argc, char *argv[])

spec [ option ] [ infile ]

  • -l int

    • FFT length \((2 \le L)\)

  • -m int

    • order of numerator coefficients \((0 \le M < L)\)

  • -n int

    • order of denominator coefficients \((0 \le N < L)\)

  • -z string

    • filename of double-type numerator coefficients

  • -p string

    • filename of double-type denominator coefficients

  • -e double

    • small value added to power spectrum

  • -E double

    • relative floor in decibels

  • -o int

    • output format

      • 0 amplitude spectrum in dB

      • 1 log amplitude spectrum

      • 2 amplitude spectrum

      • 3 power spectrum

  • infile str

    • double-type data sequence

  • stdout

    • double-type spectrum

The below example performs spectral analysis. To prevent \(log(0)\), a small value is add to power spectrum using -e option.

frame -l 400 data.d | window -l 400 -L 512 | spec -l 512 -e 1e-6 > data.sp

Instead a relative floor value of spectrum can be set using -E option.

spec -E -30 data.d2 > data.sp

Parameters
  • argc[in] Number of arguments.

  • argv[in] Argument vector.

Returns

0 on success, 1 on failure.

class sptk::WaveformToSpectrum

Convert waveform to spectrum.

The input is the \(L\)-length waveform signals:

\[ \begin{array}{cccc} x(0), & x(1), & \ldots, & x(L-1). \end{array} \]
The output is the \((N/2+1)\)-length spectrum and takes one of the following forms.

Type 0:

\[ \begin{array}{cccc} 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, & 20 \log_{10}|H(N/2)|. \end{array} \]
Type 1:
\[ \begin{array}{cccc} \ln|H(0)|, & \ln|H(1)|, & \ldots, & \ln|H(N/2)|. \end{array} \]
Type 2:
\[ \begin{array}{cccc} |H(0)|, & |H(1)|, & \ldots, & |H(N/2)|. \end{array} \]
Type 3:
\[ \begin{array}{cccc} |H(0)|^2, & |H(1)|^2, & \ldots, & |H(N/2)|^2, \end{array} \]
where \(N\) is the FFT length.

Public Functions

WaveformToSpectrum(int frame_length, int fft_length, SpectrumToSpectrum::InputOutputFormats output_format, double epsilon, double relative_floor_in_decibels)
Parameters
  • frame_length[in] Frame length, \(L\).

  • fft_length[in] FFT length, \(N\).

  • output_format[in] Output format.

  • epsilon[in] Small value added to power spectrum.

  • relative_floor_in_decibels[in] Relative floor in decibels.

inline int GetFrameLength() const
Returns

Frame length.

inline int GetFftLength() const
Returns

FFT length.

inline SpectrumToSpectrum::InputOutputFormats GetOutputFormat() const
Returns

Output format.

inline double GetEpsilon() const
Returns

Epsilon.

inline double GetRelativeFloorInDecibels() const
Returns

Relative floor.

inline bool IsValid() const
Returns

True if this object is valid.

bool Run(const std::vector<double> &waveform, std::vector<double> *spectrum, WaveformToSpectrum::Buffer *buffer) const
Parameters
  • waveform[in] \(L\)-length waveform signals.

  • spectrum[out] \((N/2+1)\)-length spectrum.

  • buffer[out] Buffer.

Returns

True on success, false on failure.

class Buffer

Buffer for WaveformToSpectrum class.

class sptk::FilterCoefficientsToSpectrum

Convert filter coefficients to spectrum.

The input is the \(M\)-th order numerator coefficients and the \(N\)-th order denominator coefficients:

\[\begin{split} \begin{array}{cccc} b(0), & b(1), & \ldots, & b(M), \\ K, & a(1), & \ldots, & a(N). \end{array} \end{split}\]
The output is the \((L/2+1)\)-length spectrum and takes one of the following forms.

Type 0:

\[ \begin{array}{cccc} 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, & 20 \log_{10}|H(L/2)|. \end{array} \]
Type 1:
\[ \begin{array}{cccc} \ln|H(0)|, & \ln|H(1)|, & \ldots, & \ln|H(L/2)|. \end{array} \]
Type 2:
\[ \begin{array}{cccc} |H(0)|, & |H(1)|, & \ldots, & |H(L/2)|. \end{array} \]
Type 3:
\[ \begin{array}{cccc} |H(0)|^2, & |H(1)|^2, & \ldots, & |H(L/2)|^2, \end{array} \]
where \(L\) is the FFT length.

Public Functions

FilterCoefficientsToSpectrum(int num_numerator_order, int num_denominator_order, int fft_length, SpectrumToSpectrum::InputOutputFormats output_format, double epsilon, double relative_floor_in_decibels)
Parameters
  • num_numerator_order[in] Order of numerator coefficients, \(M\).

  • num_denominator_order[in] Order of denominator coefficients, \(N\).

  • fft_length[in] FFT length, \(L\).

  • output_format[in] Output format.

  • epsilon[in] Small value added to power spectrum.

  • relative_floor_in_decibels[in] Relative floor in decibels.

inline int GetNumNumeratorOrder() const
Returns

Order of numerator coefficients.

inline int GetNumDenominatorOrder() const
Returns

Order of denominator coefficients.

inline int GetFftLength() const
Returns

FFT length.

inline SpectrumToSpectrum::InputOutputFormats GetOutputFormat() const
Returns

Output format.

inline double GetEpsilon() const
Returns

Epsilon.

inline double GetRelativeFloorInDecibels() const
Returns

Relative floor.

inline bool IsValid() const
Returns

True if this object is valid.

bool Run(const std::vector<double> &numerator_coefficients, const std::vector<double> &denominator_coefficients, std::vector<double> *spectrum, FilterCoefficientsToSpectrum::Buffer *buffer) const
Parameters
  • numerator_coefficients[in] \(M\)-th order coefficients.

  • denominator_coefficients[in] \(N\)-th order coefficients.

  • spectrum[out] \((L/2+1)\)-length spectrum.

  • buffer[out] Buffer.

Returns

True on success, false on failure.

class Buffer

Buffer for FilterCoefficientsToSpectrum class.

class sptk::SpectrumToSpectrum

Convert spectrum to spectrum.

The input and output are the \((N/2+1)\)-length spectrum and take one of the following forms.

Type 0:

\[ \begin{array}{cccc} 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, & 20 \log_{10}|H(N/2)|. \end{array} \]
Type 1:
\[ \begin{array}{cccc} \ln|H(0)|, & \ln|H(1)|, & \ldots, & \ln|H(N/2)|. \end{array} \]
Type 2:
\[ \begin{array}{cccc} |H(0)|, & |H(1)|, & \ldots, & |H(N/2)|. \end{array} \]
Type 3:
\[ \begin{array}{cccc} |H(0)|^2, & |H(1)|^2, & \ldots, & |H(N/2)|^2, \end{array} \]
where \(N\) is the FFT length.

Public Types

enum InputOutputFormats

Input and output format.

Values:

enumerator kLogAmplitudeSpectrumInDecibels
enumerator kLogAmplitudeSpectrum
enumerator kAmplitudeSpectrum
enumerator kPowerSpectrum
enumerator kNumInputOutputFormats

Public Functions

SpectrumToSpectrum(int fft_length, InputOutputFormats input_format, InputOutputFormats output_format, double epsilon, double relative_floor_in_decibels)
Parameters
  • fft_length[in] FFT length, \(N\).

  • input_format[in] Input format.

  • output_format[in] Output format.

  • epsilon[in] Small value added to power spectrum.

  • relative_floor_in_decibels[in] Relative floor in decibels.

inline int GetFftLength() const
Returns

FFT length.

inline InputOutputFormats GetInputFormat() const
Returns

Input format.

inline InputOutputFormats GetOutputFormat() const
Returns

Output format.

inline double GetEpsilon() const
Returns

Epsilon.

inline double GetRelativeFloorInDecibels() const
Returns

Relative floor.

inline bool IsValid() const
Returns

True if this object is valid.

bool Run(const std::vector<double> &input, std::vector<double> *output) const
Parameters
  • input[in] \((N/2+1)\)-length spectrum.

  • output[out] \((N/2+1)\)-length spectrum.

Returns

True on success, false on failure.

bool Run(std::vector<double> *input_and_output) const
Parameters

input_and_output[inout] \((N/2+1)\)-length spectrum.

Returns

True on success, false on failure.

class OperationInterface

Interface of spectrum operation.

Public Functions

virtual bool Run(std::vector<double> *input_and_output) const = 0
Parameters

input_and_output[inout] Input/output spectrum.

Returns

True on success, false on failure.