Archiv für den Monat: Februar 2015

Creating a beat frequency interference with R

A beat frequency is a mix of two frequencies which are very close to each other but not similar. The trick is that they are to close to each other to be separated by the human ear as two distinct frequencies, thus generating  a single tone with fluctuating amplitude behavior – a periodic change in volume. In Fact this effect just appears within the human brain, therefore the two tones can be measured physically by using the appropriate instruments. Further more the effect also works in a binaural situation where one ear can only hear one frequency respectively.

The following graphic shows two almost similar sinus waves, one at 440 Hz and one slightly below, at 435 Hz. The sound data is produced for exactly 2 seconds of time at a 44100 Hz sample rate, giving us 88200 sample points for 2 seconds. The first three demonstrations of the graph show only the beginning of the wave whereas the last one presents the combination of both signals for the complete 2 seconds.


Basically a combination of two sinus waves can be mathematically represented by:

f3And if we assume that both amplitudes are the same we get the reduced form by:


It is interesting to understand that the resulting frequency of the beat, i.e. the recognized periodic fluctuation of volume, is given by:



440Hz – Sinus – 2 seconds

435Hz – Sinus – 2 seconds

435 & 440Hz – Sinus – resulting beat frequency – 2 seconds

The oscillations in this post are simple created in R by using standard mathematical functions in combination with the time series package in R. In addition the seewave package is used to store the sinus waves as a .wav file to the system.

The time series package handles data as equispaced points in time. This is in accordance with the sampling of continuous sound signals as the become digitized. A common used sampling frequency for CD quality is 44.1 kHz which results in 88.2k sample points for a length of 2 seconds.

For ease of use the summation of the amplitude 2a becomes reduced to a by division.

The graphical representation of the sound can easily be saved as a .jpg file to the system.

In addition to the sample above we can also see and hear what it is like when the beat effect fades out and the brain starts to recognize two different tones. Therefore the next few examples present the resulting wave after summing two different frequencies, where one is always 440 Hz.



435 & 440Hz – Sinus – resulting beat frequency – 2 seconds

425 & 440Hz – Sinus – resulting (beat) frequency – 2 seconds

415 & 440Hz – Sinus – resulting (beat) frequency – 2 seconds

405 & 440Hz – Sinus – resulting (beat) frequency – 2 seconds

395 & 440Hz – Sinus – resulting (beat) frequency – 2 seconds

485 & 440Hz – Sinus – resulting (beat) frequency – 2 seconds


Latex code for the Formulas above:

S&P 500 growth 1975 – 2014

Just a few graphs on the development of the S&P500 Index from 1975 – 2014, using data from yahoo finance.

The first graph shows the price movement of the index for the time period from 1975 to 2014 (available data at yahoo finance), with slower but rather constant growth in the first half of the time period and higher growth in the second. And of course the two major set backs from 2000-2003 and 2007-2009 are clearly visible.


The next graph presents the same time series separated into decades, merged together into one graph. It is easy to see that there is a constant positive development within the different decades (with respect to the choice of truncation). The question arising now is, in which period did the most change in index value occur. The answer to this question kind of turns the plot on its head. It can be found in the next graph.

SP500.jpg 1975-2005 4decades-new

Regarding the question from above the following plot shows the same development in percent values, for the individual decades, included into one graph. Now the separation between the periods becomes more clear, with the highest movement between 1985-1995 and the lowest between 2005 and 2014.

SP500.jpg 1975-2005 4decades percent-new

An other interesting effect appears  when we modify the truncation of the single decades. E.g. if we observe the time frames from 1980-1990, 1990-2000, 2000-2010, an so on. 3 decades of the index development are strongly positive whereas 1 decade shows a negative development (2000-2010), indicating the possible importance of timing models.

SP500.jpg 1975-2005 4otherdecades percent2-new