clear all

directory = 'N:/DeploymentOct12-09/R2009-285-08-00-26/R00000';
startDate = '12-Oct-2009 01:20:00';
dnStartDate = datenum(startDate);

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

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

numSections = 16;
bufSize = 20 * 60 * 48000 / numSections;
ADCData = zeros(numSections, bufSize, 'int16');

for i=1:10
    dnFileDate = datenum(fileDates(i));
    if ((dnFileDate >= dnStartDate) && strncmp(fileNames(i), 'D', 1))
        tic
        fid = fopen(strcat(directory,'\',char(fileNames(i))));
        fprintf('Processing file: %s   %s\n',strcat(directory,'\',char(fileNames(i))),char(fileDates(i)));
        for j=1:numSections
            fprintf('Section %d ... ',j);
            ADCData(j,:) = fread(fid, 'int16');
            fprintf('Calculating Section PSD \n',j);
            Pxx(i,:) = pwelch(ADCData(j,:), window, Noverlap, Nfft);
        end
        fclose(fid);
        toc
    end
end

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




        
        
        
        


