Hi there,
While I recently tried to align Neuralynx data with data simultaneously recorded using a Nihon Kohden system, I stumbled upon the discontinuous data loading error that has previously been reported (#58) and documented (http://www.fieldtriptoolbox.org/faq/discontinuous_neuralynx/).
After further investigation, I found out that the Neuralynx system is saving data as a series of 512-sample batches and that when user hits pause or stop buttons, the recording stops at sample i from the current 512-sample batch, and the remaining samples (i+1 to 512) are a copy of samples i+1 to 512 of the previous batch. These repeated samples are marked as invalid somewhere in the ncs structure.
Besides, in the dataset I explored, I found that all ncs files had the same number of breaks (i.e., of 512-sample batches containing invalid samples), at the same timing, whatever their sampling rate.
Here's a very simple code snippet that loads Neuralynx data as epochs:
% Load Neuralynx data as continuous
cfg = [];
cfg.dataset = 'IRxx/macro/';
dataNLX = ft_preprocessing(cfg);
% Get epoch boundaries from low-level Fieldtrip functions
ncs = read_neuralynx_ncs('IRxx/macro/elec_y.ncs');
idx = find(ncs.NumValidSamp<512);
nValSamp = ncs.NumValidSamp(idx);
nTrials = length(idx);
trl = zeros(nTrials, 3);
trl(:, 2) = ((idx-1)*512 + nValSamp)';
trl(1, 1) = 1;
trl(2:end, 1) = (idx(1:end-1)*512+1)';
% Apply these boundaries to epoch data
cfg = [];
cfg.trl = trl;
dataNLX = ft_redefinetrial(cfg, dataNLX);
Then, each epoch can successfully be aligned with the Nihon Kohden data using cross-correlation (see the following figure; top row shows raw cross-correlation coefficients for each of the four epochs; CS for Clinical System/Nihon Kohden; SU for Single-Unit/Neuralynx system).

This code fixed the issue for me, and it seems more straightforward than the timestamp-based NaN-interpolation strategy. However, I haven't found an obvious way to include it in the current ft_preprocessing / read_neuralynx_ncs implementation yet, so I just wanted to get your feedback first about whether or not you think it worth spending time to create a pull request.
Best,
Ludovic
Hi there,
While I recently tried to align Neuralynx data with data simultaneously recorded using a Nihon Kohden system, I stumbled upon the discontinuous data loading error that has previously been reported (#58) and documented (http://www.fieldtriptoolbox.org/faq/discontinuous_neuralynx/).
After further investigation, I found out that the Neuralynx system is saving data as a series of 512-sample batches and that when user hits pause or stop buttons, the recording stops at sample i from the current 512-sample batch, and the remaining samples (i+1 to 512) are a copy of samples i+1 to 512 of the previous batch. These repeated samples are marked as invalid somewhere in the ncs structure.
Besides, in the dataset I explored, I found that all ncs files had the same number of breaks (i.e., of 512-sample batches containing invalid samples), at the same timing, whatever their sampling rate.
Here's a very simple code snippet that loads Neuralynx data as epochs:
Then, each epoch can successfully be aligned with the Nihon Kohden data using cross-correlation (see the following figure; top row shows raw cross-correlation coefficients for each of the four epochs; CS for Clinical System/Nihon Kohden; SU for Single-Unit/Neuralynx system).
This code fixed the issue for me, and it seems more straightforward than the timestamp-based NaN-interpolation strategy. However, I haven't found an obvious way to include it in the current ft_preprocessing / read_neuralynx_ncs implementation yet, so I just wanted to get your feedback first about whether or not you think it worth spending time to create a pull request.
Best,
Ludovic