Test and Measurement Forum

Different Downsampling Ratios

Post your MATLAB discussions here

Different Downsampling Ratios

Postby conrads » Mon Jul 25, 2016 2:16 pm

Hello all,

I would like to capture data from a PicoScope 4824 using two different downsampling ratios for different channels when the device is operated in streaming mode. To be more specific, I would like to stream data from a certain number of channels without any downsampling while the other channels should be streamed using downsampling performed by the firmware.

From the programmer's guide I understand that this should be possible:
You can collect data from the PicoScope 4000 driver with a different downsampling factor when ps4000aRunBlock or ps4000aRunStreaming has already been called and has successfully captured all the data.


However, I am not quite sure if it is possible to implement this using the Matlab interface. As a first step, I simply tried to set up two streamingGroupObj with different downsampling ratios, but this seems to be the wrong way.

I would appreciate any hints or comments.
Thanks a lot

Conrad
conrads
Newbie
 
Posts: 0
Joined: Mon Jul 25, 2016 1:57 pm

Re: Different Downsampling Ratios

Postby Hitesh » Tue Jul 26, 2016 8:48 am

Hi Conrad,

There are two potential solutions to your requirement, both of which would require a modification to the ps4000aWrap.dll.

The first would be to modify the wrapper library to allow for buffers to be setup for each of the channels depending, taking into account the ratio mode. The streaming callback would then copy the data as required.

The second would involve implementing the ps4000aGetValuesAsync() function in the wrapper, then the process would be to setup the buffers for one ratio mode, retrieve the data and then repeat for the next ratio mode.

Which ratio modes do you intend to use, and for which channels?

Edit: I have run some tests here using C/C++ code and it is possible to start streaming data collection with the ratio mode set to a combination of aggregation, decimation and averaging. Please note that it is not possible to retrieve raw data from the driver during the data collection when the ratio mode is set for downsampling.

If you have set the data collection for downsampling (e.g. averaging or averaging and aggregation), and require raw data as well, you will need to setup data buffers for your raw data and use the ps4000aGetValuesAsync() function to retrieve the raw data values after calling ps4000aStop().

Regards,
Last edited by Hitesh on Tue Aug 09, 2016 11:56 am, edited 2 times in total.
Reason: Updated to highlight what is possible with downsampling in streaming mode
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Different Downsampling Ratios

Postby martinR » Thu Aug 18, 2016 9:10 am

Hello,

I am working with Conrad on this project. We now have decided to use C instead of Matlab but as I didn't want to create a new thread maybe an admin could put the thread into the correct subforum.

I have tried to understand the C Example and use it as a baseline to solve our problem. Sadly I don't seam to be able to figure it out. First I want to explain our goal a littele bit more detailed. We want to collect data via streaming over a very long period of time. Therefore, RAM usage can be an issue if we have a lot of samples for all channels. One signal has a much higher frequency then all other signals, so we only need a high sampling rate for that channel. All other channels could be collect with a lower sampling rate so we would have less memory usage. Therefore we want to use downsampling on those other channels, idealy done durnig data collection by the hardware already.

Now the question is, if this is possible and how?

I have looked into the different functions in the programmers guide, especially the GetValuesAsync(). From what I understand is, that this function is called after all data is collected, so we would actually not have less RAM usage, as all channels are collected using the high sampling rate and only downsampled in the end. Is this correct or have I missunderstood anything?

Also, how can I call channels indivdually? If I understand GetValueAsync() correctly, I call a callback function in wich I can access the buffers like in the callBackStreaming() function. But as far as I understand, downsampling is done for every channel the same.

At the moment, I am trying to create my own workaround. I am waiting until the appBuffer is full and then I am using a user created function to downsample this chunk of data. As the appBuffer has a defined size I can ensure that memory usage is not an issue. But due to execution times I am a litte bit scared that I might miss some data points if the calculations are done by the application while streaming is active. Can you tell me if my approach is viable? Is there an easier solution that I might have overlooked?

Please note, that for testing purposes, I don't have a PicoScope 4000 Series, but a PicoScope 5000A Series(5443A) unit at hand.

Thank you for your time and help.

Kind Regards

Martin
martinR
Newbie
 
Posts: 0
Joined: Thu Aug 18, 2016 8:32 am

Re: Different Downsampling Ratios

Postby Hitesh » Thu Aug 18, 2016 10:15 am

Hi Martin,

Referring to my previous post, it is possible to setup data buffers for each channel each corresponding to a different downsampling method. The ratio of downsampling would remain the same.

When you call the ps5000aRunStreaming() function, you can specify an OR of the ratio modes required e.g. averaging and decimation. However it is not possible to request raw and downsampled data during the data collection.

Although downsampled data will be returned, the driver will still hold raw data samples (equal to the sum of the pre- and post-trigger samples).

To retrieve raw data samples, you will need to use the ps5000aGetValuesAsync() call after stopping streaming data collection. You will need to setup data buffers for the channels that you require data for using ps5000aSetDataBuffer().

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Different Downsampling Ratios

Postby martinR » Thu Aug 18, 2016 11:04 am

Hello,

thank you for your replay. To clarify, the workflow would be to setup buffers for the channels I want to downsample like in the example and a buffer that can hold all collected data for the channel I want raw data. I then collect the data of the downsampled channels during streaming like in the Example and after collection is finished, I retrieve the data of the channel I want raw data using GetValueAsync?

I ask because if I understand the example correctly, the driverBuffer in the example does not hold all collected data but overrides the driverBuffer continuously.

Kind Regards

Martin
martinR
Newbie
 
Posts: 0
Joined: Thu Aug 18, 2016 8:32 am

Re: Different Downsampling Ratios

Postby Hitesh » Fri Aug 19, 2016 12:47 pm

Hi Martin,

The procedure to use would be as follows:

  • Set up the driver buffers for the channels to be downsampled (call ps5000aSetDataBuffer())
  • Setup temporary application buffers into which the driver buffer data will be copied in the streaming callback
  • Start the device streaming and collect data
  • Call ps5000aStop()
  • Setup new driver buffers for the raw data, calling ps5000aSetDataBuffer() (and appropriate application buffers)
  • Call ps5000aGetValuesAsync() to retrieve the data

You may wish to consider implementing a second callback function for the ps5000aGetValuesAsync() call. Also, you will need to poll a flag to check if this callback function has been called - i.e. data is available.

Hope this helps,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Different Downsampling Ratios

Postby martinR » Tue Aug 23, 2016 11:08 am

Hello,

thank you for your help. I have implemented your workflow and it is working fine if I collect the raw data for all channels aswell. But it behaves strange if I try to collect raw data only for certain channels.

I set up buffers for raw data like this:

Code: Select all
for (i = 0; i < unit->channelCount; i++)
   {
      if ((i >= DUAL_SCOPE && unit->channelCount == QUAD_SCOPE && powerStatus == PICO_POWER_SUPPLY_NOT_CONNECTED) || !rawData[i])
      {
         // No need to set the channels C and D if Quad channel scope and power supply not connected.
         // No need to set the channels if no raw data is needed.
         unit->channelSettings[i].enabled = FALSE;
      }
      else
      {
         buffers2[i * 2] = (int16_t*)calloc(preTrigger + postTrigger, sizeof(int16_t));
         buffers2[i * 2 + 1] = (int16_t*)calloc(preTrigger + postTrigger, sizeof(int16_t));

         status = ps5000aSetDataBuffers(unit->handle, (PS5000A_CHANNEL)i, buffers2[i * 2], buffers2[i * 2 + 1], preTrigger + postTrigger, 0, PS5000A_RATIO_MODE_NONE);

         appBuffers2[i * 2] = (int16_t*)calloc(preTrigger + postTrigger, sizeof(int16_t));
         appBuffers2[i * 2 + 1] = (int16_t*)calloc(preTrigger + postTrigger, sizeof(int16_t));

         printf(status ? "StreamDataHandler:ps5000aSetDataBuffers(channel %ld) ------ 0x%08lx \n" : "", i, status);
      }
   }

I use rawData[] to tell the application which channels I need raw data. I then call ps5000GetValuesAsync() like this:

Code: Select all
status = ps5000aGetValuesAsync(unit->handle, 0, preTrigger + postTrigger, 1, PS5000A_RATIO_MODE_NONE, 0, callBackStreaming, &bufferInfo2);


I would now assume that I would get preTrigger+postTrigger amount of data points, currently 1000000, for the channel I want raw data from. But for some reason I only get 50000 data points which is the sampleCount value previously set for streaming.

I use the same callBackStreaming() for both GetStreamingLatestValues() and GetValuesAsync(), but this doesn't make any problem when I set buffers for all channels. I thought through disabling certain channels I could achiev to only get raw data for certain channels.

Is there something I have overlooked?

Kind Regards

Martin

Edit: I have an additional question regarding memory. If I understand the functionality correctly, the osciloscope is saving the raw data in an internal buffer. In case of the 4824 this would be 256 MS and in case of the 5443A this would be 64 MS. As all channels are saved constantly, the maximum number of samples you can save per channel is 32 MS for the 4824 and 16 MS for the 5443A. This would limit the maximum duration of measurment or the maximum sample rate, as if the internal buffers are full, raw data gets lost as it is overwritten. My question is if I have understood this correctly and if there are ways to counteract this problem?
martinR
Newbie
 
Posts: 0
Joined: Thu Aug 18, 2016 8:32 am

Re: Different Downsampling Ratios

Postby Hitesh » Thu Aug 25, 2016 10:14 am

Hi Martin,

Could you please post your code here or e-mail it to support@picotech.com so that I can see the full code flow?

How are you calling the ps5000aRunStreaming() function i.e. what are the values for each argument? Which channels are you retrieving the raw data for using the ps5000aGetValuesAsync() function? Are you only setting up buffers for those channels prior to the call?

Which version of the ps5000a.dll driver are you using and is it 32-bit or 64-bit?

With regards to your edit, in streaming mode the buffer memory is used as a cache. The driver will use the PC memory to store values so that they can be retrieved later. As long as you are regularly retrieving the data values during the data collection process, you should not lose data for the real-time part of the collection (data will still be there post-capture for the ps5000aGetValuesAsync() call).

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Different Downsampling Ratios

Postby martinR » Thu Aug 25, 2016 12:02 pm

Hello,

we will send an email with code and answers to your questions.

Thank you for your help in advance.

Kind Regards

Martin
martinR
Newbie
 
Posts: 0
Joined: Thu Aug 18, 2016 8:32 am


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests