Signal generator hints
From CCRMA Wiki
Revision as of 09:49, 23 September 2010 by Njb (Created page with 'These are listed in some what easiest-to-hardest. As we did the sine wave in class, it's first! ==sine wave== * Use the <math.h> library sine function to compute the sine wave.…')
These are listed in some what easiest-to-hardest. As we did the sine wave in class, it's first!
- 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.
- Use a Gaussian distributed random number generator to create white noise.
- 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.
- 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
- The saw wave output should visually look the the teeth of a saw. The width (w) is a number between 0.0 and 1.0 the determines the period as well as the shape of the wave (e.g., width=.5 should result in a triangle wave, width=0 has shoots straight up to 1, and then has a negative slope downward, etc). First use the center frequency to determine how many sample you need to create the correct time period (T) in samples. Then use the width control to divide up the period into two section lengths (left and right) proportional to the width value. From there, "draw" a line with the correct slopes within each section.