Question: Use the following matlab code: % Example 5.13 Applies an Transfer Function to % the EEG data stored in eeg_data. % clear all, close all;
Use the following matlab code:
% Example 5.13 Applies an Transfer Function to % the EEG data stored in eeg_data. % clear all, close all; load eeg_data; N = length(eeg); fs = 50; % Assume sample interval is 100 Hz % % Plot original data t = (0:N-1)/fs; % Construct time vector f= (0:N-1)*fs/N; % Construct frequency vector subplot(2,1,1); plot(t,eeg,'k'); % Plot time data xlabel('Time (sec)','FontSize',14); % Label plot axes ylabel ('EEG','FontSize',14); title('A) Original Data','FontSize',14); % % Decompose data %eeg = [eeg zeros(1,N-1)]; Vin1 = (fft(eeg)); % Use only magnitude in this example Vin = [Vin1(2:end) Vin1(1)]; Vout = Vin./(1 - .002*(2*pi*f).^2 + j*.003*2*pi*f); % Now solve for output using X comp0onents as input vout = real(ifft(Vout)); % Now recontruct time data and plot subplot(2,1,2); plot(t,vout,'k'); xlabel('Time (sec)','FontSize',14'); % Label plot axes ylabel ('EEG','FontSize',14'); title('B) Output Signal','FontSize',14); figure; nf = fix(length(Vout)/2); % Plot only non-redundant points subplot(2,1,1) plot(f(1:nf),abs(Vin(1:nf)),'k'); xlabel('Frequency (Hz)','FontSize',14'); ylabel('|In (f)|','FontSize',14'); title('A) Input Spectrum','FontSize',14); subplot(2,1,2); plot(f(1:nf),abs(Vout(1:nf)),'k'); xlabel('Frequency (Hz)','FontSize',14'); % Label plot axes ylabel ('|Out (f)|','FontSize',14'); title('B) Output Spectrum','FontSize',14); % figure; % Plot the spectrum of vout and compare with Vout Not part of example, but fun X = abs(fft(vout)); plot(f(1:nf),X(1:nf),'k') % This problem could be expanded to include a detemination of the TF using % the ratio of Vout/Vin but that was done in the previous section with % sinusiods.
Answer:
This example demonstrates how the 3-step processing approach (Figure 5.31/p212) works in finding the output of a complex biosignal to a particular transfer function, i.e. (1) FFT a given input signal to convert it from its time-domain to its frequency-domain; (2) the TF algebraic operation on the frequency-domain input signal to obtain the frequency-domain output and; (3) IFFT the output signal to convert it from its frequency-domain to its time-domain.
Assignment #3-1 (5 pts): From the partial script shown on p213, (1) which variable represents the frequency-domain input EEG? (2) Which variable represents the frequency-domain output? (3) Which variable represents the time-domain output? (4) What are the codes that complete the 3-step operation?
Assignment #3-2 (5 pts): Complete the script shown on p213 such that the time-domain input EEG and the time-domain output after the 3-step operation are plotted. Note: (1) Use 1/(1-0.05*(2*pi*f).^2 + j*0.1*2*pi*f) as TF and (2) Use the following two sets of codes to label the input and output plots;
xlabel('Time (sec)','FontSize',14);
ylabel ('EEG','FontSize',14);
legend('Input','FontSize',14);
xlabel('Time (sec)','FontSize',14');
ylabel ('EEG','FontSize',14');
legend('Output','FontSize',14);
Assignment #3-3-1 (5 pts): Write codes in a new section such that the frequency-domain input EEG (i.e. the input spectrum) and the frequency-domain output (i.e. the output spectrum) are plotted in a new figure. Note: (1) Plot the absolution values for both the input and output with the abs routine and; (2) Use the following two sets of codes to label the input and output plots;
xlabel('Frequency (Hz)','FontSize',14');
ylabel('|Input (f)|','FontSize',14');
legend('Input Spectrum','FontSize',14);
xlabel('Frequency (Hz)','FontSize',14');
ylabel ('|Output (f)|','FontSize',14');
legend('Output Spectrum','FontSize',14);
Assignment #3-3-2 (5 pts): The input and output spectra plotted in Assignment #3-3-1 contain redundant data points (i.e. the data in the 25~50 Hz frequency range that is the mirror image of that in 0~25 Hz) and they can be corrected by plotting the first half data points only using the following codes, an alternative way to xlim,
plot(f(1:nf),abs(Vin(1:nf)),'k');
plot(f(1:nf),abs(Vout(1:nf)),'k');
Assignment #3-4 (5 pts): Plot the magnitude and phase spectra of this TF in frequency (Hz).
Assignment #3-5 (5 pts): Use fft to transform the time-domain output signal into frequency-domain and plot it. Compare the resulting spectrum with the one obtained from the TF operation. Put a snapshot picture of the resulting plot in your lab report.
Assignment #3-6 (bonus 5 pts): Based on the input and out spectra, provide a brief description in your lab report about how the input EEG is processed by this system.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
