close all
clear all

load('X:\707976 EPBuoyPrototypeAndTesting\Deployments\Sept2013\DecodedResults\R00006\D000464_131002_185001.mat')

RectifiedPower = RectifiedVoltage.*RectifiedCurrent;
MeanRectifiedPower = mean(RectifiedPower);
RMSRectifiedPower = rms(RectifiedPower);


figure('Position',[1000         255         982        1243],'PaperSize',[8.5 11],'PaperPosition',[.5 .5 7.5 10]);
ah1 = subplot(3,1,1)
plot(time-time(1),RectifiedPower)
xlabel('time (s)');
ylabel('Electrical Power (W)');
legend(['Mean = ' num2str(MeanRectifiedPower,3) 'W    RMS = ' num2str(RMSRectifiedPower,4) 'W   Peak = ' num2str(max(RectifiedPower),4) 'W'])
title('Power')

idx = 22701:22900;
ah2 = subplot(3,1,2)
plot(time(idx)-time(1),RectifiedPower(idx))
xlabel('time (s)');
ylabel('Electrical Power (W)');

ah3 = subplot(3,1,3)
[nelements,centers]= hist(RectifiedPower,[0:500:10000]);
bar(centers+250,100*nelements/sum(nelements),1)
xlabel('Power (W)');
ylabel('% of time');

print('-dpdf','PowerRangeExample');

RPM = RectifiedVoltage*5000/450;
MeanRPM = mean(RPM);
RMSRPM = rms(RPM);


figure('Position',[1000         255         982        1243],'PaperSize',[8.5 11],'PaperPosition',[.5 .5 7.5 10]);
ah1 = subplot(3,1,1)
plot(time-time(1),RPM)
xlabel('time (s)');
ylabel('Speed (RPM)');
legend(['Mean = ' num2str(MeanRPM,3) 'RPM    RMS = ' num2str(RMSRPM,4) 'RPM   Peak = ' num2str(max(RPM),4) 'RPM'])
title('RPM')

idx = 22701:22900;
ah2 = subplot(3,1,2)
plot(time(idx)-time(1),RPM(idx))
xlabel('time (s)');
ylabel('Speed (RPM)');

ah3 = subplot(3,1,3)
[nelements,centers]= hist(RPM,[0:500:6000]);
bar(centers+250,100*nelements/sum(nelements),1)
xlabel('Speed (RPM)');
ylabel('% of time');

print('-dpdf','SpeedRangeExample');
