0
$\begingroup$

How to plot a random impulse train with random height and space? From the following code, I was able to get a random height graph and a random interval space graph.

randHeights = Mod[{RandomVariate[NormalDistribution[5, 2], 20]}, 1];
randSpace = RandomVariate[NormalDistribution[5, 2]];
f[t_] := 1;

GraphicsRow[{
  ListPlot[randHeights, Filling -> Axis, PlotStyle -> Red, 
   PlotRange -> All, AspectRatio -> .5],
  
  ListPlot[Table[{t, f[t]}, {t, 0, 50, randSpace}], Filling -> Axis, 
   AspectRatio -> .5]
  }]

You may get a different result from the one I have here, and I'm still unsure how to combine these two concepts.

I'm looking for a single graph that has different intervals & heights (with a maximum of 1) on every run. Any idea, anyone? Thanks for the help!
$\endgroup$
3
  • $\begingroup$ randSpace = Table[RandomVariate[NormalDistribution[5, 2]], 1000]; and Sort[randSpace][[1 ;; 10]] can easily generate negative numbers. Usually random delay is specified around a base delay and is a fraction of a base delay. $\endgroup$
    – Syed
    Dec 6, 2021 at 16:54
  • $\begingroup$ @Syed I tried to use this code, but it's not generating any graph. Is it because of the Sort command? $\endgroup$
    – nightcape
    Dec 7, 2021 at 12:29
  • $\begingroup$ This was to show that delays could be negative too (not just zero) if a UniformDistribution were chosen. $\endgroup$
    – Syed
    Dec 7, 2021 at 14:03

1 Answer 1

2
$\begingroup$

Something like this?

n = 20;
t1 = RandomReal[{0, 1}, n];
t2 = RandomReal[{0, 1}, n];
t1 = Accumulate[t1];
dat = Transpose[{t1, t2}];
ListPlot[dat, Filling -> Axis]

enter image description here

$\endgroup$
4
  • $\begingroup$ Almost, but I don't want to make it overlap or have a close interval from one to another, that is why I use NormalDistribution $\endgroup$
    – nightcape
    Dec 6, 2021 at 11:12
  • 2
    $\begingroup$ I think you can adapt this yourself $\endgroup$ Dec 6, 2021 at 11:33
  • $\begingroup$ Got it, I use RandomVariate[NormalDistribution[10, 2], n] for one of the t. Thanks! $\endgroup$
    – nightcape
    Dec 7, 2021 at 2:37
  • 1
    $\begingroup$ 👍 Glad to hear this. You learn more if you do it yourself. $\endgroup$ Dec 7, 2021 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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