Signal processing is a new domain for me, and I don’t quite know where to start looking for the solution to my problem.
I have a line graph that was converted to an audio file consisting of nothing but pure tones. I’m trying to convert it back to a line graph using Processing, although I think language is irrelevant. I’m vaguely aware that I may be needing to use a Fourier transform, but it’s not something I’m familiar with.
I’ve looked at all of the examples provided with Processing using Minim and its spectrum analysis functionality, and I’m still lost as to how I should proceed, or what I should even look for.
I imagine modems and fax machines convert serialized data to audio form and back in much the same way, though I’m not sure how they manage to convert the data back from tonal form.
The basic way to do this is for each pixel in the area you are drawing to, you determine which data sample or samples to represent by drawing a pixel at a calculated height.
The gory details:
Disregarding the complexity of compressed audio,an audio file is a set of samples. The samples are recorded at a fixed rate. For audio, common sample rates are 44100, 48000, or 96000 samples per second. The audio file will usually specify this rate. To draw this data, you then map the audio samples to pixels.
For an easy example, say you have 1 second of ECG data recorded at 48000 samples per second. That’s 48000 samples in the file. Let the samples be floating point values that range from 0 to 1, though often they are integer samples. And assume you are drawing to a 10 pixel high by 100 pixel wide rectangle.
Given all that, it means that each pixel will represent 480 samples of your data. You can average those 480 samples to get the value that you should draw in the first pixel. To figure out where to fill in the pixel you map the sample’s range, 0 to 1, to the drawing rectangle, height 0 to 10. A 0 sample will draw at the bottom of your rectangle, a 1 sample will draw at the top, and a 0.5 sample will draw in the middle. Say that first 480 samples averages to 0.1. Then you’d draw a dot at 1 pixel up from the bottom at the left-most pixel in the drawing area, (0,1) relative to the bottom of the drawing rectangle.
Repeat this until you’ve determined where to draw the pixel for each pixel in your display area.
If you have fewer samples than you have pixels to display into, you’ll interpolate values for each pixel. Given the same drawing area, 10 x 100, but only 10 data samples you’ll interpolate nine pixel positions for each data sample.