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

Click For Summary

Discussion Overview

The discussion revolves around the challenge of multiplying two data sets that differ in length and spacing, specifically in the context of data analysis and plotting. Participants explore methods for normalizing or interpolating the data to facilitate this multiplication, focusing on the overlapping region of the data sets.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes the issue of having two data sets with different lengths and non-uniform spacing, seeking a method to make them compatible for multiplication.
  • Another participant suggests focusing on the overlapping region by discarding data points outside this range and mentions the need for interpolation if the specific energies differ between the data sets.
  • A third participant inquires about the smoothness of the data to determine if cubic spline interpolation in MATLAB could be applied effectively.
  • Another participant points out that similar interpolation can be achieved using Python's SciPy library, providing an alternative for those without access to MATLAB.
  • A later reply confirms successful use of the 'interpolate' function from SciPy in Python, indicating it resolved the participant's issue.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of focusing on the overlapping region and the potential need for interpolation, but there are multiple approaches suggested, including different tools and methods for interpolation. The discussion remains open regarding the best method to apply based on specific data characteristics.

Contextual Notes

Participants mention non-uniform spacing and the need for interpolation without specifying the exact nature of the data sets, which may affect the choice of interpolation method. The discussion does not resolve which interpolation technique is superior or under what conditions each method should be applied.

ademus4
Messages
2
Reaction score
0
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).
 
Technology news on Phys.org
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.
 
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.
 
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.
 
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):

no_labels.png
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
4K
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K