Determine the offset where the most constructive interference occurs

I have two data arrays:

I would like to align these similar graphs together (by adding an offset to any array):

In essence, I want the most constructive interference, as shown, when two waves together create the same wave, but with a larger amplitude:

It is also the same as searching for the most destructive interference, but one of the arrays must be inverted, as shown:

Note that the second wave is inverted (peaks become deflections / vice versa).

The actual data will consist not only of one main and one secondary peak and trough, but also many, and there can be no noticeable surges. I made the data in the diagram easier to show how I would like the data to be aligned.

, :

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

, . , .

, 1 2?

JSFiddle ( , , , )

+4
2

( ) , , : : Fiddle

importand - function matchData()

N max min spikes, .

-1

Source: https://habr.com/ru/post/1536412/


All Articles