clear all

Fs = 48000;
dT = 1/Fs;
overlapPercent = 50;

segLength = 2^16;
overLapPercent = 0;
fileSize = 48000 * 60 * 2;

hSpectrum = spectrum.welch('Blackman-Harris', segLength, overlapPercent);

for i=1:3
    if i==1
        fileName = 'DeploymentNov24-09\BTNoiseData\gndedBBBT\R00000\D000000';
    elseif i==2
        fileName = 'DeploymentNov24-09\BTNoiseData\gndedBB\R00000\D000000';
    elseif i==3
        fileName = 'PerformanceTests\InputsGndedBattPwr';
    end
    
    fid = fopen(fileName);
    fprintf(1, 'Reading %s \n', fileName);
    ADCData(i,:) = fread(fid, 'int16=>int16');
    fclose(fid);

    Vref = 1.5;
    LSB = Vref / (2^15 - 1);
    data(i,:) = double(LSB * double(ADCData(i,:)));

    rms(i) = sqrt(mean(single(data(i,:)).^2));
    
    pxx(i,:) = psd(hSpectrum, single(data(i,:)), 'Fs', Fs);
    figure;
    psd(hSpectrum, single(data(i,:)), 'Fs', Fs)
    titleText = strcat('Welch PSD file: ',fileName);
    title(titleText);
    Pxx(i,:) = 10 * log10(pxx(i,:).Data);
end


