<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;">Thanks for your help Jan-Matijs,</span></div>
<div><br>
</div>
<div class="elementToProof"><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;">I implemented your corrected loop and I am now reading in multiple .csc channels using<br>
</span></div>
<div class="elementToProof"><i><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;"><span>      </span>alldata = ft_appenddata([], data{:});</span></i><br>
</div>
<div><br>
</div>
<div class="elementToProof"><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;">I think I read somewhere that one should
</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;">define re-referencing before running ft_preprocessing. However, ft_preprocessing occurs within this loop:</span><br>
</div>
<div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof ContentPasted1" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i>for k = 1:numel(channellist)</i>
<blockquote style="margin-top:0;margin-bottom:0">
<div class="ContentPasted1"><i>cfg.dataset = sprintf('%s.ncs',channellist{k});</i></div>
<div class="ContentPasted1"><i>data{k} = ft_preprocessing(cfg);</i></div>
</blockquote>
<div class="ContentPasted1"><i>end</i></div>
<div class="ContentPasted1"><br>
</div>
<div class="ContentPasted1 ContentPasted3">It seems like I should insert this in the loop (above, before ft_preprocessing), because I want to use channel 84 as a reference for each channel.
<br>
</div>
<div class="ContentPasted1 ContentPasted2">
<blockquote style="margin-top:0;margin-bottom:0"><i>cfg.reref = 'yes';</i>
<div class="ContentPasted2"><i>cfg.refchannel = 'CSC84.ncs';</i></div>
</blockquote>
<div class="ContentPasted2"><br>
</div>
<div class="ContentPasted2">But this construction throws errors:<br>
</div>
<div class="ContentPasted2 ContentPasted4">
<blockquote style="margin-top:0;margin-bottom:0"><i>Error using preproc (line 279)</i>
<div class="ContentPasted4"><i>reference channel was not found</i></div>
<div><i><br class="ContentPasted4">
</i></div>
<div class="ContentPasted4"><i>Error in ft_preprocessing (line 599)</i></div>
<div class="ContentPasted4"><i>      [cutdat{i}, label, time{i}, cfg] = preproc(dat, hdr.label(rawindx),</i></div>
<div class="ContentPasted4"><i>      tim, cfg, begpadding, endpadding);</i></div>
</blockquote>
</div>
<div class="ContentPasted2 ContentPasted4"><br>
</div>
<div class="ContentPasted2">Any guidance you can provide?</div>
<div class="ContentPasted2"><br>
</div>
<div class="ContentPasted2">Thank you!<br>
</div>
<br>
</div>
<br>
</div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof"><br>
------------------------------<br>
<br>
Message: 2<br>
Date: Tue, 11 Apr 2023 20:30:18 +0000<br>
From: Peter Kaskan <peter.kaskan@einsteinmed.edu><br>
To: "fieldtrip@science.ru.nl" <fieldtrip@science.ru.nl><br>
Subject: Re: [FieldTrip] fieldtrip Digest, Vol 148, Issue 24<br>
<br>
Hello Jan-Mathijs,<br>
<br>
Thanks for the reply; I was traveling and just got back to this...<br>
<br>
In my initial, very rudimentary preprocessing script, cfg.dataset will take a single neuralynx file:<br>
<br>
      cfg.dataset = 'CSC4.ncs';<br>
            cfg.continuous = 'yes';<br>
            highpass, lowlass, demean, detrend etc..<br>
            filtContData = ft_preprocessing(cfg);<br>
<br>
But the question was how to reference one channel with another.<br>
<br>
I have been trying to implement your channellist and appenddata suggestion as you describe (below) using channellist = {'CSC1.ncs'; 'CSC2.ncs'; 'CSC3.ncs'} and the subsequent data loop.<br>
<br>
However, my initial attempt left some errors related to<br>
Error using ft_checkconfig (line 163)<br>
The field cfg.datafile is required<br>
The field cfg.headerfile is required<br>
<br>
Error in ft_preprocessing (line 385)<br>
      cfg = ft_checkconfig(cfg, 'required',   {'headerfile', 'datafile'});<br>
After digging a little further in ft_preprocessing lines 446-447<br>
<br>
% translate the channel groups (like 'all' and 'MEG') into real labels<br>
<br>
  cfg.channel = ft_channelselection(cfg.channel, hdr);<br>
<br>
  assert(~isempty(cfg.channel), 'the selection of channels is empty');<br>
<br>
... we rescued the error by resetting<br>
<br>
cfg.channel = CSC1.ncs;<br>
<br>
Do you know what is happening? If we use: channellist = {'CSC1.ncs'; 'CSC2.ncs'; 'CSC3.ncs'}<br>
<br>
does the cfg.datafile and cfg.headerfile need to be defined some other way?<br>
<br>
<br>
Thanks, Peter<br>
<br>
<br>
<br>
________________________________<br>
From: fieldtrip <fieldtrip-bounces@science.ru.nl> on behalf of fieldtrip-request@science.ru.nl <fieldtrip-request@science.ru.nl><br>
Sent: Monday, March 27, 2023 6:00 AM<br>
<br>
Hi Peter,<br>
<br>
ft_read_data is a so-called ‘intermediate’ level fieldtrip function and not typically called directly by the casual user.<br>
<br>
I think your use case calls for the following strategy:<br>
<br>
channellist = {‘channel1’;’channel2’;…’channelN’};<br>
for k = 1:numel(channellist)<br>
   cfg.channel = channellist{k}; % or something equivalent, at least instructing the reading function to grab a channel specific file<br>
   data{k} = ft_preprocessing(cfg);<br>
end<br>
<br>
alldata = ft_appenddata([], data{:});<br>
<br>
Once you have the alldata object, you can apply re-referencing. Perhaps indeed this is best done by creating a ‘montage’, and apply it to the data.<br>
<br>
Best wishes,<br>
<br>
Jan-Mathijs<br>
<br>
<br>
<br>
On 23 Mar 2023, at 22:12, Peter Kaskan via fieldtrip <fieldtrip@science.ru.nl<mailto:fieldtrip@science.ru.nl>> wrote:<br>
<br>
Hello,<br>
<br>
I am writing a ft_preprocessing script; I can give it channel1.csc and proceed with filtering, defining trials etc.<br>
<br>
...but, how do I re-reference to another channel?<br>
<br>
Is there a way to use ft_read_data to create a structure with all channels, and then tell it what channel I want to use as a reference?<br>
<br>
Or do I need to create a montage, and how do I do that with n #s of separate neuralynx.csc channels?<br>
<br>
<br>
<br>
Thanks - Peter<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Wed, 12 Apr 2023 06:30:21 +0000<br>
From: "Schoffelen, J.M. (Jan Mathijs)"<br>
        <janmathijs.schoffelen@donders.ru.nl><br>
<br>
Hi Peter,<br>
<br>
Apologies, I was a bit sloppy in my earlier code snippet. I think it should have read something like this<br>
<br>
channellist = {‘channel1’;’channel2’;…’channelN’};<br>
<br>
cfg = [];<br>
cfg.<someoptionsfor filtering etc><br>
for k = 1:numel(channellist)<br>
   %% NOT THIS: cfg.channel = channellist{k}; % or something equivalent, at least instructing the reading function to grab a channel specific file<br>
   cfg.dataset = sprintf(‘%s.ncs’,channellist{k});<br>
   data{k} = ft_preprocessing(cfg);<br>
end<br>
<br>
If each channel is represented as a single file, ft_preprocessing needs to be instructed in each iteration of the loop with a fresh cfg.dataset<br>
Once you have ‘appended’ the channels through ft_appenddata (note that this requires each of the channels' data structures to have the same number of samples) , you should be able to re-reference.<br>
<br>
I hope that this helps to get you on your way.<br>
<br>
Good luck,<br>
Jan-Mathijs<br>
</div>
</span></font></div>
</body>
</html>