Seeking Guidance on Electrophysiology Data Analysis: Data Smoothing, Baseline Adjustment, and Graph Overlay

50 visualizzazioni (ultimi 30 giorni)
Hello everyone,
I'm currently working on analyzing my electrophysiology experiment data, and I could really use some guidance on a few specific aspects. Here's what I've done so far and where I'm stuck:
  1. Experiment Setup: I conducted an electrophysiology experiment measuring fEPSP, generating ten .wcp data files, with each file containing a biological replicate of the experiment. Additionally, I have an Excel file called notebook.xlsx, which contains information about when each drug cocktail was applied to the slice in each experiment.
  2. Data Import: I've successfully imported notebook.xlsx into MATLAB using the readtable function. Furthermore, I've set up a loop to import the data files using the filenames listed in the notebook.
  3. Preprocessing Steps: Here's where I need assistance:
  • Baseline Adjustment: I'm struggling with setting the baseline to zero for each record.
  • Data Smoothing: I'm unsure about the best method to smooth the data effectively as it is all importing into the inccorect format
  • Plotting: I need help overlaying multiple graphs for comparison. graph one being first drug application, second being secodn drug application and thrid being third drug application and the final being an overlay of all of the graphs
  1. Data Analysis:
  • Peak Amplitude Extraction: I need to extract the peak amplitude for each record under four different conditions, using the information from the notebook
  • Statistical Analysis: Suggestions on performing statistical analysis and visualizing the results graphically.
Here's the code I have so far:
clear all
close all
clc
%% Import notebook data
notebook_data = readtable("/Users/lilybrazier/Documents/MATLAB/Coursework 2 (summative) - Assignment brief and materials-20240308/data files/notebook.xlsx");
CADO = notebook_data(:,2);
CADO_DPCPX = notebook_data(:,3);
CADO_DPCPX_NBQX = notebook_data(:,4);
time_interval = 9.765000000000000e-05;
%% Batch process data files
data = "/Users/lilybrazier/Documents/MATLAB/Coursework 2 (summative) - Assignment brief and materials-20240308/data files/";
files = dir(fullfile(data, "*.wcp"));
num_files = length(files);
%% Loop Through .wcp data and import using the import_wcp function
for i = 1:num_files
current_file = fullfile(data, files(i).name);
% Import the data using your function import_wcp
imported_data{i} = import_wcp(current_file);
end
%% Create a time axis
% Define the sampling
for i = 1:num_files
num_samp{i} = size(imported_data{i}.S{1,1});
t{i} = 0:imported_data{i}.t_interval:((num_samp{1,i}(:,2))-1)*imported_data{i}.t_interval; % generating the time axis
t{i} = t{i}*10000;
end
%% setting the baseline to zero ??
%% Smooth Data
smoothfactor = 11;
% smooth data noisy data
for i = 1:num_files
smoothed_data{i} = smooth(imported_data{1,i}.S{1,1}(:,:),smoothfactor);
%(imported_data{1, 1}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
end
%% Plot Graphs
figure
%CADO Drug condtion subplot
subplot (3,3,1)
for i = 1:10
% Find the closest time in the t cell array
[~, idx] = min(abs(t{i} - CADO{i,:}));
% Define new time axis for 10 seconds after the extracted time
new_time_axis2 = t{i}(idx) + t{i}(idx)+10);
% Extract corresponding values from imported_data
corresponding_values2 = imported_data{i}.S{1}(:, idx{i}:idx{i}+length(new_time_axis2)-1);
% Plot data
plot(new_time_axis2, corresponding_values2);
hold on;
% Measure peak amplitude
peak_amplitude2 = max(corresponding_values2, [], 1) - min(corresponding_values2, [], 1);
peak_amplitudes2(i) = peak_amplitude2;
end
%CADO_DPCP Drug condtion subplot
subplot(3,3,2)
for i = 1:num_files
% Find the closest time in the t cell array
[~, idx] = min(abs(t{i} - CADO_DPCPX{i,:}));
% Define new time axis for 10 seconds after the extracted time
new_time_axis = t{i}(idx) : t{i}(idx) + 10;
% Extract corresponding values from imported_data
corresponding_values = imported_data{i}.S{1}(:, idx:idx+length(new_time_axis)-1);
% Plot data
plot(new_time_axis, corresponding_values);
hold on;
% Measure peak amplitude
peak_amplitude = max(corresponding_values) - min(corresponding_values);
peak_amplitudes(i) = peak_amplitude;
end
%CADO_DPCPX Drug condtion subplot
corresponding_values3 []
new_time_axis3 = []
for i = 1:10
% Find the closest time in the t cell array
[~, idx] = min(abs(t{i} - CADO_DPCPX_NBQX{i,:}));
% Define new time axis for 10 seconds after the extracted time
new_time_axis3{i,i} = t{i}(idx) : t{i}(idx) + 10;
% Extract corresponding values from imported_data
corresponding_values3{i,i} = imported_data{i}.S{1}(:, idx:idx+length(new_time_axis3)-1);
% Plot data
plot(new_time_axis3{i}, corresponding_values3{i});
hold on;
% Measure peak amplitude
peak_amplitude3 = max(corresponding_values3) - min(corresponding_values3)
peak_amplitudes3(i) = peak_amplitude3;
end
%Overlay all electrophysiology data in final plot
subplot(3,3,4:6)
plot(imported_data{1, 1}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 2}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 3}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 4}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 5}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 6}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 7}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 8}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 9}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
hold on
plot(imported_data{1, 10}.S{1, 1},'DisplayName','imported_data{1, 1}.S{1, 1}')
%% Run Satistical Analyis on peaks (ANOVA) and then post host comparision on the peaks of the diffetn drugs

Risposte (1)

Star Strider
Star Strider il 21 Mar 2024
There are probably several ways to do what you want, depending on what that is.
To remove a wandering or non-zero baseline, onoe option is to use a highpass filter with relatively low frequency stopband. This will remove any D-C offsets as well as low-frequency baseline wander. The signal will be biphasic (likely with a zerp mean) and if low frequencies are part of the signal, this may not be the best option. (It works well with EKG traces.) Another option is to use either findpeaks (with a negated signal argument so that valleys become peaks) or islocalmin both with appropriate prominence settings to return the deepest valleys. After that, use polyfit on the identified valleys with the appropriate polynomial degree (usually 3) and then polyval on the entire independent variable vector and subtract that result from the signal vector to remove the baseline variation. (I have done this with spectrum signals with good results.) In this instance, the signal will not go below zero if it is performed correctly. That may require some experimentation.
Smoothing the data depends on the result you want. If the data have broadband noise, either wavelet denoising (requires the Wavelet Toolbox) or the sgolayfilt function can help with that. For band-limited noise, use a lowpass or bandpass filter to isolate the signal from the noise. It is always appropriate to use a reference electrode that simply picks up environmental noise. That signal can be subtracted from the other signals using differential amplifiers prior to the ADC stage of your instrumentation. Of course, always use shielded coaxial leads with the shield attached to the instrument ground, and the instrument connected to a true earth ground.
To plot more than one series on the same axes, use the hold function. (The vectors plotted on the same axes do not all have to have the same lengths, although (x,y) pairs in any specific plot call do need to have the same lengths.)
For the peak identification and related statistics, use findpeaks, islocalmax is also an option.
The statistical analyses can be done using the Statistics and Machine Learning Toolbox functions. Note that paired (comparing before-and-after effects on the same subjects after administering a drug, for example) and unpaired (comparing different, although matched, populations with one population undergoing the intervention such as the administration of a drug) comparisons require different functions. A set of tests that only require that the distributions betwen the groups are the same without specifying the distribution are the Wilcoxon ranksum (unpaired) and signrank (paired) tests. There are others. It may be worthwhile to consult with a statistician prior to designing your study to be certain that you have considered the statistical tests you want to do on it.
This is by no means an exhaustive discussion of all the possibilities, however it should get you started.

Community Treasure Hunt

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

Start Hunting!

Translated by