% constants gas_watts_per_pulse = 649.8; elec_watts_per_pulse = 58.35; log_interval = 60*2880/2801; % seconds between log records windowSize = 2; % setup %logs = csvread('20191015-0740_DATALOG.csv'); logs = csvread('20191018-0750_DATALOG.csv'); tend = datetime(2019,10,18,07,50,0); %% read file and create timebase Nlogs = length(logs); Ndays = (Nlogs*log_interval)/(24*60*60); % log length (in days) tsecs = (0:(Nlogs-1))*log_interval; % sample times since start (in secs) tstart = tend - Ndays; tDays = tstart + tsecs/(24*60*60); % absolute sample times startDay = dateshift(tstart, 'start','day'); elec = logs(:,4)*elec_watts_per_pulse; gas = logs(:,3)*gas_watts_per_pulse; temp = logs(:,2); temp(temp > 35)=NaN; % filter outliers temp(temp < 0)=NaN; %% do plotting b = (1/windowSize)*ones(1,windowSize); a = 1; % moving-average filter figure(1); for ddex = 0:(ceil(Ndays)-1) ss = dateshift(tDays, 'start','day') - startDay == ddex; % logical array tagStr = datestr(tDays(find(ss,1)), 'ddd dd'); subplot(3,1,1); hold on plot(timeofday(tDays(ss)), filter(b,a,elec(ss)), 'b', 'Tag', tagStr); plot(timeofday(tDays(ss)), filter(b,a,gas(ss)), 'g', 'Tag', tagStr); subplot(3,1,2); hold on plot(timeofday(tDays(ss)), filter(b,a,temp(ss)), 'r', 'Tag', tagStr); subplot(3,1,3); hold on plot(timeofday(tDays(ss)), 1e-3*cumsum(elec(ss)*log_interval/3600), 'b', 'Tag', tagStr); plot(timeofday(tDays(ss)), 1e-3*cumsum(gas(ss)*log_interval/3600), 'g', 'Tag', tagStr); end %% add labels, units, etc. subplot(3,1,1); ylabel('Power (W)'); ylim([0 6000]); xlim(duration([0,24],0,0)); set(gca, 'XTick', duration(0:6:24,0,0)) grid on legend('Elec', 'Gas', 'Location', 'northwest'); set(datacursormode(gcf),'UpdateFcn',@datacursorUpdateFcn); subplot(3,1,2); ylabel('Temperature (°C)'); ylim([15 25]); xlim(duration([0,24],0,0)); set(gca, 'XTick', duration(0:6:24,0,0)) grid on set(datacursormode(gcf),'UpdateFcn',@datacursorUpdateFcn); subplot(3,1,3); ylabel('Energy Consumed (kWh)'); xlim(duration([0,24],0,0)); set(gca, 'XTick', duration(0:6:24,0,0)) grid on legend('Elec', 'Gas', 'Location', 'northwest'); set(datacursormode(gcf),'UpdateFcn',@datacursorUpdateFcn);