CCRMA

Random Processes and State Machines


Probability distributions

Probability is the likehood of occurrence of a given event, ratio of number of occurrences of that event to the total number of results of the random process. A probability distribution is a table that shows the likehood of occurrence of one of more events, where the probability of occurrence of a given event is expressed as a value between 0 and 1.

[continuous vs discrete distributions]

Random numbers... as normally generated in a computer are not really really random. They are the result of executing an algorithm, the output values can be considered statistically random if the algorithm is good enough. Normally the random number generator is seeded by a number, after that the numbers generated are predictable (each time we seed the generator with the same number it produces the same sequence of "random" numbers).

In common lisp we can generate random floating point values using the (random xxx) function, where xxx is a floating point number. If we need integers (for example to generate midi note numbers) then the argument to random should be an integer.

[Distributions: uniform, linear, triangular, exponential...]

The example file probability.lisp has some examples of probability distributions (Note: you'll have to first compile and load plot.lisp to be able to plot the distributions)

State Machines

[a definition]

A state machine remembers a "state" (a memory of where it is in its internal process) and depending on whar state it is in, it calculates outputs that are determined by the current inputs and then transitions to a different (or the same) state. We could specify a state machine by a connected graph. States are represented by circles. Directed arrows specify the transitions between states. Each transition is determined by the "current state" (that is, the circle it originates in) and by the input conditions. As a side effect of the state transition the state machine defines new output values.

[Mealy: transition -> output; Moore: state -> output]

[Markov chains: probability for transitions between states]

A very simple state machine could be defined by the following lisp code:

(defparameter h-state t)

(defun harmonize (input)
  (if h-state
      ;; up by a fifth
      (progn
	(setf h-state nil)
	(+ input 7))
    ;; up by a fourth
    (progn
      (setf h-state t)
      (+ input 5))))

h-state is a global variable that remembers the current state of the state machine. It can have two values, t or nil (ie: this state machine has only two state). The function definition is simple, depending on h-state is executes two branches of code, each one calculates and returns an output value based on the input to the state machine and the current state. It then transitions to the other state.

(with-sound()
  (loop
    repeat 10
    for time from 0 by 0.2
    for note = 60 then (harmonize note)
    do
    (fm-violin time 0.16 (pitch (if (> note 128) 128 note)) 0.1)))

See statemachine.lisp for ready to run examples...

Each state within the state machine has to define what to do with the outputs and how to transition to the next state. So far we have only seen a completely deterministic behavior in our state machine.

What if some of the decisions were taken by stochastic (random) processes? The output of our state machine is no longer completely predictable. Those stochastic decisions could influence the transition between states of the generation of outputs from the current inputs to the state machine.

  • State Machines
    • Deterministic
    • Stochastic

Assignment #4) [due on February 7th, 2002]

Go to the main course page and read again the blurb on the project that's required for the course. The project proposal is long overdue and as of last class we had only gotten one. So I have decided to include it as part of the assignments for the course. Please email project proposals to Michael Gurevich (gurevich@ccrma).

This assignment is PASS/FAIL, if you have an approved project proposal byt the assignment due date of February 7th, 2002, you pass, otherwise you fail. Should be clear enough.


©2000-2002 Fernando Lopez-Lezcano. All Rights Reserved.
nando@ccrma.stanford.edu