algorithm - Determine offset where the most constructive interference occurs -


i have 2 arrays of data:

i align these similar graphs (by adding offset either array):

essentially want constructive interference, shown when 2 waves produce same wave larger amplitude:

this same finding destructive interference, 1 of arrays must inverted shown:

notice second wave inverted (peaks become troughs / vice-versa).

the actual data not consist of 1 major , 1 minor peak , trough, of many, , there might not noticeable spikes. have made data in diagram simpler show how data aligned.

i thinking few loops, such as:

biggest = 0 loop -10 10 offset     count = 0     loop through array1 ar1         loop through array2 ar2             count += array1[ar1] + array2[ar2 - offset]     replace biggest count if count/sizeof(array1) > biggest 

however, requires looping through offset , looping through both arrays. real array definitions extremely large , would take long.

how go determining offset required match data1 data2?

jsfiddle (note language agnostic , understand algorithm more-so actual code)

look @ convolution , cross-correlation computation using fast fourier transformation. it's way how done in real life applications.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -