excel - VBA: Amplitude of superimposed sine waves -


i have written excel macro allows user create graph , add noise data in form of superimposed sine waves. in order give user more control have made number of sine waves used , maximum amplitude of sine waves inputs.

the frequency , phase of each sine wave random variable between 2 preset values , amplitude random variable greater 0 , less or equal user input value amplitude. maximum possible amplitude not increase addition of more sine waves amplitude individual wave divided number of waves being used. each of these variables generated separately each of superimposed waves , position of each point calculated iteratively.

the issue having when more sine waves used probability of resultant curve being @ maximum @ given point lot less , whole curve has lower amplitude , closer mean. means user has iteratively vary amplitude until required not ideal.

here relevant code:

j = worksheets("sheet1").range("ae19").value c = worksheets("sheet1").range("aa19").value w = 1 = 4 4003         worksheets("sheet2").range("i" & i).value = 0 next while w <= c     = ((int((5 - 1 + 1) * rnd + 1)) / (10 / j) / c)     f = int((8 - 1 + 1) * rnd + 1)     p = (int((6 - 1 + 1) * rnd + 1)) / 6     = 4 4003         x = worksheets("sheet2").range("h" & i).value         b = worksheets("sheet2").range("i" & i).value         worksheets("sheet2").range("i" & i).value = b + (a * sin((x / (10 * f)) + (2 * application.worksheetfunction.pi() * p)))     next     w = w + 1 loop 

where c number of sine waves used , j maximum amplitude given user.

also when allow each value of amplitude user defined value (rather dividing c) use of more waves increases amplitude.

if able suggest how can adjust code not happen , expected amplitude of resultant code remains same regardless of number of waves used (however still want amplitude of waves individually vary).

i’m still quite new vba if spot glaring flaws in code please point out.


Comments