Cepstrum Module
The cepstrum module contains functions for cepstral analysis of signals.
| FUNCTION | DESCRIPTION |
|---|---|
complex_cepstrum |
Compute the complex cepstrum of a real sequence. |
real_cepstrum |
Compute the real cepstrum of a real sequence. |
inverse_complex_cepstrum |
Compute the inverse complex cepstrum of a real sequence. |
minimum_phase |
Compute the minimum phase reconstruction of a real sequence. |
Notes
The cepstrum is defined as the inverse Fourier transform of the logarithm of the Fourier transform of a signal. It has applications in speech processing, echo detection, and signal deconvolution.
Functions
complex_cepstrum
complex_cepstrum(
x: NDArray[float64], n: Optional[int] = None
) -> Tuple[NDArray[float64], NDArray[int_]]
Compute the complex cepstrum of a real sequence.
The complex cepstrum is given by: $$ c[n] = F^{-1}\left[\log_{10}\left(F{x[n]}\right)\right] $$
where \(x[n]\) is the input signal and \(F\) and \(F^{-1}\) are respectively the forward and backward Fourier transform.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Real sequence to compute complex cepstrum of. |
n
|
Length of the Fourier transform. |
| RETURNS | DESCRIPTION |
|---|---|
NDArray[float64]
|
The complex cepstrum of the real data sequence |
NDArray[int_]
|
The amount of samples of circular delay added to |
See Also
real_cepstrum: Compute the real cepstrum.inverse_complex_cepstrum: Compute the inverse complex cepstrum of a real sequence.
Examples:
In the following example we use the cepstrum to determine the fundamental frequency of a set of harmonics. There is a distinct peak at the quefrency corresponding to the fundamental frequency. To be more precise, the peak corresponds to the spacing between the harmonics.
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from acoustic_toolbox.cepstrum import complex_cepstrum
>>> fundamental = 100.0
>>> harmonics = np.arange(1, 30) * fundamental
>>> signal = np.sin(2.0*np.pi*harmonics[:,None]*t).sum(axis=0)
>>> ceps, _ = complex_cepstrum(signal)
>>> fig = plt.figure()
>>> ax0 = fig.add_subplot(211)
>>> ax0.plot(t, signal)
>>> ax0.set_xlabel('time in seconds')
>>> ax0.set_xlim(0.0, 0.05)
>>> ax1 = fig.add_subplot(212)
>>> ax1.plot(t, ceps)
>>> ax1.set_xlabel('quefrency in seconds')
>>> ax1.set_xlim(0.005, 0.015)
>>> ax1.set_ylim(-5., +10.)
References
- Wikipedia, "Cepstrum". http://en.wikipedia.org/wiki/Cepstrum
- M.P. Norton and D.G. Karczub, D.G., "Fundamentals of Noise and Vibration Analysis for Engineers", 2003.
- B. P. Bogert, M. J. R. Healy, and J. W. Tukey: "The Quefrency Analysis of Time Series for Echoes: Cepstrum, Pseudo Autocovariance, Cross-Cepstrum and Saphe Cracking". Proceedings of the Symposium on Time Series Analysis Chapter 15, 209-243. New York: Wiley, 1963.
Source code in acoustic_toolbox/cepstrum.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
real_cepstrum
Compute the real cepstrum of a real sequence.
The real cepstrum is given by: $$ c[n] = F^{-1}\left[\log_{10}\left|F{x[n]}\right|\right] $$
where \(x[n]\) is the input signal and \(F\) and \(F^{-1}\) are respectively the forward and backward Fourier transform.
Note that contrary to the complex cepstrum the magnitude is taken of the spectrum.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Real sequence to compute real cepstrum of. |
n
|
Length of the Fourier transform. |
| RETURNS | DESCRIPTION |
|---|---|
NDArray[float64]
|
The real cepstrum. |
See Also
complex_cepstrum: Compute the complex cepstrum of a real sequence.inverse_complex_cepstrum: Compute the inverse complex cepstrum of a real sequence.
Examples:
References
- Wikipedia, "Cepstrum". http://en.wikipedia.org/wiki/Cepstrum
Source code in acoustic_toolbox/cepstrum.py
inverse_complex_cepstrum
Compute the inverse complex cepstrum of a real sequence.
The inverse complex cepstrum is given by: $$ x[n] = F^{-1}\left[\exp(F(c[n]))\right] $$
where \(c[n]\) is the input signal and \(F\) and \(F^{-1}\) are respectively the forward and backward Fourier transform.
| PARAMETER | DESCRIPTION |
|---|---|
ceps
|
Real sequence to compute inverse complex cepstrum of. |
ndelay
|
The amount of samples of circular delay added to |
| RETURNS | DESCRIPTION |
|---|---|
NDArray[float64]
|
The inverse complex cepstrum of the real sequence |
See Also
complex_cepstrum: Compute the complex cepstrum of a real sequence.real_cepstrum: Compute the real cepstrum of a real sequence.
Examples:
Taking the complex cepstrum and then the inverse complex cepstrum results in the original sequence.
>>> import numpy as np
>>> from acoustic_toolbox.cepstrum import inverse_complex_cepstrum
>>> x = np.arange(10)
>>> ceps, ndelay = complex_cepstrum(x)
>>> y = inverse_complex_cepstrum(ceps, ndelay)
>>> print(x)
>>> print(y)
References
- Wikipedia, "Cepstrum". http://en.wikipedia.org/wiki/Cepstrum
Source code in acoustic_toolbox/cepstrum.py
minimum_phase
Compute the minimum phase reconstruction of a real sequence.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Real sequence to compute the minimum phase reconstruction of. |
n
|
Length of the Fourier transform. |
| RETURNS | DESCRIPTION |
|---|---|
NDArray[float64]
|
The minimum phase reconstruction of the real sequence |
Compute the minimum phase reconstruction of a real sequence using the real cepstrum.
See Also
real_cepstrum: Compute the real cepstrum.
Examples:
References
- Soo-Chang Pei, Huei-Shan Lin. Minimum-Phase FIR Filter Design Using Real Cepstrum. IEEE TRANSACTIONS ON CIRCUITS AND SYSTEMS-II: EXPRESS BRIEFS, VOL. 53, NO. 10, OCTOBER 2006
Source code in acoustic_toolbox/cepstrum.py
:::