Fourier, DCT and Hartley Transforms¶
Fast transforms on real data, including zoom FFT and FFT-based convolution.
Fourier¶
v_rfft
¶
V_RFFT - Calculate the DFT of real data, returning only the first half.
v_rfft
¶
Calculate the DFT of real data Y=(X,N,D).
Data is truncated/padded to length N if specified. N even: (N+2)/2 points are returned with the first and last being real N odd: (N+1)/2 points are returned with the first being real In all cases floor(1+N/2) points are returned. D is the dimension (0-based axis) along which to do the DFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Real input data. |
required |
n
|
int
|
Transform length. Default is the size of x along axis d. |
None
|
d
|
int
|
Axis along which to compute the FFT. Default is first axis with size > 1. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
The first floor(1+N/2) points of the DFT. |
Source code in pyvoicebox/v_rfft.py
v_irfft
¶
V_IRFFT - Inverse FFT of a conjugate symmetric spectrum.
v_irfft
¶
Inverse FFT of a conjugate symmetric spectrum X=(Y,N,D).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array_like
|
The first half of a complex spectrum (as produced by v_rfft). |
required |
n
|
int
|
Number of output points to generate. Default: 2*M-2 where M is size of y along axis d. Note: default is always even; specify n explicitly if odd output is desired. |
None
|
d
|
int
|
Axis along which to perform the transform. Default: first non-singleton dimension. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Real inverse DFT of y. |
Source code in pyvoicebox/v_irfft.py
v_rsfft
¶
V_RSFFT - FFT of a real symmetric spectrum.
v_rsfft
¶
FFT of a real symmetric spectrum X=(Y,N).
Y is the "first half" of a symmetric real input signal and X is the "first half" of the symmetric real Fourier transform.
If N is even, the "first half" contains 1+N/2 elements. If N is odd, the "first half" contains (N+1)/2 elements. If N is omitted it will be taken to be 2*(length(Y)-1) and is always even.
If Y is a matrix (2-D), the transform is performed along each column.
The inverse function is y = v_rsfft(x, n) / n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array_like
|
Real input data. Must be real-valued. |
required |
n
|
int
|
Full signal length. Default: 2*(M-1) where M is the number of rows. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
The first half of the symmetric real Fourier transform. |
Source code in pyvoicebox/v_rsfft.py
v_zoomfft
¶
V_ZOOMFFT - DTFT evaluated over a linear frequency range.
v_zoomfft
¶
DTFT evaluated over a linear frequency range Y=(X,N,M,S,D).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input vector or array. |
required |
n
|
float
|
Reciprocal of normalized frequency increment (can be non-integer). The frequency increment is fs/n. Default: size(x, d). |
None
|
m
|
int
|
Number of output points is floor(m). Default: floor(n). |
None
|
s
|
float
|
Starting frequency index (can be non-integer). The starting frequency is s*fs/n. Default: 0. |
0
|
d
|
int
|
Axis along which to do FFT (0-based). Default: first non-singleton. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Output DTFT coefficients. |
f |
ndarray
|
Normalized frequencies (1 corresponds to fs). |
Source code in pyvoicebox/v_zoomfft.py
DCT and Hartley¶
v_rdct
¶
V_RDCT - Discrete cosine transform of real data.
v_rdct
¶
Discrete cosine transform of real data Y=(X,N,A,B).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Real-valued input data. Transform is applied to columns. |
required |
n
|
int
|
Transform length. x will be zero-padded or truncated to length n. Default: number of rows of x. |
None
|
a
|
float
|
Output scale factor. Default: sqrt(2*n). |
None
|
b
|
float
|
Output scale factor for DC term. Default: 1. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
DCT output data. |
Source code in pyvoicebox/v_rdct.py
v_irdct
¶
V_IRDCT - Inverse discrete cosine transform of real data.
v_irdct
¶
Inverse discrete cosine transform of real data X=(Y,N,A,B).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array_like
|
DCT coefficients (as produced by v_rdct). Transform applied to columns. |
required |
n
|
int
|
Output length. Default: number of rows of y. |
None
|
a
|
float
|
Scale factor. Default: sqrt(2*m) where m is the number of rows of y. |
None
|
b
|
float
|
DC scale factor. Default: 1. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Inverse DCT output data. |
Source code in pyvoicebox/v_irdct.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
v_rhartley
¶
V_RHARTLEY - Calculate the Hartley transform of real data.
v_rhartley
¶
Calculate the Hartley transform of real data Y=(X,N).
Data is truncated/padded to length N if specified. The inverse transformation is x = v_rhartley(y, n) / n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Real input data. |
required |
n
|
int
|
Transform length. Default: length of x. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Hartley transform of x. |
Source code in pyvoicebox/v_rhartley.py
Convolution¶
v_convfft
¶
V_CONVFFT - 1-D convolution or correlation using FFT.
v_convfft
¶
1-D convolution or correlation using FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like or int
|
Input array, or size(x, d) when using precompute mode ('z' in m). If h is a _ConvFFTPrecomputed object, x is the input array. |
required |
h
|
array_like or _ConvFFTPrecomputed
|
Impulse response, or precomputed structure from previous call with 'z'. |
required |
d
|
int
|
Axis of x to do convolution along (0-based). Default: first non-singleton. |
None
|
m
|
str
|
Mode options: 'x' for real correlation, 'X' for complex correlation, 'z' for precomputation. |
''
|
h0
|
int
|
Origin sample number in h (1-based). Default: 1. |
1
|
x1
|
int
|
Start of range in x to align with origin of h (1-based). Default: 1. |
1
|
x2
|
int
|
End of range in x to align with origin of h (1-based). Default: size(x, d). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
z |
ndarray or _ConvFFTPrecomputed
|
Convolution output, or precomputed structure if 'z' in m. |
Source code in pyvoicebox/v_convfft.py
25 26 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
v_frac2bin
¶
V_FRAC2BIN - Convert a column vector to binary string representation.
v_frac2bin
¶
Convert a column vector to binary S=(D,N,M).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
array_like
|
Scalar or 1-D array of values to convert. |
required |
n
|
int
|
Minimum number of integer bits to output. If negative, leading zeros will be output as spaces for positions to the left of |n|'th integer column. Default: 1. |
1
|
m
|
int
|
Number of places after binary point. If negative, values are truncated rather than rounded. Default: 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
s |
list of str
|
List of binary string representations, one per input value. |