aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs
index 54f7171..e35062e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -69,8 +69,8 @@ impl<T> BufferDumper<T> {
}
struct DDS {
- trig_table_quadrature: Vec<i8>,
- trig_table_inphase: Vec<i8>,
+ trig_table_carrier_1: Vec<i8>,
+ trig_table_carrier_2: Vec<i8>,
/* instantaneous phase */
phase: u32,
@@ -83,23 +83,23 @@ struct DDS {
}
impl DDS {
- fn init(samp_rate: f32, freq: f32, phase: f32, waveform: Waveform) -> Self {
- let mut trig_table_inphase = Vec::with_capacity(TRIG_TABLE_LEN);
- let mut trig_table_quadrature = Vec::with_capacity(TRIG_TABLE_LEN);
+ fn init(samp_rate: f32, freq: f32, carrier_phase_delta: f32, waveform: Waveform) -> Self {
+ let mut trig_table_carrier_1 = Vec::with_capacity(TRIG_TABLE_LEN);
+ let mut trig_table_carrier_2 = Vec::with_capacity(TRIG_TABLE_LEN);
let incr = 1.0f32 / TRIG_TABLE_LEN as f32;
for i in 0..TRIG_TABLE_LEN {
- let inphase = f32::cos(incr * i as f32 * 2.0 * PI) * 127.0;
- let quadrature = f32::sin(incr * i as f32 * 2.0 * PI) * 127.0;
+ let c1 = f32::sin((incr * i as f32 + carrier_phase_delta/2.0) * 2.0 * PI) * 127.0;
+ let c2 = f32::sin((incr * i as f32 - carrier_phase_delta/2.0) * 2.0 * PI) * 127.0;
match waveform {
Waveform::Sine => {
- trig_table_inphase.push(f32::round(inphase) as i8);
- trig_table_quadrature.push(f32::round(quadrature) as i8);
+ trig_table_carrier_1.push(f32::round(c1) as i8);
+ trig_table_carrier_2.push(f32::round(c2) as i8);
}
Waveform::Rect => {
- trig_table_inphase.push(if inphase >= 0.0 { 127 } else { -127 });
- trig_table_quadrature.push(if quadrature >= 0.0 { 127 } else { -127 });
+ trig_table_carrier_1.push(if c1 >= 0.0 { 127 } else { -127 });
+ trig_table_carrier_2.push(if c2 >= 0.0 { 127 } else { -127 });
}
}
}
@@ -107,9 +107,9 @@ impl DDS {
let phase_step = (freq / samp_rate) * 2.0 * PI * ANG_INCR;
DDS {
- trig_table_quadrature,
- trig_table_inphase,
- phase: f32::round(phase * ANG_INCR) as u32,
+ trig_table_carrier_1,
+ trig_table_carrier_2,
+ phase: 0,
phase_step: f32::round(phase_step) as u32,
phase_delta: 0,
phase_slope: 0,
@@ -131,7 +131,8 @@ fn main() {
opts.optopt("d", "device-index", "Select device index", "DEVINDEX");
opts.optopt("c", "center-freq", "Center frequency in Hz (default: 1440 kHz)", "FREQ");
opts.optopt("s", "samplerate", "Samplerate in Hz (default: 96 MS/s)", "RATE");
- opts.optopt("m", "mod-index", "Modulation index (default: 0.25)]", "FACTOR");
+ opts.optopt("m", "mod-index", "Modulation index (default: 0.25)", "FACTOR");
+ opts.optopt("p", "carrier-phase", "Carrier phase difference (default: 90)", "DEGREES");
opts.optopt("i", "input-rate", "Input baseband sample rate (default: 48000 Hz)", "RATE");
opts.optopt("w", "waveform", "(sine|rect) default: rect", "WAVEFORM");
opts.optflag("C", "device-count", "Return FL2K device count and quit");
@@ -183,6 +184,12 @@ fn main() {
None => 0.25,
};
+ let carrier_phase_delta_degrees = match cli_args.opt_str("p") {
+ Some(s) => s.parse().expect("floating point value"),
+ None => 90.0,
+ };
+ let carrier_phase_delta = carrier_phase_delta_degrees * PI / 180.0;
+
let waveform = match cli_args.opt_str("w") {
None => Waveform::Rect,
Some(w) if w == "sine" => Waveform::Sine,
@@ -211,6 +218,7 @@ fn main() {
eprintln!("Input rate: {} kHz", (input_rate as f32)/1e3);
eprintln!("Samplerate: {} MHz", (samp_rate as f32)/1e6);
eprintln!("Center frequency: {} kHz", base_freq/1e3);
+ eprintln!("Carrier phase d {} deg ({} rad)", carrier_phase_delta_degrees, carrier_phase_delta);
let running = Arc::new(AtomicBool::new(true));
@@ -341,7 +349,7 @@ fn main() {
// Read PD and PDSLOPE, interpolate to higher rate
thread::spawn(move || {
- let mut dds = DDS::init(samp_rate as f32, base_freq, 0.0, waveform);
+ let mut dds = DDS::init(samp_rate as f32, base_freq, carrier_phase_delta, waveform);
let mut debug_writer = match output {
Output::Debug => Some(BufWriter::new(File::create("debug-dds.csv").expect("create file"))),
@@ -367,8 +375,8 @@ fn main() {
panic!("Phase IDX out of bounds");
}
- out_i.push(dds.trig_table_inphase[phase_idx_i as usize]);
- out_q.push(dds.trig_table_quadrature[phase_idx_q as usize]);
+ out_i.push(dds.trig_table_carrier_1[phase_idx_i as usize]);
+ out_q.push(dds.trig_table_carrier_2[phase_idx_q as usize]);
if let Some(w) = &mut debug_writer {
writeln!(w, "{},{},{},{},{}", ix, dds.phase, dds.phase_delta, phase_idx_i, phase_idx_q)