% eda09_16
% read Reynolds Channel Water Quality dataset
% columns are days, precip, air_temp, water_temp, salinity, turbidity, chlorophyl
% baldpass filter the data and plot it

% load data
D = load('reynolds_interpolated.txt');
[N, Ncols] = size(D);
Dt=1;
Df=D;

% figure 1 (low pass filter)
fcenter = 1/365.25;
flow = 0.75*fcenter;
fhigh =1.25*fcenter;

% bandpass filter
for i = [2:Ncols]
    [z, u, v] = chebyshevfilt(D(:,i), Dt, flow, fhigh);
    Df(:,i) = z;
end

% rename
t = Df(:,1);        % time, days
p = Df(:,2);        % precipitation, inches
at = Df(:,3);       % air temperature, deg C
wt = Df(:,4);       % water temperature, deg C
s = Df(:,5);        % salinity, practical salinity units
tb = Df(:,6);       % turbidity, 
c = Df(:,7);        % chlorophyll, micrograms per liter

% plot limits in samples
itmin=1;
itmax=N;
tmin=t(itmin);
tmax=t(itmax);

figure(1);
clf;

subplot(6,1,1);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(p(itmin:itmax)), max(p(itmin:itmax))] );
plot( t, p, 'k-', 'LineWidth', 2 );
ylabel('precip');

subplot(6,1,2);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(at(itmin:itmax)), max(at(itmin:itmax))] );
plot( t, at, 'k-', 'LineWidth', 2 );
ylabel('T-air');

subplot(6,1,3);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(wt(itmin:itmax)), max(wt(itmin:itmax))] );
plot( t, wt, 'k-', 'LineWidth', 2 );
ylabel('T-water');

subplot(6,1,4);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(s(itmin:itmax)), max(s(itmin:itmax))] );
plot( t, s, 'k-', 'LineWidth', 2 );
xlabel('time, days');
ylabel('salinity');

subplot(6,1,5);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(tb(itmin:itmax)), max(tb(itmin:itmax))] );
plot( t, tb, 'k-', 'LineWidth', 2 );
xlabel('time, days');
ylabel('turbidity');

subplot(6,1,6);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(c(itmin:itmax)), max(c(itmin:itmax))] );
plot( t, c, 'k-', 'LineWidth', 2 );
xlabel('time, days');
ylabel('chlorophyl');

% figure 2 (high pass filter)
figure(2);
clf;

fcenter = 1/5;
flow = 0.75*fcenter;
fhigh =1.25*fcenter;

% bandpass filter
for i = [2:Ncols]
    [z, u, v] = chebyshevfilt(D(:,i), Dt, flow, fhigh);
    Df(:,i) = z;
end

% rename
t = Df(:,1);        % time, days
p = Df(:,2);        % precipitation, inches
at = Df(:,3);       % air temperature, deg C
wt = Df(:,4);       % water temperature, deg C
s = Df(:,5);        % salinity, practical salinity units
tb = Df(:,6);       % turbidity, 
c = Df(:,7);        % chlorophyll, micrograms per liter

% plot limits in samples
itmin=400;
itmax=600;
tmin=t(itmin);
tmax=t(itmax);

subplot(6,1,1);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(p(itmin:itmax)), max(p(itmin:itmax))] );
plot( t, p, 'k-', 'LineWidth', 2 );
ylabel('precip');

subplot(6,1,2);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(at(itmin:itmax)), max(at(itmin:itmax))] );
plot( t, at, 'k-', 'LineWidth', 2 );
ylabel('T-air');

subplot(6,1,3);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(wt(itmin:itmax)), max(wt(itmin:itmax))] );
plot( t, wt, 'k-', 'LineWidth', 2 );
ylabel('T-water');

subplot(6,1,4);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(s(itmin:itmax)), max(s(itmin:itmax))] );
plot( t, s, 'k-', 'LineWidth', 2 );
xlabel('time, days');
ylabel('salinity');

subplot(6,1,5);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(tb(itmin:itmax)), max(tb(itmin:itmax))] );
plot( t, tb, 'k-', 'LineWidth', 2 );
xlabel('time, days');
ylabel('turbidity');

subplot(6,1,6);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax, min(c(itmin:itmax)), max(c(itmin:itmax))] );
plot( t, c, 'k-', 'LineWidth', 2 );
xlabel('time, days');
ylabel('chlorophyl');



