Open StrandmonYellow opened 2 weeks ago
Hi @StrandmonYellow - I think that the primary issue is that the digital signal bits are returned packed in a byte. So, you get 8 digital samples per byte. You can unpack them using numpy, like this:
y = np.unpackbits(y, bitorder='little')
If you want, you can also use the JLS library to compute average power for you much faster than from python and without having to load all the data. Replace that r.fsr
call with:
avg_power = r.fsr_statistics(power.signal_id, 0, p_length, 1)[0, jls.SummaryFSR.MEAN]
The UI uses this fsr_statistics call to compute power. It also truncates the signal to only what is stored for all included signals.
You will need to time align the GPI signal to the power signal. You can use the timestamp_to_sample_id
and sample_id_to_timestamp
methods for this. See the extract.py
entry point for an example.
Does this help?
This helps! Thanks. Why is time alignment necessary? I assume that the signals are sampled simultaneously? Only that the GPI signals are sampled with a twice as high frequency compared to the power signal.
The signals are sampled simultaneously, but the JLS file and recording makes no guarantee that the first samples are aligned across the signals. For a single Joulescope, you can use the signal's sample_id_offset
property to align them. However, this does not work for multiple Joulescopes. In general, it's better just to time align, which is not difficult.
Joulescope model
JS220
UI version
other
Your question
UI Version 1.1.10.
I want to do some calculations about the signals I recorded. I want to calculate the average power consumption of a signal whenever GPI[0] is High, and do the same for whenever GPI[0] is low. This could be done by using Python and CSV. However, If i have a ~251 second recording with a sample rate of 1Mhz, this export to CSV using the example python script takes a very long time.
So I tried to do it by reading the JLS files directly into python using the pyjls library. Here I can read the average power values without any problems. I can open a file and look at the number of samples in the recording for the power signal and the GPI[0] signal.
The output i get is what i expect:
To check if I am doing things correct, I can calculate the overall power of the complete recording to compare with the joulescope UI, and this returns almost the same value as the UI tells me. (I think the UI does some rounding before the calculations are being made vs when i do it with the raw values in python?)
I know that it is calculated over the complete dataset because with the IDE I am using, the length of the array is correct.
But now there is something I don't understand. When I do this for the GPI[0] signal, the output does not correspond to the number of samples I expect. For example, when I take the first 2000 samples, the output array is just 1/8th the length of what I expect.
With output:
I can confirm this using the IDE:
I think this has something to do with the sample_decimate_factor of 128 for the power signal, and 1024 for the GPI[0] signal. However, the signalDef that gets returned states a sample frequency of 2Mhz which would correspond with the duration of the recording (~251 seconds) and the given length of 503189504.
When I open the file in the Joulescope UI software, I can zoom in and see that there are twice as many datapoints for the GPI[0] signal when compared to the power signal, so the data is there inside of the file.
Is there a difference between the decimated saved data and the non-decimated saved data? what am I missing here.
What OS are you using?
Windows 11