merge_waves function

Merge waves