How to read a binary file and then classify it?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a text file in " dat " format that is the output of an audio device and needs to be read in binary and then classified on it to be able to meaningfully calculate and obtain their SNR. Can someone guide me how to categorize them? (I have attached a sample file)
3 commentaires
Walter Roberson
le 8 Oct 2023
That file 1.dat is not a text file. It is a binary file in an unknown format.
There is no standard ".dat" file format: ".dat" is an extension used by many different software packages for very different purposes.
There is a possibility that the .dat file is a hyperspectral data file produced by ENVI, but such a file would be accompanied by a .hdr file... and it seems unlikely given that we are told that this is from an audio device and ENVI is seldom used for audio.
I made some tests trying to figure out if the data was binary integers. If you examine the data as a series of bytes (uint8) then most of the bytes are either 0 or 255, and there is a relatively even distribution of the other values bytes (except that 1 was about 4 times as common as the others). Looking at the statistical distribution of the values using other potential representation (such as single precision) I could not justify any other potential representation (though I cannot rule out that it might be some ultrasound as 16 bit unsigned integers)
So we have to ask what the data format is; and we have to ask "classify as what" ?
Réponses (1)
Walter Roberson
le 29 Oct 2023
Modifié(e) : Walter Roberson
le 29 Oct 2023
This assumes that the data really is int32, which I am not convinced of.
FileName = '1.dat';
file_id=fopen(FileName,'r');
data = fread(file_id, 10000, 'int32');
sinw = [];
cosw = [];
sinw = double(data(1:2:end));
cosw = double(data(2:2:end));
Corr=cosw.^2+sinw.^2;
Corrmax = max(Corr);
dc1 = find(Corr == Corrmax);
% "find station of corrmax in corr"
meancorr=mean(Corr);
Corr=Corr./meancorr;
nn=Corr(dc1);
Corrr=mean(nn);
%remember the mean could be negative in theory, so what used to be max
%might be min now
peaksd1=max(Corr);
SNR=10*log10(peaksd1);
1 commentaire
Walter Roberson
le 29 Oct 2023
To classify them:
[cluster, means] = kmeans(Corr, 2);
scatter(cluster, Corr)
but you will not find the result to be enlightening.
Voir également
Catégories
En savoir plus sur Using audio files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!