One question that keeps arising is how to acquire synchronised data across multiple distributed targets and different hardware. Whilst true hardware-based synchronisation may be the answer, quite often data needs resampling due to phase-offsets, clocks-drifting, lack of external sample clocking and so on.
One solution is to capture a sync pulse within the data set itself and to resample all of the data accordingly. Unaware of any existing code that can do this, I wrote a VI that can take a continuous data stream and feed out a continuous, but resampled, data stream.
The file “Resample with known pulse stream.vi” is fairly simple but should accommodate most use cases. Your acquired data is fed in as a 2D array. You must feed a TRUE into the reset on the first pass along with valid data in the Config cluster. This latter data is latched and used on subsequent calls.
Each time the vi is called, previous data is prepended and then the waveform on the “sync” channel is analysed. A simple peak detect is performed and the last peak is rejected due to possible conflict with the end of the data set. This data isn’t lost however as it’s then added back onto the data for the next pass. The first pass of the vi is also used to establish threshold levels if not manually defined. If the pulses are long, flat-topped square-waves then the peak detection function will not work correctly. In that instance, there is the option to perform a simple filter and differentiation (hence the subVI “Filter and diff.vi”). This allows us to capture the front edge of the pulse rather than the peak. It will introduce an offset but we don’t care because if all synchronised sources are using the same process, that offset will be constant.
So, once we have the array of detected pulses, we can use those locations to perform a linear resampling of the data on all the channels in order to generate the expected number of samples per sync pulse. If we do this for every sync pulse, we may propagate jitter from the pulse timing into the final data. This is why there is a decimation value so that the data is fitted over a number of sync pulses and not every single one.
Probably the best way to try this out is to have a play with the test vi “resample waveform based on known pulse stream cont.vi”
LabVIEW 2016 (not base)
I've now added a zip file containing the same code saved for LV2014. It should work however I can't test it.
Copy the attached VIs files a folder and load the example code “resample waveform based on known pulse stream cont.vi”
This VI calls the resampling code and allows you to familiarise yourself with how it processes the incoming stream.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.