signal_generator: actually catch the extreme symmetry cases (0 and 1)
This commit is contained in:
parent
cbd4a7d181
commit
fc60887da3
@ -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 = {
|
|
||||||
let ftws = [ftw / config.symmetry, ftw / (1.0 - config.symmetry)];
|
|
||||||
|
|
||||||
// Clip both frequency tuning words to within Nyquist before rounding.
|
// Clip both frequency tuning words to within Nyquist before rounding.
|
||||||
if ftws[0] > NYQUIST {
|
let frequency_tuning_word = [
|
||||||
[1u32 << 31, ftws[1] as u32]
|
if config.symmetry * NYQUIST > ftw {
|
||||||
} else if ftws[1] > NYQUIST {
|
ftw / config.symmetry
|
||||||
[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)
|
||||||
|
Loading…
Reference in New Issue
Block a user