Finalizes fft, working-ish bfsk
This commit is contained in:
16
src/bfsk.rs
16
src/bfsk.rs
@ -3,7 +3,7 @@
|
||||
use std::f32::consts::PI;
|
||||
|
||||
use crate::complex::{Complex, Complex32};
|
||||
use crate::fft::{self, windows, FFTDirection, FFT};
|
||||
use crate::fft::{self, FFT, FFTDirection, windows};
|
||||
use crate::map;
|
||||
use crate::nco::Nco;
|
||||
|
||||
@ -36,11 +36,7 @@ where
|
||||
self.sample_index = 0;
|
||||
let bit = self.bit_stream.next()?;
|
||||
|
||||
let frequency = if bit {
|
||||
self.deviation
|
||||
} else {
|
||||
-self.deviation
|
||||
};
|
||||
let frequency = if bit { self.deviation } else { -self.deviation };
|
||||
self.oscillator.set_frequency(frequency);
|
||||
}
|
||||
|
||||
@ -65,15 +61,15 @@ pub struct BFSKDem {
|
||||
impl BFSKDem {
|
||||
pub fn new(samples_per_bit: u32, deviation: f32) -> Self {
|
||||
// Calculate bin locations :
|
||||
let bin_index = map(deviation, 0., 2. * PI, 0., samples_per_bit as f32).floor() as u32;
|
||||
let bin_index = map(deviation, 0., 2. * PI, 0., samples_per_bit as f32).round() as u32;
|
||||
|
||||
println!("bin_index: {bin_index}");
|
||||
|
||||
|
||||
BFSKDem {
|
||||
samples_per_bit,
|
||||
deviation,
|
||||
sample_index: 0,
|
||||
fft: FFT::new(samples_per_bit as usize, windows::rectangular),
|
||||
fft: FFT::new(samples_per_bit as usize, windows::bartlett),
|
||||
bin_pos: bin_index as usize,
|
||||
bin_neg: (samples_per_bit - bin_index - 1) as usize, // -deviation = negative frequency = upper half
|
||||
}
|
||||
@ -86,6 +82,6 @@ impl BFSKDem {
|
||||
let positive_energy = self.fft.get_output()[self.bin_pos];
|
||||
let negative_energy = self.fft.get_output()[self.bin_neg];
|
||||
|
||||
positive_energy.mag() < negative_energy.mag()
|
||||
positive_energy.mag() > negative_energy.mag()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user