Signal generator hints

From CCRMA Wiki
Revision as of 21:13, 27 September 2017 by Ge (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

sine wave

  • Use the <math.h> library sine function to compute the sine wave. You'll have to make sure to normalize the input to the sine wave by the sampling rate.
  • For class one simple way to do it was: sin( 2 * pi * fc * t / fs ) where fc is the center frequency, t is a time increment increasing by 1 each sample, and fs is the sample rate.


  • For simplicity, you can use a uniform distributed random number generator. If you want, try to find a Gaussian distributed random number generator!

impulse train

  • Use the center frequency to the fundamental period (T) in samples. The signal should be all zeros, except have a value of 1.0 at the period T.

pulse wave

  • Compute the period (T) as above. Now divide up the period into two sections proportional to the width control (e.g., width=.5 should result in a square wave). You should probably disallow width of exactly 1.0 or 0.0 as this could create a constant amplitude signal (DC)..and you won't hear anything.
  • This will be very similar to the saw