clear

directory = 'N:\Data';
startDate = '5-Dec-2008 15:20:00';
dnStartDate = datenum(startDate);

Fs = 27e6 / 512;
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) && strncmp(fileNames(i), '108', 3))
        tic
        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');
        data(recordNum,:) = rawData;
        ind = find(data(recordNum,:) > hex2dec('7FFFFF'));
        data(recordNum,ind) = data(recordNum,ind) - hex2dec('1000000');
        lsb = 2^23 - 1;
        data(recordNum,:) = 2.5 * data(recordNum,:) / lsb;
        Pxx(i,:) = pwelch(data(recordNum,:), window, Noverlap, Nfft);
        recordNum = recordNum + 1;
        fclose(fid);
        toc
    end
end

time=0:1/Fs:(length(data(1,:))-1)/Fs;




        
        
        
        


