Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Multiplying two data sets which don't have the same length or spacing

  1. Jul 23, 2012 #1
    As the post title describes, I have two data sets and want to multiply them together (and finally plot them). The problem I have is that the data are different length, so for example using Matlab:

    >>> data_set1 .* data_set2

    But this would not give me the correct answer for a number of reasons.

    The data share the same x-axis (energy in MeV). The trouble is the first data starts around 0 MeV and ends around 11. The second data starts just before the end of the first data and extends further on. The region in which they overlap is the part I am interested. Another issue I have is the length between data points is non-uniform in both data sets.

    Is there a process to normalise or do something with the data to make them 'compatible'?

    For tools, I am using anything I can get my hands on. Excel for basic ideas, Python (Numpy and MatplotLib) for proper data analysis. I am fairly comfortable with Matlab but I don't have it where I work now (I can however download Octave).
  2. jcsd
  3. Jul 23, 2012 #2
    If you're only interested in the overlap region, start by throwing away everything else. Keep only the points in the first data set which are higher energy than the minimum energy of the second data set, and similarly keep only the points in the second data set which are less than the maximum energy of the first.

    You say that the length between the data points is non-uniform, but don't specify if the specific energies are the same in each data set, or different. If they're the same, then you're done once you take the overlap. If they're different, then you'll have to interpolate at least one of the data sets. You can interpolate one of the data sets onto the points where the other is evaluated, or interpolate them both onto some other set of points. If you need to work with them in future calculations, it might simplify things to interpolate them both onto a uniformly spaced set of points.
  4. Jul 23, 2012 #3


    User Avatar
    Science Advisor

    Hi ademus, is your data smooth enough to be reasonably interpolated?

    If so try the matlab cubic spline. It is easy to use: y_new = spline(x, y, xnew), where "x" and "y" are your original data and "xnew" is the set of x samples points that you would like to use and "ynew" is the corresponding interpolated y data.
  5. Jul 23, 2012 #4
    yeah, what uart said.

    if you don't have matlab, you can do the same thing with python with scipy.interpolate, see this on-line example, for instance.
  6. Jul 25, 2012 #5
    Thanks for the responses!

    In the end I used the 'interpolate' function from Scipy in Python, which worked perfectly!

    Here is of plot of the data (without labels etc, the blue and green data are multiplied to make the red data):

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook