Hi Joeal,
You may try something along the lines of:
import numpy as np
def read_from_file(file_name, count=-1):
dt = np.dtype('<i2')
samples = np.fromfile(file_name, dt,
count).astype(np.float32).view(np.complex64)
return samples
So this reads samples as two-byte integers (assuming little-endianness,
hence the '<'), cast them to four-byte floats, and then view the
resulting array as an array of eight-byte I/Q complex samples.
Imad
On 05/09/2019 22:51, Joeal Subash via USRP-users wrote:
Hi Michael,
I am having to save as ' sc16' because of storage restrictions using a
C++ program. I specifically need details on how to convert 'sc16' to
float. Thanks.
------------------------------------------------------------------------
*From:* michael.dick...@ettus.com <michael.dick...@ettus.com>
*Sent:* 05 September 2019 19:33:46
*To:* Joeal Subash (Electronic, Electrical and Systems Engineering)
*Cc:* USRP list
*Subject:* Re: [USRP-users] sc16 - complex<int16_t> to numpy float
Hi JS - Maybe check out this Python example from UHD <
https://github.com/EttusResearch/uhd/blob/master/host/examples/python/rx_to_file.py >
... it does Rx to file, and can save as NumPy format ... which could
then presumably be easily read back into NumPy. - MLD
On Thu, Sep 5, 2019 at 11:08 AM J Subash via USRP-users
<usrp-users@lists.ettus.com <mailto:usrp-users@lists.ettus.com>> wrote:
Hi,
I am using a B200 to save samples on the host as 'short' (as
described in the uhd <https://github.com/EttusResearch/uhd>/host
<https://github.com/EttusResearch/uhd/tree/master/host>/examples
<https://github.com/EttusResearch/uhd/tree/master/host/examples>/rx_samples_to_file.cpp),
which I believe is complex<int16_t>.
I'd like to import this data into numpy and then convert it into
floating point values. Is sc16 a fixed point representation, if
yes what is the scaling factor. If no, how do I convert it into a
numpy float in Python. Any help would be much appreciated. Thanks.
BW
JS
_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com <mailto:USRP-users@lists.ettus.com>
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
--
Michael Dickens, Mac OS X Programmer
Ettus Research Technical Support
Email: supp...@ettus.com <mailto:supp...@ettus.com>
Web: http://www.ettus.com
_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com