clear

directory = 'E:\McStar\Data';
startDate = '21-Aug-2008 19:02:00';
dnStartDate = datenum(startDate);

Fs = 540000;
Nfft = 1024;
window = hanning(Nfft);
Noverlap = 0.5 * Nfft;

D = dir(directory);
fileNames = {D(3:length(D)).name};
fileDates = {D(3:length(D)).date};

recordNum = 1;
for i=1:length(fileNames)
    dnFileDate = datenum(fileDates(i));
    if dnFileDate >= dnStartDate
        fid = fopen(strcat(directory,'\',char(fileNames(i))));
        fprintf('Processing file: %s   %s\n',strcat(directory,'\',char(fileNames(i))),char(fileDates(i)));
        rawData = fread(fid, 'uint32');
        ind = find(rawData > hex2dec('7FFFFF'));
        rawData(ind) = rawData(ind) - hex2dec('1000000');
        lsb = 2^23 - 1;
        rawData = 2.5 * rawData / lsb;
        record(recordNum,:) = rawData;
        Pxx(recordNum,:) = pwelch(record(recordNum,:), window, Noverlap, Nfft);
        recordNum = recordNum + 1;
        fclose(fid);
    end
end


        
        
        
        


