Idk, i'll proly rebase
This commit is contained in:
@ -16,9 +16,11 @@ use egui_plot::PlotPoints;
|
||||
use egui_plot::Points;
|
||||
use num::Complex;
|
||||
use num::Integer;
|
||||
use oxydsp_dsp::blocks::filtering::fir::FirFilter;
|
||||
use oxydsp_dsp::blocks::iq::zero_if::ZeroIf;
|
||||
use oxydsp_dsp::blocks::math::basic::Multiplier;
|
||||
use oxydsp_dsp::blocks::synthesis::OscillatorSource;
|
||||
use oxydsp_dsp::blocks::utilities::adapters::FlatMap;
|
||||
use oxydsp_dsp::blocks::utilities::adapters::MapResultTagged;
|
||||
use oxydsp_dsp::blocks::utilities::adapters::NullSink;
|
||||
use oxydsp_dsp::blocks::utilities::adapters::Repeat;
|
||||
@ -73,14 +75,14 @@ fn demodulator()
|
||||
});
|
||||
|
||||
let (signal_source, signal) = IterSource::new(signal_rx.into_iter());
|
||||
let (zero_if, baseband) = ZeroIf::new(
|
||||
let (mut zero_if, baseband) = ZeroIf::new(
|
||||
signal,
|
||||
DigitalFrequency::from_time_frequency(CARRIER, SAMPLE_RATE as f64).into(),
|
||||
);
|
||||
// zero_if.set_fir(Fir::lowpass(
|
||||
// DigitalFrequency::from_time_frequency(CARRIER + 100., SAMPLE_RATE as f64),
|
||||
// 100,
|
||||
// ));
|
||||
zero_if.set_fir(Fir::lowpass(
|
||||
DigitalFrequency::from_time_frequency(CARRIER + 100., SAMPLE_RATE as f64),
|
||||
100,
|
||||
));
|
||||
|
||||
// Matched corellator
|
||||
let (tee, baseband, baseband_late) = Tee::new(baseband);
|
||||
@ -186,23 +188,42 @@ fn modulator()
|
||||
});
|
||||
|
||||
let mut tags = Tags::new();
|
||||
let (mut bit_source, bits) = RxSource::new(data_rx);
|
||||
let (bit_source, bits) = RxSource::new(data_rx);
|
||||
//let last_tag = tags.allocate_tag("finished");
|
||||
|
||||
let (phase_map, phase) = Scan::new(bits, 1., |state, bit| {
|
||||
let (phase_map, phase) = Scan::new(bits, Complex::<f32>::new(1., 0.), |state, bit| {
|
||||
if bit
|
||||
{
|
||||
*state *= -1.;
|
||||
*state *= Complex::new(1., 0.);
|
||||
}
|
||||
else
|
||||
{
|
||||
*state *= Complex::new(-1., 0.)
|
||||
}
|
||||
*state
|
||||
});
|
||||
let (repeater, phase) = Repeat::new(phase, SAMPLE_PER_SYMBOL);
|
||||
|
||||
// Convert to pulse train
|
||||
let (repeater, phase) = FlatMap::new(phase, |x| {
|
||||
let mut v = vec![Complex::<f32>::new(0., 0.); SAMPLE_PER_SYMBOL - 1];
|
||||
v.push(x);
|
||||
v
|
||||
});
|
||||
|
||||
// Pulse shaping
|
||||
// gaussian fir
|
||||
let fir = Fir((0..SAMPLE_PER_SYMBOL)
|
||||
.map(|x| gaussian(0.3, x as f32 / SAMPLE_PER_SYMBOL as f32))
|
||||
.collect());
|
||||
//.normalized();
|
||||
|
||||
let (phase_filter, phase) = FirFilter::new(phase, fir);
|
||||
|
||||
let (oscillator, passband) = OscillatorSource::<f32>::new(
|
||||
DigitalFrequency::from_time_frequency(CARRIER, SAMPLE_RATE as f64).into(),
|
||||
);
|
||||
let (multiplier, passband) = Multiplier::new(passband, phase);
|
||||
let (output_tx, output_rx) = sync_channel::<Complex<f32>>(48_000);
|
||||
let (output_tx, output_rx) = channel::<Complex<f32>>();
|
||||
let (tx_map, passband) = MapResultTagged::new(passband, move |s| {
|
||||
let _ = output_tx.send(s.0);
|
||||
// if s.retrieve(&last_tag).is_some()
|
||||
@ -214,16 +235,24 @@ fn modulator()
|
||||
let null_sink = NullSink::new(passband);
|
||||
|
||||
let graph = flowgraph![
|
||||
bit_source, phase_map, repeater, oscillator, multiplier, tx_map, null_sink
|
||||
bit_source,
|
||||
phase_map,
|
||||
repeater,
|
||||
oscillator,
|
||||
multiplier,
|
||||
tx_map,
|
||||
null_sink,
|
||||
phase_filter
|
||||
];
|
||||
graph.run();
|
||||
|
||||
let udp_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||
while let Ok(sample) = output_rx.recv()
|
||||
{
|
||||
std::thread::sleep(Duration::from_micros(20));
|
||||
let val = sample.re + random::<f32>() * 0.2;
|
||||
std::thread::sleep(Duration::from_micros(15));
|
||||
let val = sample.re + random::<f32>() * 0.5;
|
||||
let _ = udp_socket.send_to(&val.to_le_bytes(), "127.0.0.1:25565");
|
||||
let _ = udp_socket.send_to(&val.to_le_bytes(), "127.0.0.1:25566");
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,3 +281,9 @@ pub fn from_bits(n: [bool; 8]) -> u8
|
||||
| ((n[6] as u8) << 6)
|
||||
| ((n[7] as u8) << 7)
|
||||
}
|
||||
|
||||
pub fn gaussian(sigma: f32, t: f32) -> f32
|
||||
{
|
||||
let sq = (t - 0.5) / sigma;
|
||||
(-sq * sq).exp()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user