Function hackrfone::iq_to_cplx_f32[][src]

pub fn iq_to_cplx_f32(i: u8, q: u8) -> Complex<f32>
This is supported on crate feature num-complex only.
Expand description

Convert an IQ sample pair to a floating point complex number.

Generally you will want to use iq_to_cplx_i8 for storing or transfering data because the samples are 2-bytes in the native i8, vs 8-bytes in f32.

Floats are easier to work with for running samples through digital signal processing algorithms (e.g. discrete fourier transform) where the i8 can easily saturate.


Post-processing sample data.

use hackrfone::{iq_to_cplx_f32, HackRfOne, RxMode, UnknownMode};

let mut radio: HackRfOne<UnknownMode> = HackRfOne::new().unwrap();
let mut radio: HackRfOne<RxMode> = radio.into_rx_mode()?;
let data: Vec<u8> = radio.rx()?;

for iq in data.chunks_exact(2) {
    let cplx: num_complex::Complex<f32> = iq_to_cplx_f32(iq[0], iq[1]);
    // .. do whatever you want with cplx here

Guide level explanation.

use hackrfone::iq_to_cplx_f32;
use num_complex::Complex;

assert_eq!(iq_to_cplx_f32(255, 1), Complex::new(-1.0, 1.0));