| Computer Code for Generating an Array of a Sine Wave
Here's some simple computer code (in the 'C' language) for generating an array with a 512 entry sine wave in it:
#define TABLE_SIZE 512
#define TWO_ (3.14159 * 2)
float samples [TABLE_SIZE];
float phaseIncrement = TWO_ /TABLE_SIZE;
float currentPhase = 0.0;
int i;
for ( i = 0; i < TABLE_SIZE; i ++){
samples[i] = sin(currentPhase);
currentPhase += phaseIncrement;
}
What can you say about the frequency of the sinewave computed above? (Hint, you need to know the sampling rate, or how many samples we're computing per second: typically, that might be 44.1 kHz) How about the amplitude? How would you take the code above and change the amplitude? Change the frequency? Maybe distort the sinewave?
How much do you remember from geometry class? Do you remember that you took a geometry class (if not, we can't be of much help). Or better yet, how much do you remember from Chapter 3, where we talked about phasors?
What's TWO- doing in there? Try to figure out what's going on in this code! What would happen, for example if you changed sin(i) to sin(i)/2, or 2*sin(i)? If you know a programming language, try writing a program that does a graphical printout of the wave. |