# How can I hear what a mathematical function sounds like?

I'm working on differential equations homework right now, and I just came across a solution to a problem that has the form: I graphed the function with my computer and it has an interesting waveform that I want to hear. Is there a way I can do this?

• – Dom
Mar 31 '16 at 1:55
• You could try doubling the frequency once or twice or three times, then do a Fourier analysis of it to get its spectra, and then re-create it with an additive synth. I feel like somewhere out there, there must be a synth that will accept an equation for a waveform, but I don't know for certain. I wonder if you would get a good answer at the software recommendations stack exchange. Mar 31 '16 at 2:25
• You don't need to do a Fourier analysis - it's a linear combination of cosines. The Fourier coefficients are `16/15` and `-1/15`, right there in the equation, and all of the other coefficients are zero. You could re-create this in any addative synth, e.g. ZynAddSubFX, or operator in Ableton. It will sound like a sine wave with a quiet second-octave harmonic. Mar 31 '16 at 5:56
• You can feed any vector of values to various DAC-like tools which will convert the data into audio output. People have done this with the digits of pi, among other wacky things. Mar 31 '16 at 12:23
• @naught101 thank you for your excellent insight! Would you be so kind as to elaborate on how you know the 2nd octave harmonic is softer? Is it the -1/15 term ? or does it have to do with the .5t and 2t
– sova
Apr 1 '16 at 2:31

As naught101 says, your particular case here is a sinusoidal wave with a quiet third harmonic. To hear what this sounds like at an audible frequency, go to http://meettechniek.info/additional/additive-synthesis.html in a browser that supports the Web Audio API (like Firefox or Chrome), turn the audio on, and set it like this: H1 there represents your `(16/15)cos(½ t)`, although as the default frequency of this online synthesizer is 440, we've effectively scaled it to cos(440 × 2π × t), and (16/15) has just been normalised to '1.000'. H3 represents the `-(1/15)cos(2t)` bit, again scaled up in frequency - ideally the volume would be 0.0625, which is 1/16 of the volume of the fundamental (H1), but 0.065 is close enough.

You may not find it sounds that interesting after all! In fact all waveforms that are strictly periodic with no variation tend to sound quite boring (to me at least) - they'll all just be a static hum or buzz. It's usually the variation in the shape of the waveform over time that makes it sound interesting.

Because of the nature of that particular equation it's easy to reproduce its output in an additive synthesizer. In the more general case, one way to hear an equation is to sample its output - generate the 'y' for certain values of 't' (at a certain sample rate such as 44.1 kHz, which would generate 44100 samples per second) - and play back the list of y values as PCM digital audio data.

As an example, one audio editor I use to do this is the (quite old) Adobe Audition 1.5, that can load in a text file, interpret each line as a sample value, and play the resulting waveform back like a WAV or any other audio file. To do this, it wants the y values scaled to fit within the range of 8-bit or 16-bit data (e.g. within −32,768 to 32,767 for 16-bit) and rounded to the nearest integer, so the text file would look like (e.g.)

``````3917
4587
5387
4645
3024
1911
791
-632
-1901
-2554
-2124
-1234
``````

You could ask on https://softwarerecs.stackexchange.com/ to see if there's any newer / free audio editor that can import textual sample data like this.

If you can do any coding at all, it should be fairly easy to find a library that can write audio files (e.g. the Python language has the 'wave' module) once you have generated a list of sample values, so you can easily write an audio file in a common format from your program.

This kind of sampling is likely to be what Dom's excellent wolframalpha suggestion will be doing internally, though I couldn't get it to work in my browser! To get your equation into the audible range, you could scale it - e.g. using (16/15)cos(250 * 2π * t)-(1/15)cos(1000 × 2π × t) will give you a wave with a fundamental frequency of 250Hz (assuming t is in seconds). One thing to watch for when sampling is aliasing - to avoid this, you need to sample at a rate of at least double the value of any frequency component of the waveform generated by the function.

You don't need any specific audio software to generate audible waveforms. Here's a simple C program that will generate the required data on standard output:

``````#include <stdint.h>
#include <stdio.h>
#include <math.h>

double y(double t) {
return (16 * cos(t/2) - cos(t*2)) / 15;
}

double pitch = 440 * 2*3.14159;  // so the base pitch will be a standard A note

int main() {
int16_t v;
char* p = (char*) (&v);  // "buffer" for standard output
double t=0;

while (t+=1./44100) {
v = (int16_t) ( y(t*pitch) * (2<<12) );
putchar(p);putchar(p);  // disclaimer: this is NOT good programming
putchar(p);putchar(p);  // style, just a quick hack to output data
}
return 0;
}
``````

Save a `signal.c`, and execute

``````gcc signal.c -lm && ./a.out | aplay -f cd
``````

This should work right out of the box, in a normal Linux install (e.g. Ubuntu).

• maybe `double pitch = 440; double angularVelocity = pitch * 2* 3.14159`? Apr 1 '16 at 7:16
• Well yeah... but the physics units are a bit messed up anyway here; it doesn't really make sense to consider cos(2 ⋅ t) if t is a time. Apr 1 '16 at 9:37
• `You don't need any specific audio software`, when you write your own software... Nov 9 '18 at 7:09

Equations could be fed into e.g. SuperCollider. Another option is to "fencepost" the equation and convert the value of the equation at those points into a pitch (and possibly also a duration, perhaps based on the slope at that point, or whatever), though this will require some amount of fussing to appropriately scale the fenceposts (what the x values are) and output (y values) to fit into a suitable ambitus:

``````% perl -e 'for \$x (0..10) { printf "%d\n", 60 + 10 *( 16/15*cos(.5*\$x) - 1/15*cos(2*%x) ) }'
70
68
65
60
54
50
48
49
52
57
62
% perl -e 'for \$x (0..100) { printf "%d\n", 60 + 10 *( 16/15*cos(.5*\$x) - 1/15*cos(2*%x) ) }' | atonal-util pitch2ly --mode=absolute | ly-fu --instrument=orchestral\ harp --open --absolute -
`````` The question assumes that the waveform at stake is directly human hearable. If that would be the case, an alternative approach to the programmatic one would be to use an additive synthesizer to synthesize the waveform. For those into the computer music/DAW realm, there are a number of free VST synthesizers that perform additive synthesis, and I remember at least one (would have to look for it in my backup archives) that directly genererates a waveform from a mathematical function expression.

However, the presented function is NOT human hearable. It's a combination of 2 sine waves of frequency:

• f1 = 0.5 /(2*Pi) = ~0.32 Hz
• f2 = 2 / (2*Pi) = ~3,14 Hz

Human hearing starts at around 20Hz, so the presented function is not direcly hearable. In order to have a sonic rendering of the function, we will have to apply some sort of a "sonification" process, i.e., apply some sort of transformation to the function that puts it into the range of human hearable audio. In this case a simple frequency multiplication, say, by a 100, would do the trick, and allow the application of the methods indicated in previous answers. But there a lot very diverse and interesting techniques that can be used to "sonify" any set of sample data.

A wealth of information can be found by searching for "sonification" but for those interested who don't already have a starting point, I suggest trying the free online Earsketch environment from Georgia Tech university. It's a complete interactive music programming environmnt based on the Python syntax, so if you're already familiar with Python that helps a lot, but Python is an easy to learn language anyway. It's totally online, you don't have to install anysoftware.

A specific chapter of the Earsketch online tutorial talks about sonification.

Here's a data sonification shared Earsketch example project (in this case, weather data). It's quite easy just to replace your own data.

• The OP didn't include any physical units. It could as well be f₁ = (0.5 min⁻¹) / 2π ≈ 0.0013 Hz, which is even further into the subsonic. Or, more sensibly, it could be understood as referring to an arbitrary time scale, i.e. the base frequency is ad libitum. Apr 8 '16 at 12:06

For this we needed 4 years, WE DID IT. we create sample with 440 frq.
f(x) = 16/15 cos(1/2x) - 1/15 cos(2x) Enjoy listening https://drive.google.com/file/d/1BPtJyHHpR3jCnHHlDAtylO6IpPDHsPb7/view?usp=sharing 