| 16 | |
| 17 | impl Correlator { |
| 18 | fn sync(&mut self, input: &[Complex32]) -> (usize, f32) { |
| 19 | debug_assert_eq!(input.len(), SEARCH_WINDOW + 63); |
| 20 | |
| 21 | for i in 0..SEARCH_WINDOW { |
| 22 | unsafe { |
| 23 | let mut sum = Complex32::new(0.0, 0.0); |
| 24 | for k in 0..64 { |
| 25 | sum += *input.get_unchecked(i + k) * *LONG.get_unchecked(k); |
| 26 | } |
| 27 | *self.cor.get_unchecked_mut(i) = sum; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // let mut foo : Vec<(usize, Complex32)> = self.cor.iter().copied().enumerate().collect(); |
| 32 | // foo.sort_by(|x, y| y.1.norm().total_cmp(&x.1.norm())); |
| 33 | // println!("top {:?}", &foo[0..5]); |
| 34 | |
| 35 | self.cor_index.clear(); |
| 36 | self.cor_index |
| 37 | .extend(self.cor.iter().map(|x| x.norm_sqr()).enumerate()); |
| 38 | self.cor_index.sort_by(|x, y| y.1.total_cmp(&x.1)); |
| 39 | let (first, second) = if self.cor_index[0].0 < self.cor_index[1].0 { |
| 40 | (self.cor_index[0].0, self.cor_index[1].0) |
| 41 | } else { |
| 42 | (self.cor_index[1].0, self.cor_index[0].0) |
| 43 | }; |
| 44 | |
| 45 | ( |
| 46 | first, |
| 47 | (self.cor[first] * self.cor[second].conj()).arg() / 64.0, |
| 48 | ) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #[derive(Block)] |