Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 347
EmmaL Avatar asked Dec 11 '12 20:12

EmmaL


1 Answers

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.

like image 136
MvG Avatar answered Sep 19 '22 04:09

MvG