SAND-Lab / MEA-NAP

MEA-NAP. A streamlined diagnostic and analytic tool for data obtained using microelectrode arrays.
GNU General Public License v3.0
12 stars 6 forks source link

Filter parameters and spike dection #54

Closed wxc1234567891111111 closed 1 week ago

wxc1234567891111111 commented 2 weeks ago

Hello, when I was importing data into the pipeline for analysis, I was wondering if the code would filter the original signal and what the filter parameters were, but I couldn't find the code for this part. At the same time, I also want to know how the code calculates the specific threshold of the signal and how to determine whether a spike has exceeded the threshold. So I want to know which function code corresponds to the above two parts.

Timothysit commented 2 weeks ago

Hi, sorry for the late response. The code for spike detection in general can be found here: https://github.com/SAND-Lab/MEA-NAP/blob/be1a6729821976fa5f1371769d1357044c472560/Functions/WATERS-master/detectSpikesCWT.m

From line 89 - 94, you can find the filter used to process the original signal:

lowpass = filterLowPass;  
highpass = filterHighPass; 
wn = [lowpass highpass] / (fs / 2);
filterOrder = 3;
[b, a] = butter(filterOrder, wn);
trace = filtfilt(b, a, double(data));

The low pass is generally 600 Hz and the high pass is 8000 Hz if you record with a 25 kHz sampling rate, and set to 6150 Hz if you record with a 12.5 kHz sampling rate. But both of these default values can be changed in the GUI.

The threshold detection code is here: https://github.com/SAND-Lab/MEA-NAP/blob/be1a6729821976fa5f1371769d1357044c472560/Functions/WATERS-master/detectSpikesThreshold.m#L58

In brief, the user provides the multiplier value from the GUI / in the script, and the threshold value is:

threshold = m - multiplier*s;

where m is the median of the filtered signal (so should be zero) and s is the median absolute deviation of the signal.

Let me know if there are some questions left! Or I will close this issue if you are happy with the answer.

wxc1234567891111111 commented 1 week ago

Thank you for your answer. It has been very helpful to me and I understand this part of the code

Timothysit commented 1 week ago

No worries! Please ask more questions if you have them :) I will close this issue now.