MATHEMATICA TUTORIAL

# Audio Processing

Mathematica provides support for the manipulation of audio data. Sounds can be synthesized, manipulated, and analyzed.

### Audio Playback

 ListPlay[{a1,a2,...}] play a sound with a sequence of amplitude levels Play[f,{t,tmin,tmax}] play a sound with amplitude f as a function of time t in seconds Sound[prims] play a set of sound primitives prims EmitSound[snd] emit the sound snd when evaluated

Playing functions, lists, and primitives.

Sound can be created in several ways. One way is to simply write a series of amplitude values using ListPlay.

Play noise generated from random values.
 Out[19]=

Sounds can also be created using a function over time.

Generate a sine wave at 440 Hz.
 Out[20]=

ListPlay and Play are sound primitives that can be passed to Sound.

Play noise and then a sine tone successively.
 Out[21]=
Play noise and the sine tone overlapped.
 Out[23]=

EmitSound can be used to play the sound without a playback object.

### Sound Primitives

 SampledSoundList[{a1,a2,...},r] underlying representation of ListPlay SampledSoundFunction[f,n,r] underlying representation of Play

Lower-level representations of sound.

Create a SampleSoundList from a numeric list, with a sample rate of 8000.
 Out[24]=
Extract the SampleSoundList from a ListPlay object.
 Out[29]//Short=
Extract the SampleSoundFunction from a Play object.
 Out[27]=
These can also be used as primitives.
 Out[30]=

### Import/Export

 Import["file"] import a sound Export["file.ext",expr] export a sound

Importing and exporting functions.

It is possible to import audio data from a file on the local file system or from any accessible remote location.

This imports a sound from the Mathematica documentation directory.
 Out[56]=

Use Export to write a sound to disk.

This example takes the first second of the sound above and writes it to disk.
 Out[57]=

## Synthesis

Synthesizing audio data is relatively simple in Mathematica. In the example below, a Manipulate is created that controls the amplitudes of the first five harmonics of a 440 Hz fundamental. Basically, any Mathematica function can be used to create audio data.

 Out[37]= Play Animation ▪

### Amplitude Modulation

An example of amplitude modulation (AM), where carrier amplitude is controlled by another oscillator.
 Out[103]= Play Animation ▪

### Frequency Modulation

An example of frequency modulation (FM), where carrier frequency is controlled by another oscillator.
 Out[106]= Play Animation ▪

### Granular Synthesis

Granular synthesis is a basic technique that takes small samples from a sound file, called grains, and layers and rearranges them in different ways.

An example of granular synthesis, where multiple grain streams are created from the original sample.
 Out[27]=

## Audio Manipulation

### Delay Effects

Create an echo effect.
 Out[31]=
Create a chorus effect.
 Out[93]=

### Filtering

SampledSoundList, which contains audio data, can be used as input to many functions in the Mathematica signal processing suite.

 LowpassFilter[data,c] apply a lowpass filter with a cutoff frequency to an array of data HighpassFilter[data,c] apply a highpass filter with a cutoff frequency to an array of data BandstopFilter[data,{1,2}] apply a bandstop filter with cutoff frequencies and to an array of data BandpassFilter[data,{1,2}] apply a bandpass filter with cutoff frequencies and to an array of data

Some filters can be directly applied to audio signals.

Lowpass filtering of a noisy sound, using a cutoff frequency of 3000 Hz.
 Out[9]=
Highpass filtering of a noisy sound.
 Out[17]=
Bandstop and bandpass filtering of a sound.
 Out[16]=
 Out[17]=
 Out[18]=

### Equalization

Create an equalizer, using a set of bandpass filters.
 Out[29]=

## Fourier Analysis

Spectrograms and Periodograms

 Spectrogram[list] plot the spectrogram of list SpectrogramArray[list] return the spectrogram data of list Periodogram[list] plot the squared magnitude of the discrete Fourier transform (power spectrum) of list PeriodogramArray[list] return the squared magnitude of the discrete Fourier transform (power spectrum) of list

Spectral visualization and analysis.

A spectrogram of a sound and the corresponding data.
 Out[20]=
A periodogram of a sound and the corresponding data.
 Out[22]=

### Spectral Noise Gate

A spectral noise gate.
 Out[17]=
 Out[24]=

## Related TutorialsRelated Tutorials

New to Mathematica? Find your learning path »
Have a question? Ask support »