Register to reply 
Multiplying two data sets which don't have the same length or spacing 
Share this thread: 
#1
Jul2312, 06:38 AM

P: 2

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 xaxis (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 nonuniform 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
Jul2312, 11:51 AM

P: 687

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 nonuniform, 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. 


#3
Jul2312, 12:34 PM

Sci Advisor
P: 2,751

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. 


#4
Jul2312, 04:43 PM

P: 879

Multiplying two data sets which don't have the same length or spacing
yeah, what uart said.
if you don't have matlab, you can do the same thing with python with scipy.interpolate, see this online example, for instance. 


#5
Jul2512, 05:27 AM

P: 2

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): 


Register to reply 
Related Discussions  
D spacing from Xray diffraction data  Atomic, Solid State, Comp. Physics  3  
DFT of large data sets  Math & Science Software  0  
Method for multiplying members of three sets to yield specific values  General Math  0  
Relationship interatomic spacing or interplanar spacing and grain size  Atomic, Solid State, Comp. Physics  5  
Linearly Spacing Data in C  Programming & Computer Science  3 