DFT Trait

This commit is contained in:
2025-09-19 16:54:26 +02:00
parent 1392fe02bb
commit 6432ebfe02
7 changed files with 409 additions and 151 deletions

60
src/bfsk.rs Normal file
View File

@ -0,0 +1,60 @@
// 2-FSK Modulator
use crate::complex::Complex;
use crate::fft::FFT;
use crate::nco::Nco;
pub struct BFSKMod<'a, T: Iterator<Item = bool>> {
samples_per_bit: u32,
bandwidth: f32,
bit_stream: &'a mut T,
// State
oscillator: Nco,
sample_index: u32,
}
impl<'a, T> BFSKMod<'a, T>
where
T: Iterator<Item = bool>,
{
pub fn new(samples_per_bit: u32, bandwidth: f32, bit_stream: &'a mut T) -> Self {
BFSKMod {
samples_per_bit,
bandwidth,
oscillator: Nco::new(0.0),
bit_stream,
sample_index: samples_per_bit,
}
}
pub fn step_modulate(&mut self) -> Option<Complex<f32>> {
if self.sample_index == self.samples_per_bit {
self.sample_index = 0;
let bit = self.bit_stream.next()?;
let frequency = if bit {
self.bandwidth / 2.0
} else {
-self.bandwidth / 2.0
};
self.oscillator.set_frequency(frequency);
}
self.sample_index += 1;
self.oscillator.step();
Some(self.oscillator.cexp())
}
}
// FSK Demodulator (dumb non coherent + no symbol timing recovery)
pub struct BFSKDem {
samples_per_bit: u32,
deviation: f32,
// State
sample_index: u32,
fft: FFT,
}
impl BFSKDem {}