# Create sine function with random increase in phase

I am trying to simulate a signal that randomly increases its phase, so far I have tried two thing but neither worked. I usually use matlab but I want to learn some Mathematica so I thought I would try this in Mathematica.

My first try was

times = Table[i, {i, 0, 2, 0.05}];
function[source_, t_][fiIN_] :=
With[{fi = fiIN + 0.01*RandomReal[]},source*(1 + Sin[2 Pi*t + fi])];


Where I wanted to feed fi back into fiIN for each subsequent t value (in the list times). I did not know how to makes this work though so I went on with my second try:

fiupdate[fi_] := fiupdate[fi - 1] + 0.01*RandomReal[];
fiupdate = 0;
fitimes = Range[Length[times]];


However this function does not remember the value of RandomReal[] for the earlier steps, so fiupdate could be smaller than  or . Also when using this function I get an error:

fis = fiupdate[fitimes];
\$RecursionLimit::reclim: Recursion depth of 1024 exceeded


Im not sure how to make this work. Any help is appreciated. Thank you!

Your problem can be reduced to creating an increasing function, phase, and then use Sin[t + phase[t]].

Here is one way to do this by interpolating a sorted list of random numbers:

tmax = 40;
phase = Interpolation[Sort[RandomReal[10, tmax]]];
Plot[phase[t], {t, 1, tmax}]
Plot[{Sin[t], Sin[t + phase[t]]}, {t, 1, tmax}] • Thanks, this is a nice and clear implementation.
– Leo
Sep 22, 2013 at 15:05

You can use Sin[t + phase[t]] where phase[t] is Interpolation of a random process.

This random process can be implemented by Accumulate

tmin = 0;
tmax = 10;
dt = 0.1;

phase = Interpolation[
Transpose@{ Range[tmin, tmax, dt],
Accumulate@RandomReal[1.0, Floor[(tmax - tmin)/dt + 1]]},
InterpolationOrder -> 1];

Plot[phase[t], {t, tmin, tmax}] or by PoissonProcess

phase = Interpolation[
RandomFunction[
PoissonProcess[1/dt], {0, Floor[(tmax - tmin)/dt + 1]}]["Path"],
InterpolationOrder -> 1];

Plot[phase[t], {t, tmin, tmax}] • Thanks. I like the way you show two equivalent techniques.
– Leo
Sep 22, 2013 at 15:09

One way will be to use Nest or something like that...

tmax = 20;
times = Table[i, {i, 0, tmax, 0.05}];
fi = With[{dist = .8}, (*here you can control how big jump is possible between phases*)
NestList[RandomReal[{#, # + dist}] &,RandomReal[],-1 + Length@times]];
phaseIncrese =Transpose@{times, (1 + Sin[2 Pi*#1 + #2]) & @@@ (Transpose[{times,fi}])};
With[{(f = Interpolation@phaseIncrese)},
Plot[{1 + Sin[2 Pi*t], f[t]}, {t, 1, 4}, Frame -> True]
] • Thanks, this is a very nice answer! A bit too advanced for me though. Most of your code I dont understand yet (a lot of the # and @ operators). Thats why I opted to accept ssch`s answer. But if a more advanced user is looking for the same thing I was they will probably benefit from your answer.
– Leo
Sep 22, 2013 at 15:08
• @Leo that's fine! I will elaborate the meaning when I am free. You can check my update later. Sep 22, 2013 at 15:39