LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to resample unequally spaced data in Array form?

I have an array of unequally spaced time data and corresponding signal data taken at these times.
I would like to resample the signal data to be equally spaced in time (constant dt).
How do I introduce the time data into the signal, then resample?
 
I have tried the "Align and Resample" express vi using constant dt resample and reference signal resample, both with my time signal as the reference and with a constantly spaced array as the reference (none worked).
 
I have tried to create a waveform using the data, but it seems waveform type assumes constant dt.  There is a waveform to XY Pairs vi, but not one for going the other way.
I have tried to build a 2D array and convert to DDT, but it seems DDT assumes 2D array as multiple channels.
 
How can I resample unequally spaced data?  I'm sure there is a simple answer that I am missing.
I am attaching a simple vi to illustrate my point.
 
Thank you.
__________________________________
Laine
0 Kudos
Message 1 of 9
(8,036 Views)


@Laine wrote:
How can I resample unequally spaced data? I'm sure there is a simple answer that I am missing.
I am attaching a simple vi to illustrate my point.
Thank you.


You can do a simple resampling by interpolation. I wrote a VI some years ago which should do the job. It's not using any fancy waveform or DDT data type, just arrays. In the VI you can select between linear and Spline interpolation. I attach it in a LV 8 version.

-Franz
Message 2 of 9
(8,029 Views)

Thank you Franz.  Yes, I would rather work in simple array type.

Excuse me for not including my LabVIEW version.  I am only runnin LV7.1, so cannot open your LV8 file. 

Do you mind resubmitting in 7.1 format?  Thank you.

I searched for this file in example code and discussion sections, but did not see it.

 

Thanks.

__________________________________
Laine
0 Kudos
Message 3 of 9
(8,020 Views)


@Laine wrote:

Thank you Franz.  Yes, I would rather work in simple array type.

Excuse me for not including my LabVIEW version.  I am only runnin LV7.1, so cannot open your LV8 file. 

Do you mind resubmitting in 7.1 format?  Thank you.

I searched for this file in example code and discussion sections, but did not see it.

 

Thanks.



OK, here is a 7.0 version.

(You couldn't find this VI, because I never published it...)


-Franz
Message 4 of 9
(8,005 Views)
Excellent.  This is a nice simple algorithm.
 
Thank you.
__________________________________
Laine
0 Kudos
Message 5 of 9
(7,991 Views)

Dear Franz,

 

I know it's been more than 4 years, but I have just come accross your solution to this problem and I hope you're still following this thread. So I just tried this vi and it works perfectly, although I have a slight problem with it. I have a spiral drawing that I'd like to interpolate/resample to a higher point-count or resolution (lets say its 200 points originally and I'd like to make the very same figure but in 600 points resolution); your VI does only part of the job for me and I've just realized why: since my X coordinates are not only increasing but changing order a couple of times, the VI only computes and resamples my spiral array until the maximum X value. To make it easier to understand I attached a picture too:

spiral_resample.PNG

 

I was wondering if it possible to carry out the same function (resampling) throughout the whole spiral array. If not I wonder if anyone has a good idea how to tackle this problem.

 

Thanks,

Attila

0 Kudos
Message 6 of 9
(7,365 Views)

Hi,

 

so I've found this other solution which works better than the one I previously posted, although there is a problem with this as well (a lot less significant but still troubling):

spiral_resample2_block.PNG

As you can see on the diagram, there is the template spiral figure array(of certain length that is smaller than the so called 'final draw') so what I'm trying to do is that by getting the ratio of the sizes of the two arrays I interpolate/resample the template array (to make it match the size of the other 'final' array). I carry out this operation twice, on both coordinates of the spiral (X,Y), obviously with the same numbers. The result is below:

 

spiral_resample2.PNG

 

Everything works fine , except that this method appends a few (2 or 3 pair) of coordinates at the end of the resampled array that have nothing to do with the original array. These numbers vary, depending on the interpolation method I use, apparently spline is the best, since it only adds 0s after the final right value. The only problem with this is that the size is right so I can't simply chop these last false elements off the end of the resampled array.

First I thought that the "not integer 'dt' input" (the ratio of the two array-sizes is definately not an integer number) on the Resample Waveform VI causes the problem, but then if that was the case, the resulting interpolated array would have size-issues I guess.

 

Any idea or suggestion is welcome!

 

Thank you!

---

Attila

0 Kudos
Message 7 of 9
(7,349 Views)

Hello Attika,

 

With the Resample Waveforms (single shot).vi you have the option to 'open interval? (F)'  This option chooses the interval of the input to sample.  If you set this value to true, the trailing zeros will be removed.  If the value is set to false, these trailing zeros appear.

 

The Align and Resample Express VI has the same options and you can play around with these settings to determine which work for your application.  You can read more about them here: http://digital.ni.com/public.nsf/allkb/3DADE9F3962FF89E86256D25005EBD48?OpenDocument.

 

Best of luck!

National Instruments
Senior Systems Engineer
0 Kudos
Message 8 of 9
(7,298 Views)

Hi Sarci1,

 

 

thank you for the reply! I have already tried the Align and Resample Express VI, tweaked it and everything but it doesnt seem to carry out the functionality I really need. 

 

Wiring a true value to the Resample Waveforms (single shot).vi input seems to help getting rid of the trailing zeros at the end of the array, although it did make the final resampled array smaller in size too, so now I have the same problem again (I wanted the resampled array to be of fixed length, but now its smaller by a couple of elements). However, this method might work, if I simply chop off those zeros, plus I reduce the size of the other array with which I want to compare the interpoalted one (even if this means losing a tiny bit of information this might be the only working option I seem to have right now, to properly interpolate an array to a cahnging size). Unfortunately I still have some other issues with my task; to summarize my problem I describe it in a different way now:

 

the orginal task is to compare to 'graphical signals', two spirals; one is a template, a perfect spiral genereted previously by a different program, the other is a hand-drwan figure (these are different in size: the template is a fixed-size array, but the hand-drawn array is completely random sized). To make matter worse, the problem is that this hand-drawn array of X,Y points is that they are not sampled equally in time. I have a timestamp for each, but they are not equally spaced. My goal is to somehow make it possible to compare these two signals first coordinate-wise, then in a polar system and eventuially in the frequency domain.

My approach right now is to somehow interpolate the timestamp vector first, and then resample/interpolate the X and Y vectors of the hand-drawn figure to the same size as the previously interpolated time vector. this way I could get an equally spaced time/X/Y set of vectors of a certain length. Then I should interpolate the template signal to the size of the previously interpolated set of vectors of the hand-drawn figure so I could compare the two signal at the same positions in time and frequency.

 

Unfortuanetly I've still haven't solved the first part, where I want to create the equally spaced time/X/Y vectors, so if anyone has any suggestions please share it here!

 

Thank you again for your continuous help!

 

Attila

0 Kudos
Message 9 of 9
(7,258 Views)