thinkrf sample rate
This commit is contained in:
parent
3f8506f222
commit
2e0378ff9d
|
|
@ -306,15 +306,31 @@ class ThinkRF(SDR):
|
||||||
raise NotImplementedError("ThinkRF radios do not expose a controllable bias-tee")
|
raise NotImplementedError("ThinkRF radios do not expose a controllable bias-tee")
|
||||||
|
|
||||||
def _derive_decimation(self, target_sample_rate: int | float) -> int:
|
def _derive_decimation(self, target_sample_rate: int | float) -> int:
|
||||||
"""Round sample rate to nearest supported decimation."""
|
"""
|
||||||
|
Derive decimation from target sample rate.
|
||||||
|
Always rounds DOWN decimation (UP sample rate) to meet or exceed user's requested rate.
|
||||||
|
|
||||||
|
Example: 30 MS/s requested → dec 4 (31.25 MS/s), NOT dec 8 (15.625 MS/s)
|
||||||
|
"""
|
||||||
if not target_sample_rate:
|
if not target_sample_rate:
|
||||||
return 1
|
return 1
|
||||||
requested = float(target_sample_rate)
|
requested = float(target_sample_rate)
|
||||||
if requested >= self.BASE_SAMPLE_RATE:
|
if requested >= self.BASE_SAMPLE_RATE:
|
||||||
return 1
|
return 1
|
||||||
desired = self.BASE_SAMPLE_RATE / requested
|
|
||||||
# Always round UP to next decimation (lower sample rate) to avoid exceeding user request
|
desired_decimation = self.BASE_SAMPLE_RATE / requested
|
||||||
best = min((d for d in self.SUPPORTED_DECIMATIONS if d >= desired), default=self.SUPPORTED_DECIMATIONS[-1])
|
|
||||||
|
# Round DOWN decimation (UP sample rate) to meet or exceed requested rate
|
||||||
|
# Find largest decimation that gives sample rate >= requested
|
||||||
|
valid_decimations = [d for d in self.SUPPORTED_DECIMATIONS if d <= desired_decimation]
|
||||||
|
|
||||||
|
if valid_decimations:
|
||||||
|
# Use largest valid decimation (gives sample rate >= requested)
|
||||||
|
best = max(valid_decimations)
|
||||||
|
else:
|
||||||
|
# Requested rate too low, use minimum decimation (max sample rate)
|
||||||
|
best = self.SUPPORTED_DECIMATIONS[0]
|
||||||
|
|
||||||
return int(best)
|
return int(best)
|
||||||
|
|
||||||
def enforce_sample_rate(self, requested_sample_rate: int | float, decimation: Optional[int] = None) -> tuple[int, float]:
|
def enforce_sample_rate(self, requested_sample_rate: int | float, decimation: Optional[int] = None) -> tuple[int, float]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user