% EE4541 Fall 2008 % Assignment01 - Prob 8, Moving average filter % due Thursday Sept 11 % initialization clear all; close all; clc; % load Assignment01.mat load Assignment01.mat % eeg_ch_1, eeg_ch_2, and Fs exist % plot 1 t = (0:length(eeg_ch_1)-1) / Fs; figure; subplot(211); plot_1_1 = plot(t, eeg_ch_1); set(plot_1_1, 'LineWidth', 1.25); title('EEG Ch 1'); ylabel('[uV]'); subplot(212); plot_1_2 = plot(t, eeg_ch_2); set(plot_1_2, 'LineWidth', 1.25); title('EEG Ch 2'); xlabel('Time [sec]'); ylabel('[uV]'); % plot 2 figure; plot_2 = plot(t, eeg_ch_1, t, eeg_ch_2); set(plot_2, 'LineWidth', 1.25); title('EEG waveforms'); xlabel('Time [sec]'); ylabel('[uV]'); legend('EEG Ch 1', 'EEG Ch 2'); % Hints % a. refer to 'filter' function % b. refer to plot 2, especially 'set' and 'legend' functions % c. moving average filter's characteristics % d. order = # of input terms - 1 % solution B = ones(15,1)/15; % the order 14 filtering vector filtered_ch_1 = filter(B, 1, eeg_ch_1); filtered_ch_2 = filter(B, 1, eeg_ch_2); % plot figure; subplot(211); plot_3 = plot(t, eeg_ch_1, t, filtered_ch_1); set(plot_3, 'LineWidth', 1.25); title('EEG waveforms, order = 14'); xlabel('Time [sec]'); ylabel('[uV]'); legend('EEG Ch 1', 'filtered EEG Ch 1', 'Location', 'NW'); subplot(212); plot_4 = plot(t, eeg_ch_2, t, filtered_ch_2); set(plot_4, 'LineWidth', 1.25); xlabel('Time [sec]'); ylabel('[uV]'); legend('EEG Ch 2', 'filtered EEG Ch 2', 'Location', 'NW'); % solution to (a) B = ones(15,1)/15; % the order 14 filtering vector filtered_ch_1 = filter(B, 1, eeg_ch_1); filtered_ch_2 = filter(B, 1, eeg_ch_2); % (b) figure; subplot(211); plot_5 = plot(t, eeg_ch_1, t, filtered_ch_1); set(plot_5, 'LineWidth', 1.25); title('EEG waveforms, order = 8'); xlabel('Time [sec]'); ylabel('[uV]'); legend('EEG Ch 1', 'filtered EEG Ch 1', 'Location', 'NW'); subplot(212); plot_6 = plot(t, eeg_ch_2, t, filtered_ch_2); set(plot_6, 'LineWidth', 1.25); xlabel('Time [sec]'); ylabel('[uV]'); legend('EEG Ch 2', 'filtered EEG Ch 2', 'Location', 'NW'); % (c) % i. The MA removes some of the high frequency components, for example the sharp transients are significantly reduced. % ii. The output of the filter is a delayed version of the input (approximately 7-sample delay) % iii. Transient response during the first 14 samples of the output can be observed % Here, first 2 answers are sufficient % (d) % Repeat with C=ones(9,1)/9; % Here the order is equal to # of input terms - 1 % Less loss in high frequency somponents, less delay (4 samples), and shorter transient effect (8 samples)