csn-le / wave_clus

A fast and unsupervised algorithm for spike detection and sorting using wavelets and super-paramagnetic clustering
127 stars 66 forks source link

Optimizing parameters for 12kHz recording #224

Open Zahra-Jourahmad opened 2 years ago

Zahra-Jourahmad commented 2 years ago

Hi Fernando,

Thanks a lo for the great software. I am trying to use wave_clus to detect spikes recorded from STN (a nucleus in the deep part of the brain ) during DBS surgery. The main problem that I have encountered currently is misalignment in detected clusters. I have attached the picture for a single channel as well as the parameters. Looking forward to hearing your valuable suggestions.

Thanks, Zahra STN-spike

I used default parameters except for the parameters below:

params = struct; params.detection = 'neg'; %params.detection = 'pos'; params.stdmin =3; params.stdmax =10; params.min_clus =50; params.max_clus=10; params.randomseed=1; params.mintemp=0.18; params.maxtemp=0.30; params.w_pre=30; params.w_post=44; params.template_sdnum=2.5; params.alignment_window = 5;

ferchaure commented 2 years ago

Hi Zahra, what do you mean with misalignment?

Could you tell me the sampling rate? (that neurons look really fast). I would reduce the total length of the spike to 32 samples

Zahra-Jourahmad commented 2 years ago

Thank you, Fernando. The sr=12k and we are recording from STN while patient is doing a speech task. Does the clusters and parameters (changed compared to default) look Ok to you?

What I wanted to point by misalignment, is the thickness of colored part around the detected spike (could be noise due to low stdmin) and how to resolve this issue (aside from increasing stdmin)?

Thank you

ferchaure commented 2 years ago

Thank you, Fernando. The sr=12k and we are recording from STN while patient is doing a speech task. Does the clusters and parameters (changed compared to default) look Ok to you?

The default parameters are for 30kHZ... then you have to cut in half the default w_pre and w_post.

What I wanted to point by misalignment, is the thickness of colored part around the detected spike (could be noise due to low stdmin) and how to resolve this issue (aside from increasing stdmin)?

That are just spikes/noise really close to the detected one, reducing the length of the spike will help. With the current parameters each "spike" is around ~6 ms long... the probability of having some other spike in that time window is high, and with a lot of that additional spikes "photobombing" your time window got that effect.

I will change the name of the issue, otherwise could generate some confusion.

Zahra-Jourahmad commented 2 years ago

Thanks. So changing the value of w_pre to 10 and w_post to 22 are the only parameters that I should modify? Also could you please help me understand what does params.alignment_window parameter do?

ferchaure commented 2 years ago

I would change par.alignment_window as well. Is the amount of samples it seach for a peak after a threshold crossing

Zahra-Jourahmad commented 2 years ago

I appreciate your prompt response. Are the parameters that I mentioned in the beginning, the only parameters worth changing? or do you think there is still room to change other parameters to get better results?

Zahra-Jourahmad commented 2 years ago

I want to draw your attention to cluster after making changes. I'm not sure if it was helpful. I appreciate your valuable comments. STN-spike2

Parameters: sr=12000; params.detection = 'neg'; params.stdmin =5; params.stdmax =10; params.min_clus =50; %params.max_clus=10; params.randomseed=0; params.mintemp=0; params.maxtemp=0.20; params.w_pre=10; params.w_post=22; params.template_sdnum=2.5; params.alignment_window = 5;

ferchaure commented 2 years ago

I'm a bit intrigue why you change the values of:

params.stdmax =10; I think your are safe, but usually is better to detect artefacts and remove that cluster latter, than maybe discard a high amplitude spike

params.max_clus=10; This is not a parameter any more

params.min_clus =50; Did you find a lot of clusters before? maybe it was related to the extra large time window. I didn't explore the relationship between this and sampling rate but it look a bit high

params.mintemp=0.18; It could save you time, but could happen that a clusters appears for a few temperatures and break really fast. It always safer to keep it equal to 0

Any way, handle my opinions with tweezers (Spanish phrase meaning: they could be really wrong). Spike sorting is made with at least a sampling rate of 25 kHz nowadays, any parameter could respond a bit oddly.

Zahra-Jourahmad commented 2 years ago

Thanks a lot Fernando. I know that the sampling rate for the raw data was 48k, I down sample it to 12k. In this case don't suggest to resample data? or down sample it to 30k? correct?

ferchaure commented 2 years ago

Interesting question, I would say resampling to 30kHz will be perfect (mainly because the default values of the algorithms are set for that case). Or at least to 24k that will be good enough and less problematic.

If you are down-sampling manually, remember to low pass the signal up to the new nyquist frequency before.

Zahra-Jourahmad commented 2 years ago

Thanks a lot Fernando for your great support. I will update my new results here soon.