8
$\begingroup$

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[1] = 0;
fitimes = Range[Length[times]];

However this function does not remember the value of RandomReal[] for the earlier steps, so fiupdate[10] could be smaller than [9] or [8]. 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!

$\endgroup$
10
$\begingroup$

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}]

plots

$\endgroup$
  • $\begingroup$ Thanks, this is a nice and clear implementation. $\endgroup$ – Leo Sep 22 '13 at 15:05
8
$\begingroup$

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}]

enter image description here

or by PoissonProcess

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

Plot[phase[t], {t, tmin, tmax}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. I like the way you show two equivalent techniques. $\endgroup$ – Leo Sep 22 '13 at 15:09
7
$\begingroup$

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]
]

enter image description here

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Leo Sep 22 '13 at 15:08
  • $\begingroup$ @Leo that's fine! I will elaborate the meaning when I am free. You can check my update later. $\endgroup$ – PlatoManiac Sep 22 '13 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.