# Fourier Analysis of a .aiff file

I'm trying to use Mathematica to perform Fourier Analyses on sound files, but I'm not sure how to get the Frequency Spectrum from the .aif file.

The instructions I have say:

1. use Mathematica’s Play command to take data samples of the tone at 11,025 samples per second.

2. use Mathematica’s Export command to convert the data into a .aif file.

3. use GarageBand to alter the sound wave data with one of 15 effects.

4. use Mathematica’s Import, Fullform, and Table commands to convert the new .aif file into 11,025 data samples.

5. use Mathematica’s Fourier and ListLinePlot commands to generate and plot the frequency spectrum of the altered sound wave data.

Therefore, I first produced a pure tone of 1 second by writing Play[Sin[2 Pi 440 t], {t, 0, 1}], naming it 'test' and exporting it with Export["test.aiff", test]

Where I get stuck is converting the .aif file back to the data points by using Fullform and Table commands, and converting the Fourier Transform into a Frequency Spectrum using the ListLinePlot.

If anyone could help it would be greatly appreciated, thank you in advance

If you're just trying to get the data itself, you can try:

test = Play[Sin[2 Pi 440 t], {t, 0, 1}]
Export["test.aiff", test]
audio = Import["test.aiff"]
data = AudioData[audio][]


This will also work for a single step:

data = Import["test.aiff", "Data"]

• Thanks for the response, it worked to get the data points. However, I'm still having trouble with the ListLinePlot command. I wanted a graph that looked something like imgur.com/a/5O6wPHq but using the Fourier and ListLinePlot functions ins't working. test = Play[Sin[2 Pi 440 t], {t, 0, 1}] Export["test.aiff", test] audio = Import["test.aiff"] data = AudioData[audio][] table = Fourier[data] ListLinePlot[table] However, my ListLinePlot does not look correct? Do you have any suggestions for that? Attached is an image of my code and plot imgur.com/a/IZzg5hb – fugitivedrake11 Aug 3 '19 at 5:00
• The problem is that taking the Fourier transform of the data results in complex numbers, and ListLinePlot cannot plot complex numbers. The usual method would be to plot the power of the Fourier spectrum as table = Fourier[Abs[data]^2]; ListLinePlot[table]. If you're interested in the phase, you can do table = Fourier[Arg[data]]. The caption of the image you linked to doesn't actually make it clear which one they're plotting, but it definitely looks like the power to me. – MassDefect Aug 3 '19 at 7:18
• If you actually do want a plot of the complex numbers, check out ReImPlot and AbsArgPlot. Also, keep in mind that since Fourier is looking for a 1D list of data, the x-axis of your Fourier transforms represents "the Fourier component plus 1" and not the actual frequency. That is, the data point at 1 on the x-axis represents the DC component, and the data point at 2 on the x-axis represents a wave that has a period equal to the length of the data. And Mathematica does Fourier a bit differently from some other programs. Some other programs will put the DC component in the middle of the... – MassDefect Aug 3 '19 at 7:22
• ...graph, but MMA puts it at the very beginning. – MassDefect Aug 3 '19 at 7:22