Simulating Poisson process in Matlab

Below is a simple Matlab code to simulate a Poisson process. The interarrival times were computed and recorded in int_times. The times are then grouped into bins of 10 seconds in width and the counts are stored in count.

lambda=1/60; % arrival rate per second (1 minute per packet)
T=10*3600; % simulation time in second (10 hours)
delta=0.1; % simulation step size in second
N=T/delta; % number of simulation steps
event=zeros(N,1); % array recording at each step if a "packet" arrived. 
 % initialize it to zeros
R=rand(size(event)); % generate a random array (with elements in [0,1]) of the same size as "event"
event(R<lambda*delta)=1; % set each element of event to 1 with probability lambda*delta
inds=find(event==1); % getting indices of arrivial
int_times=diff(inds)*delta; % interarrival times in seconds
edges=0:10:400; % define histogram bin
count=histc(int_times,edges);

The histogram of the absolute counts of the interarrivial is then plotted with the commands below.

figure; bar(edges,count,'histc'); % draw histogram of absolute count

fig2

Finally, the counts are normalized and compared with the theoretical result (\lambda \exp(-\lambda T)).

figure; bar(edges,count/sum(count)/(edges(2)-edges(1)),'histc'); % draw histogram of normalized counts
hold;plot(edges,lambda*exp(-lambda*edges),'r'); % plot theoretical result
legend('simulation','theoretical');

fig3

16 Replies to “Simulating Poisson process in Matlab”

  1. I know this if off topic but I’m looking into starting my own weblog and was wondering what all is needed to get
    setup? I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet savvy so I’m not 100%
    sure. Any recommendations or advice would be
    greatly appreciated. Thank you

  2. I must thank you for the efforts you’ve put in penning this site.
    I’m hoping to see the same high-grade content by you in the future
    as well. In truth, your creative writing abilities has inspired me to get my very own website now
    😉

  3. After looking at a handful of the articles on your site,
    I seriously appreciate your technique of writing a blog.
    I saved it to my bookmark webpage list and will be checking back soon. Please visit my web site too and tell me what you think.

  4. Write more, thats all I have to say. Literally, it seems as though you relied on the video
    to make your point. You obviously know what youre talking about, why waste your intelligence
    on just posting videos to your blog when you could be giving us something informative to read?

  5. Very nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed surfing around your
    blog posts. After all I will be subscribing to your feed and
    I hope you write again soon!

  6. When someone writes an piece of writing he/she keeps
    the thought of a user in his/her brain that how a user can understand it.
    So that’s why this article is perfect. Thanks!

  7. Hi there I am so happy I found your web site, I really found you by mistake,
    while I was browsing on Aol for something else, Nonetheless I am here now and would just like to say thank you for a incredible post and a all round entertaining
    blog (I also love the theme/design), I don’t have time to read
    through it all at the moment but I have saved it and also
    included your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the
    fantastic work.

  8. I’m no longer certain where you’re getting your info,
    however good topic. I must spend a while learning more or
    understanding more. Thanks for magnificent info I used to be in search of this info for my mission.

  9. Oh my goodness! Impressive article dude! Many thanks,
    However I am encountering problems with your RSS. I don’t understand why I can’t join it.
    Is there anybody getting the same RSS problems? Anyone that knows the solution will you kindly respond?
    Thanks!!

  10. Today, I went to the beach with my children. I found a
    sea shell and gave it to my 4 year old daughter
    and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is totally off topic
    but I had to tell someone!

Leave a Reply

Your email address will not be published. Required fields are marked *