Bipolar montage generation for 2 EEG electrode signals

8 次查看(过去 30 天)
I create a code to generate EEG signals of 2 cases of Fp1 electrode for first 5 secs. Now I need to encorporate the 2 signals generated into another program to find bipolar montage. How can i do it? My code to generate EEG for 5 secs.
% Get information about EDF data
eeg_info = edfinfo("Subject00_1.edf");
Error using signal.internal.edf.openFile>validateFileRead
File "Subject00_1.edf" does not exist in this path.

Error in signal.internal.edf.openFile (line 36)
validateFileRead(fileInfo,fid,filename,errmsg);

Error in edfinfo/openFile (line 202)
[fid, fileInfo] = signal.internal.edf.openFile(filename,'r');

Error in edfinfo (line 167)
[obj, filename, fid, fileInfo] = openFile(obj, filename);
% All recorded Electrode signals:
eeg_sigLevels = eeg_info.SignalLabels;
% Read the recorded signal.
eeg_data = edfread('Subject00_1.edf');
% eeg_sigLevels(i)
eeg_dataFp1 = edfread("Subject00_1.edf", "SelectedSignals",'EEG Fp1');
eegFp1_cellArray = table2array(eeg_dataFp1);
eegFp1_Array = vertcat(eegFp1_cellArray{:});
% Plot Fp1 signal for 5 secs.
figure,
t = 0:1/500:5; % 1Sec = 500 Samples. Sampling Freq. = 500Hz
plot(t, eegFp1_Array(1:2501), '-b', 'LineWidth',1.5);
grid on
title('EEG Signal')
xlabel('Time in Secs')
ylabel('Amplitude in uvolts')
% Store the EEG data in a matrix for 5secs.
EEG_dataStore = zeros(length(eeg_sigLevels),length(t));
figure,
for i = 1:length(eeg_sigLevels)
% Read the EEG data from all the electrods
eeg_dataTable = edfread("Subject00_1.edf", "SelectedSignals",eeg_sigLevels(i));
eegData_cellArray = table2array(eeg_dataTable);
eegData_Array = vertcat(eegData_cellArray{:});
% Plot all the EEG recording from diff. electrods
subplot(length(eeg_sigLevels),1, i)
plot(t, eegData_Array(1:length(t)), '-b', 'LineWidth',1.0);
EEG_dataStore(i,:) = eegData_Array(1:length(t));
end
xlabel('Time in Secs')
ylabel('Amplitude in uvolts')

采纳的回答

Sudarsanan A K
Sudarsanan A K 2024-3-18
Hi Anushasree,
To incorporate the generated EEG signals into another program for calculating the bipolar montage (the potential difference between two adjacent electrodes), you can follow these steps:
  • Define a Function for Calculating Bipolar Montage: Create a function that takes two EEG signals as input and returns their bipolar montage. This function ensures reusability and modularity in your code. For example:
Create a file named calculateBipolarMontage.m and add the following MATLAB code:
function bipolarMontage = calculateBipolarMontage(signal1, signal2)
% Ensure both signals have the same length
if length(signal1) ~= length(signal2)
error('Signals must be of the same length');
end
% Calculate the bipolar montage
bipolarMontage = signal1 - signal2;
end
  • Use the Function with Your EEG Signals: After generating or obtaining the EEG signals for the electrodes of interest (e.g., Fp1 and Fp2), use the defined function to calculate the bipolar montage.
In your main script or another program where you have the EEG signals, call the calculateBipolarMontage function:
% Assuming you have already generated eegFp1_Array and eegFp2_Array
% Calculate bipolar montage between Fp1 and Fp2
bipolarMontage_Fp1_Fp2 = calculateBipolarMontage(eegFp1_Array(1:2501), eegFp2_Array(1:2501));
% Plot the bipolar montage signal for the first 5 seconds
t = 0:1/500:5; % Time vector, adjust as necessary
figure,
plot(t, bipolarMontage_Fp1_Fp2, '-r', 'LineWidth',1.5);
title('Bipolar Montage between Fp1 and Fp2')
xlabel('Time in Secs')
ylabel('Amplitude in uvolts')
grid on
This approach allows you to easily calculate and visualize the bipolar montage between any two EEG signals by leveraging a dedicated function, enhancing code readability and maintainability.
For more information on custom functions, types of functions, and function precedence order, refer to this documentation:
I hope this helps!

更多回答(1 个)

Neelam
Neelam 2024-3-22
% Assuming you have already generated eegFp1_Array and eegFp2_Array
% Calculate bipolar montage between Fp1 and Fp2
bipolarMontage_Fp1_Fp2 = calculateBipolarMontage(eegFp1_Array(1:2501), eegFp2_Array(1:2501));
% Plot the bipolar montage signal for the first 5 seconds
t = 0:1/500:5; % Time vector, adjust as necessary
figure,
plot(t, bipolarMontage_Fp1_Fp2, '-r', 'LineWidth',1.5);
title('Bipolar Montage between Fp1 and Fp2')
xlabel('Time in Secs')
ylabel('Amplitude in uvolts')
grid on

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by