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?
5 Comments
Sorted by latest first Latest Oldest Best
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 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 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[0]);putchar(p[1]); // disclaimer: this is NOT good programming
putchar(p[0]);putchar(p[1]); // 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).
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.
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 "%dn", 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 "%dn", 60 + 10 *( 16/15*cos(.5*$x) - 1/15*cos(2*%x) ) }' | atonal-util pitch2ly --mode=absolute | ly-fu --instrument=orchestral harp --open --absolute -
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 drive.google.com/file/d/1BPtJyHHpR3jCnHHlDAtylO6IpPDHsPb7/view?usp=sharing
Terms of Use Privacy policy Contact About Cancellation policy © freshhoot.com2025 All Rights reserved.