AnsweredAssumed Answered

AD9361 Data Format Conversion

Question asked by musb on Feb 8, 2017
Latest reply on Feb 19, 2017 by rgetz

I was mucking around with reading data off the AD9361 through libiio and noticed that the iio_channel_convert doesn't seem to be changing the samples.  Shouldn't it at least shift them to the right by 4 bits?

 

//loop through each sample (1 sample = I & Q) and save to structure
p_inc = iio_buffer_step(rx_buf);
p_end = iio_buffer_end(rx_buf);
for(p_dat = iio_buffer_first(rx_buf, ch_i); p_dat < p_end; p_dat += p_inc) {
     const int16_t i = ((int16_t*)p_dat)[0]; // Real (I)
     const int16_t q = ((int16_t*)p_dat)[1]; // Imag (Q)
     iio_channel_convert(ch_i, &samples[index].i, &i);
     iio_channel_convert(ch_q, &samples[index].q, &q);
     printf("%d - I: %d/%d\tQ: %d/%d\n", index, samples[index].i, i, samples[index].q, q);
     index += 1;
}

 

 

When I run this code, I get this:

0 - I: -17/-17  Q: -653/-653
1 - I: 530/530  Q: 379/379
2 - I: -619/-619        Q: 205/205
3 - I: 209/209  Q: -628/-628
4 - I: 383/383  Q: 544/544
5 - I: -668/-668        Q: -21/-21
6 - I: 414/414  Q: -526/-526
7 - I: 179/179  Q: 642/642
8 - I: -613/-613        Q: -241/-241
9 - I: 560/560  Q: -356/-356
10 - I: -39/-39 Q: 662/662
11 - I: -529/-529       Q: -422/-422

etc....

 

Now, per what I've read and this website (https://wiki.analog.com/resources/eval/user-guides/ad-fmcomms2-ebz/software/basic_iq_datafiles), I thought each sample would have 4 additional zeros in the least significant bits.  I also tested it with iio_channel_read (which should give you already converted values), and they all matched.

 

Thanks

Outcomes