MATLAB Examples

Contents

loadIndBatch.m

Loads data from an industrial batch XLS sheet

Usage:
X = loadIndBatch(filename)
X = loadIndBatch(filename, tInterp)
%
filename - path to the file
tInterp - not all data is sampled at every instance or sometimes a sensor
        is faulty and there is no measurement. This is a time vector to
        interpolate industrial data on
function [X] = loadIndBatch1(filename, tInterp)
% % reads the first sheet in the XLS data
[ndata, textdata, alldata] = xlsread(filename);

% find batch size
[n,m] = size(alldata);
i = 1;
flag = 0;
while (i<n && flag == 0)
    if(~ischar(alldata{i,1}))
        if(isnan(alldata{i,1}))
            flag = 1;
        end
    end
    i = i + 1;
end

if(flag == 1)
    N = i - 3;
else
    error('Cannot determine the size of the batch!');
end

% gets a time vector
t = cell2mat(alldata(2:N+1,1));
Error using loadIndBatch1 (line 16)
Not enough input arguments.

Temperature T [K]

y = convertTextCells(alldata(2:N+1,2));
if(nargin==1)
    X.T = createChannel('Temperature','K','h',t(~isnan(y)),y(~isnan(y)) + 273.15);
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.T = createChannel('Temperature','K','h',tInterp,y+273.15);
end

CO_2 out gas CO_{2_{out}} [%]

y = convertTextCells(alldata(2:N+1,3));
if(nargin==1)
    X.CO2 = createChannel('Carbon dioxide concentration','% of outlet gas','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.CO2 = createChannel('Carbon dioxide concentration','% of outlet gas','h',tInterp,y);
end

Water for injection F_w [L/h]

 y = convertTextCells(alldata(2:N+1,4));
if(nargin==1)
    X.Fw = createChannel('Water for injection','L h^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.Fw = createChannel('Water for injection','L h^{-1}','h',tInterp,y);
end

Sugar feed rate F_s [L/h]

y = convertTextCells(alldata(2:N+1,5));
if(nargin==1)
    X.Fs = createChannel('Sugar feed rate','L h^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.Fs = createChannel('Sugar feed rate','L h^{-1}','h',tInterp,y);
end

pH

y = convertTextCells(alldata(2:N+1,6));
if(nargin==1)
    X.pH = createChannel('pH','pH','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.pH = createChannel('pH','pH','h',tInterp,y);
end

Vessel back pressure P_1 [bar]

y = convertTextCells(alldata(2:N+1,7));
if(nargin==1)
    X.pressure = createChannel('Vessel back pressure','bar (gauge)','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.pressure = createChannel('Head pressure','bar (gauge)','h',tInterp,y);
end

Aeration rate F_g [m^3/min]

y = convertTextCells(alldata(2:N+1,8));
if(nargin==1)
    X.Fg = createChannel('Aeration rate','m^{3} min','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.Fg = createChannel('Aeration rate','m^{3} min','h',tInterp,y);
end

Phenylacetic acid flow F_PAA [L/h]

y = convertTextCells(alldata(2:N+1,9));
if(nargin==1)
    X.Fpaa = createChannel('Phenylacetic acid flow','L h^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.Fpaa = createChannel('Phenylacetic acid flow','L h^{-1}','h',tInterp,y);
end

Dissolved oxygen concentration DO_2 [mg/L]

y = convertTextCells(alldata(2:N+1,10));
if(nargin==1)
    X.DO2 = createChannel('Dissolved oxygen concentration','mg L^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
     y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.DO2 = createChannel('Dissolved oxygen concentration','mg L^{-1}','h',tInterp,y);
end

Carbon evolution rate CER [g/min]

y = convertTextCells(alldata(2:N+1,11));
if(nargin==1)
    X.CER = createChannel('Carbon evolution rate, CER','g h^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.CER = createChannel('Carbon evolution rate,CER','g h^{-1}','h',tInterp,y);
end

Oxygen uptake rate OUR [g/min]

y =  convertTextCells(alldata(2:N+1,12));
if(nargin==1)
    X.OUR = createChannel('Oxygen uptake rate,OUR','g h^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.OUR = createChannel('Oxygen uptake rate,OUR','g h^{-1}','h',tInterp,y);
end

Biomass softsensor - estimated using CER X_est [g/l]

y = convertTextCells(alldata(2:N+1,11));
% Smoothing CER function to remove noise and spikes
y_f = y;
% Uncomment if have Signal Processing Toolbox
%y_f_mf =   medfilt1(y_f,10); % filter noise
y_f_mf = y_f;
CER = y_f_mf ;
tspan = [1 t(end)];
y0 = 0;
% Calculaing biomass from  X_CER
[Xest_CER] = ode45(@X_est_CER,tspan,y0,[],CER);
y = Xest_CER.y;
t_x = Xest_CER.x;
if(nargin==1)
    X.X_CER = createChannel('Biomass conc estimated from CER','g L^{-1}','h',t_x(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t_x(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.X_CER = createChannel('Biomass conc estimated from CER','g L^{-1}','h',tInterp,y);
end

Soybean oil F_oil [L/h]

y = convertTextCells(alldata(2:N+1,13));
if(nargin==1)
    X.Foil = createChannel('Soybean oil','L h^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.Foil = createChannel('Soybean  oil','L h^{-1}','h',tInterp,y);
end

Weight W [kg]

y = convertTextCells(alldata(2:N+1,14));
if(nargin==1)
    X.Wt = createChannel(' Vessel weight','kg','h',t(~isnan(y)),y(~isnan(y))*1000);
else
    y = interp1(t(~isnan(y)),y(~isnan(y))*1000, tInterp,'linear','extrap');
    X.Wt = createChannel('Vessel weight','kg','h',tInterp,y);
end

Oxygen conc out-gas O_2_out [%]

y = convertTextCells(alldata(2:N+1,15));
if(nargin==1)
    X.O2 = createChannel('Oxygen concentration','% of outlet gas','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.O2 = createChannel('Oxygen concentration','% of outlet gas','h',tInterp,y);
end

Penicillin titre P [g/L]

Assumption 1 g - 1670 kUnits

y = convertTextCells(alldata(2:N+1,16));
if(nargin==1)
    X.P = createChannel('Penicillin concentration','g L^{-1}','h',t(~isnan(y)),y(~isnan(y))/1670);
else
    y = interp1(t(~isnan(y)),y(~isnan(y))/1670, tInterp,'linear','extrap');
    X.P = createChannel('Penicillin concentration','g L^{-1}','h',tInterp,y);
end
 X.P.y(X.P.y<0) = 0;% Correcting for negative extrapolated values

y = convertTextCells(alldata(2:N+1,16))/1670;
t_p = convertTextCells(alldata(2:N+1,1));
if(nargin==1)
    X.P_offline = createChannel('Penicillin concentration','g L^{-1}','h',t_p(~isnan(y)),y(~isnan(y)));
else
   % y = interp1(t(~isnan(y)),y(~isnan(y))/1670, tInterp,'linear','extrap');
    X.P_offline = createChannel('Penicillin concentration','g L^{-1}','h',t_p,y);
end

Residual Nitrogen concentration N [mg/L]

y = convertTextCells(alldata(2:N+1,17)); %
t_p = convertTextCells(alldata(2:N+1,1));
if(nargin==1)
    X.NH3_offline = createChannel('Off-line Residual N','mg L^{-1}','h',t_p(~isnan(y)),y(~isnan(y)));
else
     X.NH3_offline = createChannel('Off-line Residual N','mg L^{-1}','h',t_p,y);
end
y = convertTextCells(alldata(2:N+1,17)); %
if(nargin==1)
    X.NH3 = createChannel('Residual NH3','mg L^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.NH3 = createChannel('Residual NH3','mg L^{-1}','h',tInterp,y);
end

Phenylacetic acid concentration PAA [mg/L]

y = convertTextCells(alldata(2:N+1,18));
t_p = convertTextCells(alldata(2:N+1,1));
if(nargin==1)
    X.PAA_offline = createChannel('Phenylacetic acid concentration','mg L^{-1}','h',t_p(~isnan(y)),y(~isnan(y)));
else
     X.PAA_offline = createChannel('Phenylacetic acid concentration','mg L^{-1}','h',t_p,y);
end

y = convertTextCells(alldata(2:N+1,18));
if(nargin==1)
    X.PAA = createChannel('Phenylacetic acid concentration','mg L^{-1}','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.PAA = createChannel('Phenylacetic acid concentration','mg L^{-1}','h',tInterp,y);
end

Viscosity measurements \mu_{app} [cP]

y = convertTextCells(alldata(2:N+1,19));
y(1) = 4; % initialising viscosity calculation for interpolation
if(nargin==1)
    X.viscosity = createChannel('Viscosity','centiPoise','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.viscosity = createChannel('Viscosity','centiPoise','h',tInterp,y);
end

y = convertTextCells(alldata(2:N+1,19));
t_p = convertTextCells(alldata(2:N+1,1));
if(nargin==1)
    X.viscosity_offline = createChannel('Viscosity','centPoise','h',t_p(~isnan(y)),y(~isnan(y)));
else
    X.viscosity_offline = createChannel('Viscosity','centPoise','h',t_p,y);
end

Ammonia sulphate shot addition N_shots [kg]

y = convertTextCells(alldata(2:N+1,20));
y(1) = 0;
if(nargin==1)
    X.NH3_shots = createChannel('Ammonia Sulphate shot','kg','h',t(~isnan(y)),y(~isnan(y)));
else
    y = interp1(t(~isnan(y)),y(~isnan(y)), tInterp,'linear','extrap');
    X.NH3_shots = createChannel('Ammonia Sulphate shot','kg','h',tInterp,y);
end
end

Copyright

Stephen Goldrick and Andrei Stefan University of Manchester, Newcastle University and Perceptive Engineering

All rights reserved. Copyright (c) Newcastle University, University of Manchester and Perceptive Engineering.