How do you read time or frequency domain L/R input data with Python?

Hi,
What is the REST syntax for reading the Left and Right data? I see in the webURL localhost:9402 served by the instrument it shows a syntax for graphing the left and right channel data. I’m going to present the following using the python syntax. So resp = requests.get.(“http://localhost:9402/Graph/Frequency/In/0”) , where the last zero specifies the left channel and 1 would specify the right channel.

On the same webURL it serves up it shows some syntax for reading raw frequency or time domain data, however, it does not show how to read the left or right channel. Does anyone know how to specify the left or right channel when reading raw data back? I need to gather the whole spectrum so that I can check that the noise level is below some levels.

The command i’m using looks like the following to get the left channel frequency input data …
resp = requests.get(‘http://localhost:9402/Data/Frequency/Input’) # get freq. domain data
resp_freq_L = resp.json()[‘Left’]

My second problem is how can I decode the json data? When I view the resp_freq_L, information it is a long string that looks like the following …

'8rZ6WiL1nj/4t3+b2B+lP9lDYnVOPJw/IPagksr3gD8U3/TyiA5GP92tWHxGEOk+hRAnelkO5j7XFHpWmTXiPnTpvaUbQuA+x0IVbnUs2j6ugEtmN7DQPplTYZws3cw+17Fkn6Ya0T6yNbi3VXvRPjjDmZlxa9A+OZfe9YPsyz5fj9iWajrGPov1Dclgsb4+epGlRN5qtT6/

The API suggest, it should be a " DoubleArrayResult JSON element". Does anyone know how to actually get the double array data out?

These are educated guesses based on the code you wrote,

Did you try?

data = resp.json()[“Right”]

Then it looks base 64 encoded so you could try this

import base64
text = base64.b64decode(data).decode()

And then depending on what the text looks like process it into an array?

I have not run this code nor used the REST API yet other than trying it out. So take that with a grain of salt. I did try to quickly find the info in the docs, but only had 2 mins to write this!

Hi,
Thanks! I found some information in the API which says the data is indeed Base64 encoded and double array data.

Here is what worked for me for getting the Left and Right time series data:

result2 = requests.get(‘http://localhost:9402/Data/Time/Input’) # get time domain data

N = result2.json()['Length']
raw_b64_str_left = result2.json()['Left']
raw_b64_str_right = result2.json()['Right']
utf8_str_left = base64.b64decode(raw_b64_str_left)        
utf8_str_right = base64.b64decode(raw_b64_str_right)        

dataL = utf8_str_left
dataR = utf8_str_right

cleaned_dataL = []
cleaned_dataR = []
struct_format = "<d"                # The left arrow means little endian, "d" means double 64bit data.  See: https://docs.python.org/3/library/struct.html).                                          
Ld = len(dataL)
for i in range(Ld // 8):
    cleaned_dataL.append(struct.unpack_from(struct_format, dataL, 8*i))
    cleaned_dataR.append(struct.unpack_from(struct_format, dataR, 8*i))

xL = np.squeeze(np.array(cleaned_dataL))
xR = np.squeeze(np.array(cleaned_dataR))
1 Like