fftlength = 1024; % Set FFT length
stepsize = 32; % Set step size
samples = fftlength:stepsize:length(eeg.raw); % create an index array
hanning = [1:fftlength]';
hanning_in = 2* pi() * (hanning - (fftlength+1)/2)/(fftlength+1);
%rescaled x-axis to match sample length?
hanning = (sin(hanning_in)./hanning_in).^2; % sinc^2?
hanning = repmat(hanning, 1, size(eeg.raw,2)); % match to number of channels
f=[128/fftlength:128/fftlength:128]; % frequency index for the spectral array
for kk = 1:length(samples)
% step through every quarter second starting at first possible sample
spectrum = fft(eeg.iirfilt(k-fftlength+1:k,:) .* hanning)/fftlength; % apply window to HP filtered data
spectrum = 2 * (sqrt(spectrum .* conj(spectrum))); % get magnitude
%plotting the time domain and IIR FFT data
plot(c,eeg.iirfilt(k-fftlength+1:k, channel));
title('Amplitude of Channels');
plot(f,spectrum(:, channel));
title('Amplitude Spectrum of Channels');
xlabel('Frequency (Hz)');