69.1 kB
mohkmh123's picture
Create a single, self-contained index.html file for a virtual "Biomedical Signal and Image Processing Laboratory" webpage. This page will serve as an interactive guide for Experiment 1: Analysis of Biomedical Signals in Time, Frequency, and Time-Frequency Domains Experiment 2: EEG Artifact Identification and Removal using ICA Student Name: _________________________ Student ID: _________________________ Date: _________________________ The page must be professional, easy to navigate, and include specific interactive features to simulate a real lab environment, including a novel feature to link with VS Code for code generation and execution. Key Requirements: 1. Structure and Content: o The webpage should be structured logically, following the provided lab manual. Use clear headings for "Objective," "Required Materials," "Part I: EEG," "Part II: EOG," "Part III: ECG," and "Part IV: EMG." o Incorporate all the text from the provided lab manual, including the background information, procedures, and "Analysis Task" questions for each step. o Include a header with the lab title: "Medical Signal and Image Processing Laboratory." o Include a footer with the author and copyright information:  Author: Dr. Mohammed Yagoub Esmail, SUST-BME  Contact: mohammedyagoubesmail@gmail.com, Phone: +249912867327, +966538076790  Copyright: © 2024 Dr. Mohammed Yagoub Esmail. All Rights Reserved. 2. Styling (CSS): o Use modern, clean, and academic styling. The CSS should be embedded within a <style> tag in the <head> of the index.html file. o Use a professional color scheme (e.g., blues, grays, and white). o Style different elements distinctly:  h1, h2, h3 for titles and section headings.  A specific style for "Background" sections (e.g., a light gray background box).  A distinct style for "Procedure" steps (e.g., numbered lists).  A prominent, eye-catching style for "Analysis Task" questions (e.g., using an icon like a lightbulb or question mark, and a different background color or border). o Make the layout responsive so it looks good on both desktop and tablet screens. 3. Interactivity (JavaScript): o The JavaScript code should be embedded within a <script> tag at the end of the <body> of the index.html file. o Collapsible Sections: Each major part (Part I, II, III, IV) should be a collapsible accordion panel. The user should see only the main heading and can click to expand and view the detailed procedure. This keeps the page clean and manageable. o Code Generation and VS Code Integration: This is the core interactive feature.  For each procedure step that involves writing python code (e.g., "1.a. Load the EEG_Seizure.mat file..."), place a button next to it labeled "Generate PYTHON Code."  When a user clicks this button, a modal window (popup) should appear.  The modal window will display the corresponding python code snippet in a formatted code block with syntax highlighting.  The modal window must contain two buttons: 1. "Copy Code": A button that copies the code snippet to the user's clipboard. 2. "Open in VS Code": This is the key integration. This button should be a link (<a> tag styled as a button) that uses the VS Code URI scheme (vscode://) to perform an action. Specifically, it should trigger the creation of a new, untitled PYTHON file (.m) in VS Code and paste the generated code into it. The URI should be structured like this: vscode://file/new-untitled?language=Python&content=<URL_ENCODED_CODE_SNIPPET>. o Image Placeholders: For every plot mentioned in the lab manual (e.g., "Plot of 5th Channel Signal vs. Time"), insert a styled placeholder div. This div should have a gray background, a dashed border, and centered text that says "Plot Output Area." This visually indicates where the student's generated plot should be compared. 1. Objectives Upon completion of this lab, you will be able to: • Visually identify common artifacts in EEG signals (EMG, EOG, ECG). • Understand and apply the Independent Component Analysis (ICA) algorithm to separate signal sources. • Analyze ICA components using their time course, power spectrum, and scalp topography. • Make an informed decision on which components to remove. • Reconstruct a clean EEG signal and evaluate the denoising performance. 2. Background Electroencephalography (EEG) measures the brain's electrical activity but is often contaminated by non-brain signals called artifacts. Independent Component Analysis (ICA) is a computational method that separates a set of mixed signals (like the EEG channels) into their underlying, statistically independent sources. By identifying which sources correspond to artifacts, we can remove them and reconstruct a cleaner signal, improving the quality of any subsequent analysis. 3. Materials & Setup 1. Objective This experiment aims to provide a practical understanding of fundamental biomedical signals (EEG, EOG, ECG, EMG) and the core concepts of digital signal processing used to analyze them. Students will learn to: 1. Visualize and interpret biomedical signals in the time domain. 2. Apply the Discrete Fourier Transform (DFT) to analyze the frequency content of signals. 3. Utilize the Short-Time Fourier Transform (STFT) and power spectral density estimation (pwelch) to understand how a signal's frequency content changes over time. 4. Investigate the effects of sampling and filtering on signal integrity. 5. Identify and characterize key features, artifacts, and clinical abnormalities within these signals. 2. Required Materials and Software • Software: MATLAB (with the Signal Processing Toolbox). • Datasets: o EEG_Seizure.mat: A multi-channel EEG recording of a patient experiencing an epileptic seizure. o EOG_Movement.mat: A two-channel EOG recording capturing horizontal eye movements. o ECG_Arrhythmia.mat: A two-channel ECG recording containing normal heartbeats and various arrhythmias. o EMG_Disorders.mat: Three separate EMG recordings from a healthy subject, a patient with myopathy, and a patient with neuropathy. ________________________________________ Part I: Electroencephalogram (EEG) Analysis - Seizure Detection Background: EEG signals measure the brain's electrical activity. They are characterized by low amplitude and specific frequency bands (Delta, Theta, Alpha, Beta, Gamma) associated with different brain states. During an epileptic seizure, brain activity becomes highly synchronized and abnormal, which is clearly visible in the EEG. Procedure: 1. Data Loading and Initial Visualization: a. Load the EEG_Seizure.mat file into your MATLAB workspace. This file should contain the EEG data matrix (eeg_data), the sampling frequency (fs), and channel labels (channel_labels). b. Select a single channel (e.g., Channel 5) and plot its entire duration in the time domain. Label your axes appropriately (Amplitude vs. Time in seconds). c. Analysis Task: Observe the signal's overall morphology. Identify distinct periods of activity. Does the amplitude or frequency appear to change over time? Note your initial observations. 2. Comparative Channel Analysis: a. Select a different channel (e.g., Channel 23) and plot it below the first one for comparison. b. Analysis Task: Compare the two channels. Note similarities and differences in amplitude, frequency, and the presence of artifacts like eye blinks (sharp, high-amplitude spikes). 3. Multi-Channel Visualization: a. Plot all EEG channels on a single figure. To prevent overlap, apply a vertical offset to each channel's data before plotting. A common technique is to add i * offset_value to the i-th channel's data. b. Analysis Task: Observe the global brain activity. Can you identify the approximate time when the seizure begins? Which channels appear to be most affected? Note how the seizure activity propagates across different brain regions (channels). 4. Time-Frequency Analysis of Seizure Evolution: a. From a single channel (e.g., Channel 5), extract four distinct 5-second epochs representing different states: * Baseline/Normal: 2s to 7s * Pre-Ictal (Before Seizure): 30s to 35s * Ictal (During Seizure): 42s to 47s * Post-Ictal/Late Seizure: 50s to 55s b. For each epoch, perform the following analyses: i. Time Domain Plot: Plot the 5-second segment. ii. Frequency Domain (DFT): Compute the FFT of the epoch. Use fftshift to center the spectrum at 0 Hz. Plot the magnitude spectrum against frequency (Hz). iii. Power Spectral Density (PSD): Use the pwelch function to estimate the PSD of the epoch. This provides a smoother, more statistically robust frequency representation. iv. Time-Frequency (STFT): Use the spectrogram function to visualize how the frequency content changes within the 5-second epoch. Use a Hamming window of a suitable length (e.g., 256 samples) with 50% overlap. c. Analysis Task: For each state (Baseline, Pre-Ictal, etc.), compare the four plots. How does the frequency content change from normal brain activity to seizure activity? Look for dominant frequencies, the emergence of rhythmic patterns (like the 10 Hz spikes in the pre-ictal phase), and the broadening of the frequency spectrum during the seizure. 5. Downsampling and Filtering: a. Take the pre-ictal epoch (30s-35s). Note its primary frequency content from the FFT plot. b. Design a low-pass Butterworth filter (e.g., 6th order) with a cutoff frequency just above the highest significant frequency (e.g., 60 Hz). c. Apply this filter to the epoch. d. Downsample the filtered signal by a factor of 2 using the downsample command. e. Plot the time, frequency, and spectrogram representations of this new, downsampled signal. f. Analysis Task: Compare these plots to the originals. Has any significant information been lost? Discuss the trade-offs between a lower sampling rate (less data) and signal fidelity. This demonstrates the Nyquist theorem in a practical context. ________________________________________ Part II: Electrooculogram (EOG) Analysis - Eye Movement Background: EOG measures the electrical potential difference between the front and back of the eye. This potential changes as the eye moves, allowing us to track eye movements. Procedure: 1. Data Loading and Time-Domain Visualization: a. Load the EOG_Movement.mat file. It contains two channels, one for the left eye and one for the right. b. Plot both channels on the same axes. c. Analysis Task: Describe the relationship between the two signals. Are they correlated? Inverted? What does this tell you about the electrode placement and the nature of the eye movements being recorded? 2. Frequency and Time-Frequency Analysis: a. Compute and plot the FFT for each EOG channel. b. Compute and plot the spectrogram for each channel. c. Analysis Task: What is the dominant frequency range for eye movements? Is this what you would expect? Correlate high-frequency activity in the spectrogram with high-amplitude, rapid movements in the time-domain plot. ________________________________________ Part III: Electrocardiogram (ECG) Analysis - Arrhythmia Identification Background: ECG records the heart's electrical activity. A normal heartbeat has a characteristic P-QRS-T waveform. Arrhythmias are irregularities in the heart's rhythm, which manifest as deviations from this normal pattern. Procedure: 1. Data Loading and Waveform Identification: a. Load the ECG_Arrhythmia.mat file. It contains two channels (lead II and lead V1), sampling frequency, and arrhythmia annotations. b. Plot a short segment (e.g., 5 seconds) of a "normal" period of the ECG. c. Zoom in on a single, clear heartbeat. Identify and label the P wave, QRS complex, and T wave. d. Analysis Task: Compare the morphology of the same beat in both channels. Explain why they might look different (due to different lead perspectives). 2. Arrhythmia Visualization and Labeling: a. Plot a 10-second segment of the ECG known to contain arrhythmias (e.g., starting at 530s). b. Use the provided annotation data to overlay text labels (e.g., 'PVC', 'NAPC') on the plot at the correct time points for each abnormal beat. c. Analysis Task: For each labeled arrhythmia type (PVC, NAPC, RHYTHM, etc.), visually compare it to a normal beat. Describe the key differences in terms of: * Timing: Is the beat premature or late? * Morphology: Is the QRS complex wider? Is the P wave absent? * Rhythm: Is the interval to the next beat regular or irregular? 3. Time-Frequency Analysis of Normal vs. Abnormal Beats: a. Extract two 2-second segments from Channel 1: * A segment containing only normal beats. * A segment containing an abnormal beat (e.g., the PVC/Rhythm beat around 477s). b. For both segments, compute and plot the FFT and the spectrogram. For the spectrogram, use two different window sizes (e.g., 128 and 64 samples) to observe the trade-off between time and frequency resolution. c. Analysis Task: Compare the frequency content of the normal and abnormal beats. Does the arrhythmia introduce new frequency components? How does the energy distribution in the spectrogram differ? Explain how a shorter window in the STFT provides better temporal localization of the beat's components. ________________________________________ Part IV: Electromyogram (EMG) Analysis - Neuromuscular Disorders Background: EMG measures the electrical signals produced by muscles. The signal's characteristics (amplitude, frequency, firing pattern) can reveal the health of the muscle and its controlling nerves. Procedure: 1. Data Loading and Comparative Visualization: a. Load the EMG_Disorders.mat file. It contains three separate signals: emg_healthy, emg_myopathy, and emg_neuropathy. b. Plot the entire duration of all three signals in separate subplots. c. Analysis Task: Make general observations. Which signal has the largest amplitude? Which appears most "random" or "spiky"? 2. Zoomed-in Morphological Analysis: a. Zoom in on short, representative segments of each of the three signals. b. Analysis Task: Describe the detailed morphology. * Healthy: Note the pattern of motor unit recruitment during contraction. * Myopathy (muscle disease): Look for lower-amplitude, shorter-duration motor unit action potentials (MUAPs). * Neuropathy (nerve disease): Look for high-amplitude, long-duration, "giant" MUAPs, which result from nerve regeneration and reinnervation. 3. Frequency and Time-Frequency Analysis: a. For each of the three EMG signals, compute and plot the FFT and the spectrogram. b. Analysis Task: Compare the frequency spectra. How does the frequency content shift with each disorder? * Healthy: Should have a broad spectrum. * Myopathy: Tends to shift power to higher frequencies. * Neuropathy: Tends to shift power to lower frequencies. c. Correlate the features in the spectrograms with the time-domain signals. For example, do the "giant" spikes in the neuropathy signal correspond to bursts of low-frequency power in its spectrogram? Experiment Title: Separation of Maternal and Fetal ECG Signals using Signal Processing Techniques Objective: This experiment aims to introduce fundamental signal processing techniques for analyzing and separating biomedical signals. Specifically, we will focus on separating maternal and fetal electrocardiogram (ECG) signals from a mixed signal, and removing noise. We will explore the application of Singular Value Decomposition (SVD) and Independent Component Analysis (ICA) for this purpose. Introduction: Biomedical signals, such as ECG, EEG, and EMG, often contain valuable physiological information. However, these signals can be corrupted by noise from various sources (e.g., muscle artifacts, power line interference) and can also contain superimposed signals from different physiological processes (e.g., maternal and fetal ECG). Effective signal processing techniques are crucial for extracting meaningful information and improving diagnostic accuracy. This experiment will utilize a simulated dataset containing maternal ECG, fetal ECG, and noise. We will first analyze the characteristics of these individual signals and the mixed signal in both the time and frequency domains. Subsequently, we will apply SVD and ICA to separate the fetal ECG signal from the mixed signal and evaluate the effectiveness of each method. Materials and Equipment: 1. Computer: With MATLAB installed. 2. MATLAB Toolboxes: o Signal Processing Toolbox o (Potentially) Statistics and Machine Learning Toolbox (for some functions like cov, mean) 3. Dataset: A pre-recorded or simulated dataset containing: o Maternal ECG signal (M_ECG.mat) o Fetal ECG signal (F_ECG.mat) o Noise signal (Noise.mat) o A mixed signal (Mixed_Signal.mat) which is a combination of the above. (Note: The actual file names might differ based on the source of the data. The provided document implies these signals are available.) Theoretical Background: • Time-Domain Analysis: Visual inspection of signals in the time domain to understand amplitude, frequency, and waveform characteristics. • Frequency-Domain Analysis (Power Spectral Density - PSD): Using methods like pwelch to analyze the frequency content of signals, identifying dominant frequencies and bandwidths. • Singular Value Decomposition (SVD): A matrix factorization technique that decomposes a data matrix into three other matrices (U, S, V). In signal processing, SVD can be used for dimensionality reduction, noise reduction, and source separation by identifying principal components (directions of maximum variance). • Independent Component Analysis (ICA): A statistical method used to separate a multivariate signal into additive subcomponents assuming that the subcomponents are non-Gaussian and mutually independent. ICA aims to find a linear transformation that maximizes the statistical independence of the estimated components. Experimental Procedure: Part 1: Signal Analysis and Preprocessing 1. Load Data: o Open MATLAB. o Navigate to the directory containing the dataset files. o Load the signals into the MATLAB workspace: Generated matlab load('M_ECG.mat'); % Assuming M_ECG contains the maternal ECG signal load('F_ECG.mat'); % Assuming F_ECG contains the fetal ECG signal load('Noise.mat'); % Assuming Noise contains the noise signal load('Mixed_Signal.mat'); % Assuming Mixed_Signal contains the mixed signal o Ensure your loaded variables correspond to the actual signal data (e.g., m_ecg_signal, f_ecg_signal, noise_signal, mixed_signal). You might also need time vectors if they are not implicitly handled. 2. Time-Domain Visualization: o Plot each of the individual signals (Maternal ECG, Fetal ECG, Noise) and the mixed signal against time. o MATLAB Code Snippet: Generated matlab time = 0:1/Fs:10-1/Fs; % Assuming Fs is the sampling frequency and signals are 10 seconds long figure; subplot(4,1,1); plot(time, m_ecg_signal); title('Maternal ECG'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(4,1,2); plot(time, f_ecg_signal); title('Fetal ECG'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(4,1,3); plot(time, noise_signal); title('Noise'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(4,1,4); plot(time, mixed_signal); title('Mixed Signal'); xlabel('Time (s)'); ylabel('Amplitude'); sgtitle('Time-Domain Analysis of ECG Signals'); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Visually inspect the waveforms, identify characteristic PQRST complexes, and observe the nature of the noise. 3. Frequency-Domain Analysis (PSD): o Calculate and plot the Power Spectral Density (PSD) for each signal using the pwelch function. This will help identify the frequency bands where each signal component is dominant. o MATLAB Code Snippet: Generated matlab figure; [Pxx_m, F_m] = pwelch(m_ecg_signal, [], [], [], Fs); % Use appropriate window and overlap for pwelch subplot(4,1,1); plot(F_m, 10*log10(Pxx_m)); title('Maternal ECG PSD'); xlabel('Frequency (Hz)'); ylabel('PSD (dB/Hz)'); [Pxx_f, F_f] = pwelch(f_ecg_signal, [], [], [], Fs); subplot(4,1,2); plot(F_f, 10*log10(Pxx_f)); title('Fetal ECG PSD'); xlabel('Frequency (Hz)'); ylabel('PSD (dB/Hz)'); [Pxx_n, F_n] = pwelch(noise_signal, [], [], [], Fs); subplot(4,1,3); plot(F_n, 10*log10(Pxx_n)); title('Noise PSD'); xlabel('Frequency (Hz)'); ylabel('PSD (dB/Hz)'); [Pxx_mix, F_mix] = pwelch(mixed_signal, [], [], [], Fs); subplot(4,1,4); plot(F_mix, 10*log10(Pxx_mix)); title('Mixed Signal PSD'); xlabel('Frequency (Hz)'); ylabel('PSD (dB/Hz)'); sgtitle('Frequency-Domain Analysis (PSD) of ECG Signals'); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Note the frequency ranges where maternal ECG, fetal ECG, and noise are most prominent. Typically, maternal ECG is in the lower frequency range (e.g., < 30 Hz), fetal ECG is slightly higher, and noise can be broadband or concentrated at specific frequencies. Part 2: Signal Separation using SVD 1. Prepare Data for SVD: o SVD is typically applied to a matrix. For multi-channel signals, we can arrange them as columns of a matrix. If you have a single mixed signal, you might need to create multiple "channels" or use a different approach if the data is inherently single-channel. The provided document implies a multi-channel input for SVD (3 Channel Data). Let's assume you have a data matrix X where each column is a signal (e.g., mixed_signal might be treated as one channel, and you might need to create others or use a different data structure if the original data is indeed multi-channel). o Based on the document's figures, it seems the input to SVD is a 3-channel signal. If your mixed_signal is single-channel, you might need to simulate or load a multi-channel version for this part. Let's assume X is a matrix where X(:,1) is maternal ECG, X(:,2) is fetal ECG, and X(:,3) is noise, or a combination thereof. If you only have one mixed_signal, you might need to adapt this part or focus on the ICA section which seems to handle multi-channel data more directly. o Assuming a 3-channel input matrix X: Generated matlab % Assuming X is a matrix where columns are different channels/signals % For demonstration, let's assume X is constructed from the loaded signals % This is a placeholder and needs to be adapted based on your actual data structure % If you only have one mixed signal, this part might need modification or skipping. % Let's assume X is already loaded or created as a 3-channel signal. % Example: X = [m_ecg_signal, f_ecg_signal, noise_signal]; % This is a simplification % The document implies a 3-channel input for SVD. IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END 2. Perform SVD: o Apply SVD to the data matrix X. o MATLAB Code Snippet: Generated matlab [U, S, V] = svd(X, 'econ'); % 'econ' for economy-size decomposition IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END 3. Analyze Singular Values and Vectors: o Plot the singular values (diagonal elements of S). The largest singular values correspond to the most dominant components. o Plot the "eigenspectrum" (singular values). o MATLAB Code Snippet: Generated matlab figure; plot(diag(S), 'bo-'); % Plot singular values title('Singular Values'); xlabel('Singular Value Index'); ylabel('Magnitude'); figure; plot(1:length(diag(S)), diag(S), 'bo-'); % Plot eigenspectrum title('Eigenspectrum'); xlabel('Singular Value Number'); ylabel('Singular Value'); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Identify which singular values correspond to significant components. The document suggests the second component is the fetal signal. 4. Reconstruct Denoised Signal: o To remove noise, you typically zero out the singular values corresponding to the noise components and reconstruct the signal using the remaining components. Based on the document, components 1 and 3 are considered noisy, and component 2 is kept. o MATLAB Code Snippet: Generated matlab % Create a modified singular value matrix by zeroing out noisy components S_denoised = S; S_denoised(1,1) = 0; % Zero out the first singular value (assumed noise) S_denoised(3,3) = 0; % Zero out the third singular value (assumed noise) % Reconstruct the denoised signal X_denoised_SVD = U * S_denoised * V'; IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END 5. Visualize Denoised Signal: o Plot the denoised signal (e.g., the second channel of X_denoised_SVD) and compare it with the original fetal ECG signal. o MATLAB Code Snippet: Generated matlab figure; plot(time, X_denoised_SVD(:,2)); % Plot the denoised second channel hold on; plot(time, f_ecg_signal, 'r--'); % Plot original fetal ECG for comparison title('SVD Denoised Signal (Channel 2) vs. Original Fetal ECG'); xlabel('Time (s)'); ylabel('Amplitude'); legend('SVD Denoised', 'Original Fetal ECG'); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Evaluate how well the fetal ECG signal has been separated and how much noise has been removed. Part 3: Signal Separation using ICA 1. Prepare Data for ICA: o ICA is typically applied to multi-channel data. Ensure your input data X is a matrix where each column represents a source signal. The document uses a 3-channel input for ICA. o Assuming a 3-channel input matrix X: Generated matlab % Ensure X is a matrix with channels as columns. % If you only have a single mixed signal, you might need to create artificial channels % or use a different approach if the data is not inherently multi-channel. % The document implies a 3-channel input for ICA. IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END 2. Perform ICA: o Apply ICA to the data matrix X. The ica function in MATLAB's Signal Processing Toolbox can be used. o MATLAB Code Snippet: Generated matlab [W, ZHAT] = ica(X); % W is the unmixing matrix, ZHAT contains the estimated independent components % W_inv = inv(W); % Inverse of the unmixing matrix IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END 3. Analyze Separated Sources: o The ZHAT matrix contains the estimated independent components. Plot these components in the time domain. o MATLAB Code Snippet: Generated matlab figure; subplot(3,1,1); plot(time, ZHAT(:,1)); title('Estimated Source 1'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(3,1,2); plot(time, ZHAT(:,2)); title('Estimated Source 2'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(3,1,3); plot(time, ZHAT(:,3)); title('Estimated Source 3'); xlabel('Time (s)'); ylabel('Amplitude'); sgtitle('Estimated Independent Components (ICA)'); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Identify which of the estimated sources corresponds to the maternal ECG, fetal ECG, and noise. The document suggests Source 1 is maternal, Source 2 is noise, and Source 3 is fetal. 4. Reconstruct Denoised Signal (Fetal ECG): o Based on the observation, select the component that represents the fetal ECG (e.g., ZHAT(:,3)). o To isolate this component, you can create a new matrix where only the fetal component is present, and the others are zeroed out. o MATLAB Code Snippet: Generated matlab % Assuming Source 3 is the fetal ECG ICA_fetal_signal = zeros(size(ZHAT)); ICA_fetal_signal(:,3) = ZHAT(:,3); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Note: The document also mentions reconstructing the signal using X = U * S * VT after modifying S for SVD. For ICA, you typically select the desired component directly from ZHAT or reconstruct using the corresponding column of W_inv if you want to transform back to the original space. The document's approach for ICA reconstruction is to zero out columns of W_inv and then multiply by ZHAT. Let's follow that: Generated matlab W_inv = inv(W); ICA_reconstructed = W_inv * ZHAT; % This is the original data reconstructed from components % To isolate the fetal component (assuming it's the 3rd source) % We can zero out the contributions of other sources. % A simpler approach is to just take the desired component from ZHAT. % However, if we want to reconstruct the signal in the original space, % we need to consider which component of W_inv corresponds to the desired source. % The document suggests zeroing out columns of W_inv. ICA_reconstructed_denoised = W_inv * ICA_fetal_signal; % Reconstruct using only the fetal component IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END 5. Visualize Denoised Signal: o Plot the isolated fetal ECG signal obtained from ICA and compare it with the original fetal ECG signal. o MATLAB Code Snippet: Generated matlab figure; plot(time, ICA_reconstructed_denoised(:,1)); % Assuming the reconstruction results in a single channel or you select the relevant one hold on; plot(time, f_ecg_signal, 'r--'); % Plot original fetal ECG for comparison title('ICA Denoised Signal vs. Original Fetal ECG'); xlabel('Time (s)'); ylabel('Amplitude'); legend('ICA Denoised', 'Original Fetal ECG'); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Evaluate the quality of the separated fetal ECG signal and the amount of noise removed by ICA. Part 4: Comparison and Evaluation 1. Quantitative Comparison: o Calculate similarity metrics between the original fetal ECG and the denoised signals obtained from SVD and ICA. Common metrics include:  Correlation Coefficient: Measures the linear relationship between two signals.  Mean Squared Error (MSE): Measures the average squared difference between the two signals. o MATLAB Code Snippet: Generated matlab % For SVD denoised signal (assuming it's the second channel) corr_svd = corrcoef(f_ecg_signal, X_denoised_SVD(:,2)); mse_svd = mean((f_ecg_signal - X_denoised_SVD(:,2)).^2); % For ICA denoised signal (assuming it's the first channel of reconstruction) corr_ica = corrcoef(f_ecg_signal, ICA_reconstructed_denoised(:,1)); mse_ica = mean((f_ecg_signal - ICA_reconstructed_denoised(:,1)).^2); disp(['SVD - Correlation: ', num2str(corr_svd(1,2)), ', MSE: ', num2str(mse_svd)]); disp(['ICA - Correlation: ', num2str(corr_ica(1,2)), ', MSE: ', num2str(mse_ica)]); IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Matlab IGNORE_WHEN_COPYING_END o Observation: Compare the correlation coefficients and MSE values. Higher correlation and lower MSE indicate better signal separation. The document suggests ICA performs better. 2. Qualitative Comparison: o Visually compare the time-domain plots of the original fetal ECG, SVD-denoised signal, and ICA-denoised signal. o Observe the presence of residual noise and the fidelity of the PQRST complexes in the separated signals. o The document also mentions comparing correlation matrices. Discussion: 1. Discuss the observed characteristics of the maternal ECG, fetal ECG, and noise signals in both the time and frequency domains. 2. Explain how SVD was applied and how the singular values helped in identifying components. 3. Explain how ICA was applied and how the independent components were identified. 4. Compare the performance of SVD and ICA in separating the fetal ECG signal. Which method provided a cleaner signal with less noise? 5. Discuss the advantages and disadvantages of each method based on your observations and the theoretical background. 6. Refer to the document's conclusions regarding the effectiveness of ICA versus SVD for this task. Conclusion: Summarize the findings of the experiment. State which method was more effective in separating the fetal ECG signal and why. Briefly mention the potential applications of these techniques in real-world biomedical signal processing. Further Exploration (Optional): • Experiment with different windowing functions and parameters for pwelch. • Try different numbers of components to keep in SVD. • Investigate other ICA algorithms or parameters. • Apply these techniques to other types of biomedical signals (e.g., EEG, EMG). • Explore other noise reduction techniques (e.g., filtering). ________________________________________ Important Notes for the Instructor/Lab Assistant: • Data Preparation: Ensure the dataset is readily available and correctly formatted for MATLAB. Provide clear instructions on how to load the data if it's not in a standard .mat file. • Sampling Frequency (Fs): The code snippets assume a sampling frequency Fs. This needs to be defined or loaded along with the data. • Signal Length: The time vector generation assumes a specific signal length (10 seconds). Adjust this based on the actual data. • Multi-channel Data: The SVD and ICA parts heavily rely on multi-channel input. If the provided data is only a single mixed signal, you will need to either: o Provide a multi-channel dataset. o Guide students on how to artificially create multiple channels from a single signal (though this might not be ideal for demonstrating SVD/ICA's true power). o Focus more on the ICA part if the data is inherently multi-channel. • MATLAB Functions: Ensure students have access to the necessary MATLAB toolboxes. • Guidance: Be prepared to assist students with understanding the MATLAB code and interpreting the results. The document provides specific observations (e.g., which component is which), which can be used to guide students during their analysis. This lab manual provides a structured approach to conducting the experiment based on the provided document, covering data analysis, application of SVD and ICA, and evaluation of results. - Initial Deployment
dd36056 verified