diff options
-rw-r--r-- | Cargo.lock | 64 | ||||
-rw-r--r-- | src/main.rs | 44 |
2 files changed, 58 insertions, 50 deletions
@@ -32,9 +32,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cexpr" @@ -74,9 +74,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "fl2k_ampliphase" @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "lazy_static" @@ -154,9 +154,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "nix" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ "bitflags", "cfg-if", @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "nom" -version = "7.1.1" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -176,9 +176,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "peeking_take_while" @@ -188,9 +188,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -206,9 +206,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "regex-syntax", ] @@ -262,9 +262,9 @@ checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "which" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", "libc", @@ -310,42 +310,42 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" 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) |