signal_generator: actually catch the extreme symmetry cases (0 and 1)

This commit is contained in:
Robert Jördens 2021-07-27 14:29:12 +02:00
parent cbd4a7d181
commit fc60887da3

View File

@ -65,8 +65,9 @@ impl TryFrom<BasicConfig> for Config {
type Error = Error; type Error = Error;
fn try_from(config: BasicConfig) -> Result<Config, Error> { fn try_from(config: BasicConfig) -> Result<Config, Error> {
let symmetry_complement = 1.0 - config.symmetry;
// Validate symmetry // Validate symmetry
if config.symmetry < 0.0 || config.symmetry > 1.0 { if config.symmetry < 0.0 || symmetry_complement < 0.0 {
return Err(Error::InvalidSymmetry); return Err(Error::InvalidSymmetry);
} }
@ -82,18 +83,19 @@ impl TryFrom<BasicConfig> for Config {
} }
// Calculate the frequency tuning words. // Calculate the frequency tuning words.
let frequency_tuning_word = { // Clip both frequency tuning words to within Nyquist before rounding.
let ftws = [ftw / config.symmetry, ftw / (1.0 - config.symmetry)]; let frequency_tuning_word = [
if config.symmetry * NYQUIST > ftw {
// Clip both frequency tuning words to within Nyquist before rounding. ftw / config.symmetry
if ftws[0] > NYQUIST {
[1u32 << 31, ftws[1] as u32]
} else if ftws[1] > NYQUIST {
[ftws[0] as u32, 1u32 << 31]
} else { } else {
[ftws[0] as u32, ftws[1] as u32] NYQUIST
} } as u32,
}; if symmetry_complement * NYQUIST > ftw {
ftw / symmetry_complement
} else {
NYQUIST
} as u32,
];
Ok(Config { Ok(Config {
amplitude: DacCode::try_from(config.amplitude) amplitude: DacCode::try_from(config.amplitude)