Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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!

share|improve this question
add comment

3 Answers

up vote 9 down vote accepted

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

share|improve this answer
    
Thanks, this is a nice and clear implementation. –  Leo Sep 22 '13 at 15:05
add comment

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

share|improve this answer
    
Thanks. I like the way you show two equivalent techniques. –  Leo Sep 22 '13 at 15:09
add comment

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

share|improve this answer
    
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 '13 at 15:08
    
@Leo that's fine! I will elaborate the meaning when I am free. You can check my update later. –  PlatoManiac Sep 22 '13 at 15:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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