Homework 2: Linear Systems Responses

The data file eeg.mat contains a few seconds of electro-encephalography (EEG) signal as well as one channel with electro-oculogram signal. Load the file and pick channel x(1,:) as the EOG signal and some other channel, e.g. x(5,:) as the EEG signal. Your task is to model the relationship of the EOG signal with that of the EEG signal as a linear system, whereby the EOG signal is considered the input and the EEG signal is considered the output. Specifically, find filter coefficients with the minimum least-squares error. First use a moving average (MA) filter as the model for the linear system. Then try an auto-regressive filter (AR) as a model, and then finally a combined ARMA filter. Show in all instances as a function of time: (1) the impulse response of the model (2) the output of the model, i.e. the estimated EEG channel and (3) the difference of 1 and 2, i.e. the residual error of your model. Plot the mean-squared error as a function of model order, i.e. show how the error changes as a function of the length of the MA and AR filters. Please label all axes and put a title on all your figures.

Hint: Your code starts something like this:

% load and prepare the data
clear all
close all
load eeg
fs=250;
t=(1:length(x))/fs;
y=x(5,:);
x=x(1,:);

% model as an MA filter
Q=2;
X = toeplitz ...
b = ...
a = 1;
impulse = ...
h = filter(b,a,impulse);
y_est = filter(b,1,x); % or the same thing ...
y_est = X*b;           % ... as the previous line   

% show the results 
subplot(3,1,1); stem(h); title('MA impuse response')
subplot(3,1,2); plot(t,y_est)
subplot(3,1,3); plot ...

% model as an AR filter
....

And then it may continue something like this:
% Try AR modeling with different model orders
for P=1:10
  
  % AR modeling of order P
  ...

  error(P) = ...

end

% show error as a function of model order
plot(error)

% Try MA modeling with different model orders
....

good luck!