Radio test

This commit is contained in:
2025-10-02 22:26:54 +02:00
parent 942cc1fdf0
commit cf527a13f2

View File

@ -58,7 +58,7 @@ where
{
((input - in_min.clone()) / (in_max - in_min)) * (out_max - out_min.clone()) + out_min
}
const BAUD_RATE: u32 = 1200;
const BAUD_RATE: u32 = 1000;
fn main() {
modulate();
@ -78,15 +78,15 @@ fn main() {
.with_sample_rate(SampleRate(48000));
// Channel to move samples from callback to main thread
let (tx, rx) = sync_channel::<f32>(1024);
let (tx, rx) = sync_channel::<f32>(4096);
// Build input stream
let stream = device
.build_input_stream(
&config.into(),
move |data: &[i16], _| {
move |data: &[f32], _| {
for x in data.iter() {
let _ = tx.send(*x as f32 / i16::MAX as f32); // non-blocking send
let _ = tx.send(*x * 10.); // non-blocking send
}
},
move |err| eprintln!("Stream error: {}", err),
@ -115,7 +115,7 @@ fn main() {
let samples = reader.samples::<i16>();
for x in samples {
let noise = rand.random::<f32>() * 2. - 1.;
let sample = x.unwrap() as f32 / i16::MAX as f32 + noise * 1.;
let sample = x.unwrap() as f32 / i16::MAX as f32 + noise * 0.9;
let _ = tx.send(sample);
writer
.write_sample((sample * i16::MAX as f32) as i16)
@ -156,16 +156,19 @@ fn demodulator(
// Corellators
let mut nco_pos = Nco::new(hz_to_rad_per_sample(deviation, sample_rate as f32));
let mut nco_neg = Nco::new(hz_to_rad_per_sample(-deviation, sample_rate as f32));
let corellator_pos = (0..sample_per_symbol)
.map(|_| {
let corellator_length = (sample_per_symbol as f32 * 1.5) as usize;
let corellator_pos = (0..corellator_length)
.map(|i| {
nco_pos.step();
nco_pos.cexp()
nco_pos.cexp() * windows::blackmann(i as f32 / (corellator_length as f32))
//nco_pos.cexp()
})
.collect::<Vec<_>>();
let corellator_neg = (0..sample_per_symbol)
.map(|_| {
let corellator_neg = (0..corellator_length)
.map(|i| {
nco_neg.step();
nco_neg.cexp()
nco_neg.cexp() * windows::blackmann(i as f32 / (corellator_length as f32))
//nco_neg.cexp()
})
.collect::<Vec<_>>();
let mut matched_filter_pos = FIRFilter::new(&corellator_pos);
@ -173,11 +176,11 @@ fn demodulator(
let mut elg_buffer = VecDeque::new();
let mut sps = sample_per_symbol as f32;
let delta = 0.3;
let loop_p = 0.1;
let loop_i = 0.3;
let mut loop_filter = FIRFilter::new(&[Complex32::new(1., 0.); 40]);
let mut matched_filter = FIRFilter::new(&[Complex32::new(1., 0.); 70]);
let delta = 0.5;
let loop_p = 0.8;
let loop_i = 0.2;
let mut loop_filter = FIRFilter::new(&[Complex32::new(1., 0.); 30]);
let mut matched_filter = FIRFilter::new(&[Complex32::new(1., 0.); 20]);
let mut current_position = 0.;
let mut next_sample = (sps as f32) / 2.;