Hi!
I have some files here, which have a special file format, but are actually just headerless wav files with a sample rate of 16000.
I wanted to do some fft plotting of the wav file like so
plot(abs(fft(audioread(wav_file))));
However, I get the The file type is not supported message.
Is there a way to open those files or do I have to save them was wav files first?
EDIT:
To clearify, the files mentioned are indeed raw binaries. As I haven't recorded those datas myself, I can only guess about the internal structure. I can analyze the file just fine with these import settings in Wavesurfer:
Sample rate: 16kHz
Encoding: Lin16
Channels: Mono
Byte Order: Little Endian
Read Offset: 0
Frequency: It will probably be something between 0-8kHz, since I was suppose to sample with 16kHz (right?)

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Okt. 2013
Bearbeitet: Walter Roberson am 2 Okt. 2013

0 Stimmen

You use fopen() to open them, and fread() to read them, and you apply your knowledge of the internal structure of .wav files to decode what you read in.
But you will likely find it to be much less coding to write out a temporary copy of the file with the missing header pre-pended and use audioread() on the result.
Your you sure they are in .wav format, and not raw binary data ?

12 Kommentare

Martin
Martin am 2 Okt. 2013
I'm sorry, yes, they are actually just raw binary files. Would there be another way of opening and using them then?
fid = fopen('TheFile.dat', 'r');
rawdata = fread(fid);
fclose(fid);
rawdata = rawdata(:);
sound(rawdata, 16000)
Martin
Martin am 2 Okt. 2013
Hmm. Something doesn't seem right. I just hear really bad noise. Tried to play around with the sample rate parameter, but it didn't help either. Tried to set the bits per sample, but still no clear sound. Unfortunately I can't attach a sample file, because I don't have the right to do so. I guess I do have to convert it to a wav file first.
Image Analyst
Image Analyst am 2 Okt. 2013
You forgot to attach your file. Use the paper clip icon.
zip your file and attach the zip.
Try
fid = fopen('TheFile.dat', 'r', 'l'); %'l' is LittleEndian
rawdata = fread(fid, inf, '*uint16');
Sorry, by right I didn't mean like reputation-wise right. I don't own the sound file, and there is no clear license on it, therefore I can't upload it for legal reasons.
I tried with the your added suggestions, but get the following error:
Audio data must be real and floating point.
Jan
Jan am 4 Okt. 2013
@Martin: It is unlikely, that anybody can guess the format of your data file, when you cannot explain this detail or provide the file.
Martin
Martin am 4 Okt. 2013
@Jan Simon: I know, but I guess it can't be helped then. If I should figure it out somehow, I'll come back and write an answer here. Until then I just have to convert my file into a wav-file.
Use audioplayer instead of sound()
Or...
rawfloat = double(rawdata) ./ 8192 - 1.0;
sound(rawfloat)
The file I was using, as it turned out, is a CMU adc-file[0].
It can be read roughly the following way:
ch = 1
channels=ones(1,ch);
fid=fopen(filename,'r','n');
[adc, count] = fread(fid,[ch,inf], '*int16');
fclose(fid);
for i=ch:-1:1
if channels(i) == 0
ADC(i,:)=[];
end
end
soundsc(double(ADC), 16000)
Thanks for all the help!
Jan
Jan am 7 Okt. 2013
Bearbeitet: Jan am 7 Okt. 2013
The FOR loop is meaningless here, because no element of channels can equal zero and ADC is not defined. But if this is possible, this is nicer:
ADC = ADC(channels~=0, :)
Martin
Martin am 7 Okt. 2013
Yeah, sorry. It was a function file with way more error checking. I just shortened it a bit, but was obviously not very thorough. Thanks for the tip!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Jan
Jan am 2 Okt. 2013

0 Stimmen

As far as I know, there are no "headerless WAV files". The header is mandatory for the WAV format.
Most likely you have simple binary files with raw data. But now you have to know the number of channels, the format of the single values (single, double, int16?), the frequency and for multiple channels, if the signal is stored in time or channel order. If you provide the required information, we can suggest a method to import the file.

1 Kommentar

Martin
Martin am 2 Okt. 2013
I just edit some more information in the original question. I'm very new in the speech analysis department, thus, are not quite sure which information is required, and if the provided ones are correct or not.

Melden Sie sich an, um zu kommentieren.

Prernna Bhatnagar
Prernna Bhatnagar am 23 Feb. 2017

0 Stimmen

Can anyone tell me how to open .adc files in matlan and then plot them? These filescontain EMG Signals.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by