phase

Functions

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

phase [ 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 str

    • name of file containing numerator coefficients

  • -p str

    • name of file containing denominator coefficients

  • -u

    • perform phase unwrapping

  • infile str

    • double-type real sequence

  • stdout

    • double-type phase

The below example calculates phase spectrum from 10-th order filter coefficients:

phase -z data.z -m 10 -p data.p -n 10 -l 16 > data.ph

If the filter coefficients are stable, the below example gives the same result:

impulse -l 16 | dfs -z data.z -p data.p | phase -l 16 > data.ph
Parameters:
  • argc[in] Number of arguments.

  • argv[in] Argument vector.

Returns:

0 on success, 1 on failure.

See also

grpdelay fft fftr

class FilterCoefficientsToPhaseSpectrum

Transform filter coefficients to phase 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}\]
and the output is the \((L/2+1)\)-length phase spectrum:
\[ \begin{array}{cccc} \angle H(0), & \angle H(1), & \ldots, & \angle H(L/2), \end{array} \]
where \(L\) is the FFT length.

The general form of transfer function is given by

\[\begin{split}\begin{eqnarray} H(z) &=& \frac{\sum_{m=0}^M b(m) z^{-m}}{\sum_{n=0}^N a(n) z^{-n}} \\ &=& \frac{B(z)}{A(z)}. \end{eqnarray}\end{split}\]
where \(a(0)=1\). It can be rewritten as
\[\begin{split}\begin{eqnarray} H(z) &=& \frac{B_R(z) + i B_I(z)}{A_R(z) + i A_I(z)} \\ &=& \frac{B_R(z) + i B_I(z)}{A_R(z) + i A_I(z)} \cdot \frac{A_R(z) - i A_I(z)}{A_R(z) - i A_I(z)} \\ &=& \frac{B_R(z) A_R(z) + B_I(z) A_I(z)}{A_R^2(z) + A_I^2(z)} +i \frac{B_I(z) A_R(z) - B_R(z) A_I(z)}{A_R^2(z) + A_I^2(z)}. \end{eqnarray}\end{split}\]
where the subscripts \(R\) and \(I\) denote the real and imaginary parts. Thus
\[\begin{split}\begin{eqnarray} \angle H(z) &=& \tan^{-1} \left(\frac{H_I(z)}{H_R(z)}\right) \\ &=& \tan^{-1} \left( \frac{B_I(z) A_R(z) - B_R(z) A_I(z)} {B_R(z) A_R(z) + B_I(z) A_I(z)} \right). \end{eqnarray}\end{split}\]

Public Functions

FilterCoefficientsToPhaseSpectrum(int num_numerator_order, int num_denominator_order, int fft_length, bool unwrapping)
Parameters:
  • num_numerator_order[in] Order of numerator coefficients, \(M\).

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

  • fft_length[in] Number of FFT bins, \(L\).

  • unwrapping[in] If true, perform phase unwrapping.

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 bool IsUnwrapped() const
Returns:

True if unwrapping is performed.

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> *phase_spectrum, FilterCoefficientsToPhaseSpectrum::Buffer *buffer) const
Parameters:
  • numerator_coefficients[in] \(M\)-th order coefficients.

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

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

  • buffer[out] Buffer.

Returns:

True on success, false on failure.

class Buffer

Buffer for FilterCoefficientsToPhaseSpectrum class.