Skip to content

Commit ecfac6c

Browse files
committed
Minor doc tweaks
1 parent ced2ca0 commit ecfac6c

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/sdr/_farrow.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def _compute_lagrange_basis(order: int) -> tuple[int, npt.NDArray, npt.NDArray]:
2020
"""
2121
# Support points (e.g., for 4-tap Lagrange interpolation centered at x = 0)
2222
# Indices for x[n-1], x[n], x[n+1], x[n+2]
23-
delay = order // 2
24-
x_points = np.arange(order + 1) - delay
23+
lookahead = order // 2
24+
x_points = np.arange(order + 1) - lookahead
2525

2626
# Store basis polynomials
2727
basis_polys = np.zeros((order + 1, order + 1), dtype=float)
@@ -36,7 +36,7 @@ def _compute_lagrange_basis(order: int) -> tuple[int, npt.NDArray, npt.NDArray]:
3636
# Compute Farrow coefficients. Convert
3737
farrow_coeffs = basis_polys.transpose()
3838

39-
return delay, basis_polys, farrow_coeffs
39+
return lookahead, basis_polys, farrow_coeffs
4040

4141

4242
@export
@@ -93,7 +93,7 @@ class FarrowFractionalDelay:
9393
.. ipython:: python
9494
9595
farrow = sdr.FarrowFractionalDelay(3)
96-
mu = np.linspace(0, farrow.order, 1000) - farrow.delay
96+
mu = np.linspace(0, farrow.order, 1000) - farrow.lookahead
9797
9898
plt.figure();
9999
for i in range(0, farrow.order + 1):
@@ -117,7 +117,7 @@ class FarrowFractionalDelay:
117117
118118
@savefig sdr_FarrowFractionalDelay_2.svg
119119
plt.figure(); \
120-
sdr.plot.time_domain(x, offset=-farrow.delay, marker=".", linestyle="none", label="Input"); \
120+
sdr.plot.time_domain(x, offset=-farrow.lookahead, marker=".", linestyle="none", label="Input"); \
121121
sdr.plot.time_domain(mu, y, label="Interpolated"); \
122122
plt.title("3rd order Lagrange interpolation");
123123
@@ -136,7 +136,7 @@ class FarrowFractionalDelay:
136136
sdr.plot.time_domain(sdr.FarrowFractionalDelay(1)(x, mu=mu), label="Farrow 1"); \
137137
sdr.plot.time_domain(sdr.FarrowFractionalDelay(2)(x, mu=mu), label="Farrow 2"); \
138138
sdr.plot.time_domain(sdr.FarrowFractionalDelay(3)(x, mu=mu), label="Farrow 3"); \
139-
plt.title(f"Fractional delay {mu} samples");
139+
plt.title(f"Fractional advance {mu} samples");
140140
141141
@savefig sdr_FarrowFractionalDelay_4.svg
142142
mu = 0.5; \
@@ -145,7 +145,7 @@ class FarrowFractionalDelay:
145145
sdr.plot.time_domain(sdr.FarrowFractionalDelay(1)(x, mu=mu), label="Farrow 1"); \
146146
sdr.plot.time_domain(sdr.FarrowFractionalDelay(2)(x, mu=mu), label="Farrow 2"); \
147147
sdr.plot.time_domain(sdr.FarrowFractionalDelay(3)(x, mu=mu), label="Farrow 3"); \
148-
plt.title(f"Fractional delay {mu} samples");
148+
plt.title(f"Fractional advance {mu} samples");
149149
150150
@savefig sdr_FarrowFractionalDelay_5.svg
151151
mu = 1; \
@@ -154,7 +154,7 @@ class FarrowFractionalDelay:
154154
sdr.plot.time_domain(sdr.FarrowFractionalDelay(1)(x, mu=mu), label="Farrow 1"); \
155155
sdr.plot.time_domain(sdr.FarrowFractionalDelay(2)(x, mu=mu), label="Farrow 2"); \
156156
sdr.plot.time_domain(sdr.FarrowFractionalDelay(3)(x, mu=mu), label="Farrow 3"); \
157-
plt.title(f"Fractional delay {mu} samples");
157+
plt.title(f"Fractional advance {mu} samples");
158158
159159
Group:
160160
dsp-arbitrary-resampling
@@ -182,9 +182,8 @@ def __init__(self, order: int, alpha: float = 0.5, streaming: bool = False):
182182
self._streaming = verify_bool(streaming)
183183
self._state: npt.NDArray # FIR filter state. Will be updated in reset().
184184

185-
self._delay, self._lagrange_polys, self._taps = _compute_lagrange_basis(self._order)
186-
self._lookahead = self._taps.shape[1] - self._delay - 1 # The number of samples needed before the current input
187-
self._delay, self._lookahead = self._lookahead, self._delay # Switch because correlation not convolution
185+
self._lookahead, self._lagrange_polys, self._taps = _compute_lagrange_basis(self._order)
186+
self._delay = self._taps.shape[1] - self._lookahead - 1 # The number of samples needed before the current input
188187
self._n_extra = 1 # Save one extra sample in the state than necessary
189188

190189
self.reset()
@@ -306,6 +305,7 @@ def __str__(self) -> str:
306305
string += f"\n taps: {self.taps.shape} shape"
307306
string += f"\n {np.array2string(self.taps, prefix=' ')}"
308307
string += f"\n delay: {self.delay}"
308+
string += f"\n lookahead: {self.lookahead}"
309309
string += f"\n streaming: {self.streaming}"
310310
return string
311311

@@ -410,6 +410,16 @@ def delay(self) -> int:
410410
"""
411411
return self._delay
412412

413+
@property
414+
def lookahead(self) -> int:
415+
r"""
416+
The number of samples needed before the current input sample.
417+
418+
Examples:
419+
See the :ref:`farrow-arbitrary-resampler` example.
420+
"""
421+
return self._lookahead
422+
413423

414424
@export
415425
class FarrowResampler(FarrowFractionalDelay):

0 commit comments

Comments
 (0)