EmmaL
EmmaL

Reputation: 95

How to convert a wave file into numbers in R Studio

I have loaded audio files into R and would now like to get a list of the complex number samples so I can use FFT and Wavelet transforms on the samples.

How do I get the list of numbers to work with whilst in R? I've tried 'audio$data', but get an error message as $ is not defined in the s4 class.

Any help would be highly appreciated, thanks.

Upvotes: 9

Views: 4408

Answers (1)

MvG
MvG

Reputation: 60868

After reading the file with readWave from the tuneR package, you can use audio@left and audio@right to access the raw data. The latter is only available if your data is stereo. str(audio) will give you details about the structure of an object, and is immensely useful to find out what data it contains and how to access that data.

For obvious reasons, the data in a wave file will be real (and in fact even integers), so if you need complex numbers you might have to convert them. But I would guess that such a conversion will be performed automatically if you pass a vector of integers. The normal fft function (from package stats) can handle the integer vector without a problem.

Upvotes: 8

Related Questions