Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Upsampling data (equivalent to matlab interp)

We have a requirement to sample a signal at 2 different frequencies (1Mhz for the start and then 125Khz for the remainder) and to be able to process this data, however to process the data the sampling frequency has to be the same so we have used the matlab function interp to achieve this in the past.. This was  ok, but not ideal when there is more than one person trying to do it, so we are now looking to implement similar functionality in c# using measurement studio 8, I notice that there are Labview vi's that do this, are there any measurement studio or LabWindows equivalents ?

Thanks

Paul

0 Kudos
Message 1 of 8
(9,602 Views)
Hi,
  I'm not entirely sure whether you're talking about re-sampling the acquired data, or how to acquire the data in the first place.
Measurement Studio .net can easily acquire the data, and personally I'd acquire it at full rate, and then average the data to get to the 125kHz sample rate (especially since that's a divide by 😎 which is just indexing an array. That way you get to deal with actual data rather than interpolated. You can always do a curve fit on the second part of the data if you wanted to smooth it out.
How and from where (software and hardware) are you sampling the data currently?
 
Thanks
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 2 of 8
(9,595 Views)
I'm talking about resampling data that has already been acquired.

The reason is that there is quite a comms penalty in downloading the data at 1Mhz and there is no real need to do it apart from at the start of the signal. If time weren't an option then 1Mhz wouldn't really be a problem, other than a storage overhead The data is comming from a custom piece of hardware over a 2.5Mbps connection (24 channels of upto 65536 points eiach x typically 14 tests, which could be reduced to say 24x15000 if upsampling were available).

Thanks

Paul
0 Kudos
Message 3 of 8
(9,592 Views)
Hi,
  ok - that makes sense.
Inside of Measurement Studio 8.0.1 (so that covers Visual Studio .Net 2003 and 2005), there's several curve fitting functions.
I've attached an example which uses a PolynomialInterpolation function.
Essentially it calculates a point based on X and Y data and then maintains that in an array.
Here's the code snippet and the function description.
 
using NationalInstruments.Analysis.Math;

(removed the autogenerated code)

private void Gen_Data_Sine(double [] newData, int length)
{
 
  int
i;
  for (i=0;i<length;i++)
    newData[i] = Math.Sin(i);
}

private void Gen_Data(double [] newData, int length, double dividor)
{
 
  int
i;
  double temp;
  for (i=0;i<length;i++)  
  {
    temp =
checked((double) i);
    newData[i] = temp / dividor;  
  }
}

private void btnPlot_Click(object sender, System.EventArgs e)
{
 
  double
[] yData = new double[10];
  Gen_Data_Sine(yData,10);
  waveformGraph1.PlotY (yData);
}

private void btnInterp_Click(object sender, System.EventArgs e)
{
  double[] xData = new double[10];
  double[] yData = new double[10];
  double[] interpData = new double[100];
  double errEstimate;
  double temp;
  int i;
  Gen_Data_Sine(yData,10);
  Gen_Data(xData,10,1);
  for (i=0;i<100;i++)
  {
    temp =
checked((double) i) / 10.0;
    interpData[i] = CurveFit.PolynomialInterpolation(xData,yData,temp,
out errEstimate);
  }
  waveformGraph2.PlotY (interpData);
}

 
 
Hope that helps
 
Thanks
 
Sacha Emery National Instruments (UK)
 
 
 

Message Edited by SachaE on 07-26-2006 01:40 PM

Message Edited by SachaE on 07-26-2006 01:44 PM

Message Edited by SachaE on 07-26-2006 01:46 PM

// it takes almost no time to rate an answer Smiley Wink
Download All
0 Kudos
Message 4 of 8
(9,585 Views)

And here's the information on the PolynomialInterpolation

public static

System.Double PolynomialInterpolation ( double[] inputXData , double[] inputYData , System.Double xValue , System.Double errorEstimate )

Member of

NationalInstruments.Analysis.Math.CurveFit
Summary:
Performs polynomial interpolation.

Parameters:

inputXData: The known x-values for the planar function.
inputYData: The known y-values for the planar function.
xValue: The x-value at which the tabulated function is to be interpolated.
errorEstimate: Upon return, contains an estimate of the error in interpolation.

Returns:

An estimate of the y-value corresponding to the given the xValue parameter for the tabulated function.

Thanks

Sacha Emery
National Instruments (UK)

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 5 of 8
(9,574 Views)
Thanks, however I was looking for something more like the vi described here http://zone.ni.com/devzone/conceptd.nsf/webmain/0AA71742871067A686256D55004B7A23#5
i.e using FIR Filters to perform the upsampling.

Paul

0 Kudos
Message 6 of 8
(9,574 Views)

Hi,

 the align and resample express vi is actually a wrapper over a large amount of functionality.

Depending on the exact configuration set (you say you'd prefer the FIR implementation) I've drilled down into the VI and assuming that you don't actually need the alignment section, just the resampling on a finite data set (so not continuous data supplied in parts), the vi looks something like this :

As you can see, the maths involved imply that the filter co-efficients have to be calculated and then the above vi is called, and eventually it looks as if it performs a linear interpolation on a point by point basis, however before the waveform data reaches this point, it's been heavily modified in terms of re-timing and generating the filter co-efficients themselves, so it's not a trivial "one vi" approach, hence there's no simple direct function in measurement studio to do this.

Your best approach would be to get a copy of LabVIEW (either full with application builder, or professional versions) and build a .DLL from the functionality that you need. You could then call this from your c# code as you require.

Does that help at all?

Thanks

Sacha Emery National Instruments (UK)

Message Edited by SachaE on 07-27-2006 03:04 PM

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 7 of 8
(9,559 Views)
Hi,
  I should have said, that whilst there is no individual function to do this, the component parts are available inside of Measurement Studio 8.0.1 with the design based around the Kaiser FIR filter, with a "Kaiser-Bessel window function with a sinc function to provide the scaled filter", most of which is available in the NationalInstruments.Analysis.Dsp.Filters namespace and the rest (such as the Kaiser-Bessel window) is a mathematical routine which you should be able to find functionality for on the website.
If you don't have a copy of LabVIEW to investigate with, you can download a free 30 day trial to see the full functionality listed out from here :
 
If you were considering going down this route, and making a DLL to call from Visual Studio c#, then I'd recommend talking to your internal sales engineer (call the UK office on 01635 572410) and ask about the dev suites, which would give you LabVIEW plus Measurement Studio for a lot less than buying them separately.
 
Hope that helps

Thanks
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 8 of 8
(9,551 Views)