Week 2: Beat Phase Exercise
Chris Tralie
Background
We saw at the end of module 2 that if we add two sinusoids together that are very near in frequency, then we get a so-called "beat frequency" resulting from patterns of constructive and destructive interference. In particular, if we have the function
\[ y(t) = \cos(2 \pi f_1 t) + \cos(2 \pi f_2 t) \]
and we assume, without loss of generality, that f2 > f1
, then the beat will reach its peak at a frequency of f2 - f1
. The code below shows an example in jupyter with a beat of 0.2 hz, or 0.2 cycles per second (1 cycle every 5 seconds)
Exercise 1: Beat Phase
Notice how since we're using cosines with zero phase, the beat is at its peak at t = 0
, and then it goes down after that. What if we wanted a peak to happen at a particular time? How would we change the function? In other words, what sinusoids will we use? Recall that a sinusoid is more general than a zero-phase cosine, and is defined as
\[ y(t) = A \cos (2 \pi f t + \phi) \]
To accomplish this task, it may help to review function transformations below. See if you can get a peak in the above example to occur at time 2Exercise 2: Make It A Method
Now that you know the pattern, you should create a method that takes as input a times array, two frequencies, and a peak time, and which returns audio with the beat occurring at a particular time. Use this to make an audible beat sampled at 44100hz that you can listen to.
Exercise 3: Attack Velocity
If we're thinking of using this to make some kind of digital synthesizer, one of the drawbacks is that the beat onset is very gradual. Think about what you might do to make a note pop out with a higher "velocity," so that there is a sharper "attack" to the note. Hint: You may need to use more than one frequency. If you have time, implement this in code.