clear
close all

% Useful functions: normpdf, butter, filter
% Note that normpdf expects a _standard deviation_ as input while in the
% task the variance is given.

%% Task 4b

% Generate residual
N = 500;
t = linspace(0, 10, N);

r = randn(1, N) + 2.0 * (t > 5);

figure(10)
plot(t, r)
xlabel('t')
ylabel('r')

% Task 4b: Create CUSUM and LP-filtered residual
T = 0; %YOUR CODE HERE
rlp = 0; % YOUR CODE HERE

% Task 4c: Create optimal CUSUM and compare with result from 4b
Topt = 0; %YOUR CODE HERE

% Task 4d: Detect change in variance

% Create residual with change in variance
r = randn(1, N) .* (1 + 1.0 * (t > 5));

figure(40)
plot(t, r)
xlabel('t')
ylabel('r')

Tvar = 0; %YOUR CODE HERE
