shift sin/cos before demodulation product to avoid i64

This commit is contained in:
Matt Huszagh 2021-01-12 16:07:04 -08:00
parent 41ea2ebed4
commit 80ed715f5a
2 changed files with 6 additions and 16 deletions

View File

@ -20,12 +20,6 @@ pub fn shift_round(x: i32, shift: usize) -> i32 {
(x + (1 << (shift - 1))) >> shift (x + (1 << (shift - 1))) >> shift
} }
/// TODO consolidate with `shift_round`.
#[inline(always)]
pub fn shift_round64(x: i64, shift: usize) -> i64 {
(x + (1 << (shift - 1))) >> shift
}
/// Integer division, round up half. /// Integer division, round up half.
/// ///
/// # Arguments /// # Arguments

View File

@ -101,7 +101,7 @@ use dac::{Dac0Output, Dac1Output};
use dsp::{ use dsp::{
divide_round, iir, iir_int, divide_round, iir, iir_int,
pll::PLL, pll::PLL,
shift_round, shift_round64, shift_round,
trig::{atan2, cossin}, trig::{atan2, cossin},
}; };
use pounder::DdsOutput; use pounder::DdsOutput;
@ -1088,15 +1088,11 @@ const APP: () = {
let mut signal = (0_i32, 0_i32); let mut signal = (0_i32, 0_i32);
// TODO should we shift cos/sin first to avoid i64? // shift cos/sin before multiplying to avoid i64 multiplication
signal.0 = shift_round64( signal.0 =
adc_samples[0][i] as i16 as i64 * cos as i64, adc_samples[0][i] as i16 as i32 * shift_round(cos, 16);
16, signal.0 =
) as i32; adc_samples[0][i] as i16 as i32 * shift_round(sin, 16);
signal.1 = shift_round64(
adc_samples[0][i] as i16 as i64 * sin as i64,
16,
) as i32;
signal.0 = signal.0 =
iir_lockin.update(&mut iir_state_lockin[0], signal.0); iir_lockin.update(&mut iir_state_lockin[0], signal.0);