<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Peter,
<div class=""><br class="">
</div>
<div class="">Re-referencing can only be done once the channel that will be used as a reference has been read into the matlab workspace. You will need one round of ft_preprocessing for that. It is not a necessary prerequisite to specify the rereferencing upon
 the first call to ft_preprocessing. In your use case, you need to read in the data in a for loop, because of the particular way in which your data is represented (i.e. one channel per file). ft_preprocessing can then be applied to the ‘appended’ data, with
 the reference channel of choice (which in your case will be ‘CSC84’ (without the .ncs I think).</div>
<div class=""><br class="">
</div>
<div class="">Good luck,</div>
<div class=""><br class="">
</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 25 Apr 2023, at 23:06, Peter Kaskan via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;" class="">Thanks for your help Jan-Matijs,</span></div>
<div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<br class="">
</div>
<div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;" class="">I implemented your corrected loop and I am now reading in multiple .csc channels using<br class="">
</span></div>
<div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<i class=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;" class=""><span class="">      </span>alldata = ft_appenddata([], data{:});</span></i><br class="">
</div>
<div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<br class="">
</div>
<div class="elementToProof" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;" class="">I think I read somewhere that one should<span class="Apple-converted-space"> </span></span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; font-weight: 400;" class="">define
 re-referencing before running ft_preprocessing. However, ft_preprocessing occurs within this loop:</span><br class="">
</div>
<div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">
<br class="">
</div>
<div class="ContentPasted1 elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">
<i class="">for k = 1:numel(channellist)</i>
<blockquote style="margin-top: 0px; margin-bottom: 0px;" class="">
<div class="ContentPasted1"><i class="">cfg.dataset = sprintf('%s.ncs',channellist{k});</i></div>
<div class="ContentPasted1"><i class="">data{k} = ft_preprocessing(cfg);</i></div>
</blockquote>
<div class="ContentPasted1"><i class="">end</i></div>
<div class="ContentPasted1"><br class="">
</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.<span class="Apple-converted-space"> </span><br class="">
</div>
<div class="ContentPasted2 ContentPasted1">
<blockquote style="margin-top: 0px; margin-bottom: 0px;" class=""><i class="">cfg.reref = 'yes';</i>
<div class="ContentPasted2"><i class="">cfg.refchannel = 'CSC84.ncs';</i></div>
</blockquote>
<div class="ContentPasted2"><br class="">
</div>
<div class="ContentPasted2">But this construction throws errors:<br class="">
</div>
<div class="ContentPasted2 ContentPasted4">
<blockquote style="margin-top: 0px; margin-bottom: 0px;" class=""><i class="">Error using preproc (line 279)</i>
<div class="ContentPasted4"><i class="">reference channel was not found</i></div>
<div class=""><i class=""><br class="ContentPasted4">
</i></div>
<div class="ContentPasted4"><i class="">Error in ft_preprocessing (line 599)</i></div>
<div class="ContentPasted4"><i class="">      [cutdat{i}, label, time{i}, cfg] = preproc(dat, hdr.label(rawindx),</i></div>
<div class="ContentPasted4"><i class="">      tim, cfg, begpadding, endpadding);</i></div>
</blockquote>
</div>
<div class="ContentPasted2 ContentPasted4"><br class="">
</div>
<div class="ContentPasted2">Any guidance you can provide?</div>
<div class="ContentPasted2"><br class="">
</div>
<div class="ContentPasted2">Thank you!<br class="">
</div>
<br class="">
</div>
<br class="">
</div>
</div>
<div class="BodyFragment" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<font size="2" class=""><span style="font-size: 11pt;" class="">
<div class="PlainText elementToProof"><br class="">
------------------------------<br class="">
<br class="">
Message: 2<br class="">
Date: Tue, 11 Apr 2023 20:30:18 +0000<br class="">
From: Peter Kaskan <<a href="mailto:peter.kaskan@einsteinmed.edu" class="">peter.kaskan@einsteinmed.edu</a>><br class="">
To: "<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>" <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>><br class="">
Subject: Re: [FieldTrip] fieldtrip Digest, Vol 148, Issue 24<br class="">
<br class="">
Hello Jan-Mathijs,<br class="">
<br class="">
Thanks for the reply; I was traveling and just got back to this...<br class="">
<br class="">
In my initial, very rudimentary preprocessing script, cfg.dataset will take a single neuralynx file:<br class="">
<br class="">
      cfg.dataset = 'CSC4.ncs';<br class="">
            cfg.continuous = 'yes';<br class="">
            highpass, lowlass, demean, detrend etc..<br class="">
            filtContData = ft_preprocessing(cfg);<br class="">
<br class="">
But the question was how to reference one channel with another.<br class="">
<br class="">
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 class="">
<br class="">
However, my initial attempt left some errors related to<br class="">
Error using ft_checkconfig (line 163)<br class="">
The field cfg.datafile is required<br class="">
The field cfg.headerfile is required<br class="">
<br class="">
Error in ft_preprocessing (line 385)<br class="">
      cfg = ft_checkconfig(cfg, 'required',   {'headerfile', 'datafile'});<br class="">
After digging a little further in ft_preprocessing lines 446-447<br class="">
<br class="">
% translate the channel groups (like 'all' and 'MEG') into real labels<br class="">
<br class="">
  cfg.channel = ft_channelselection(cfg.channel, hdr);<br class="">
<br class="">
  assert(~isempty(cfg.channel), 'the selection of channels is empty');<br class="">
<br class="">
... we rescued the error by resetting<br class="">
<br class="">
cfg.channel = CSC1.ncs;<br class="">
<br class="">
Do you know what is happening? If we use: channellist = {'CSC1.ncs'; 'CSC2.ncs'; 'CSC3.ncs'}<br class="">
<br class="">
does the cfg.datafile and cfg.headerfile need to be defined some other way?<br class="">
<br class="">
<br class="">
Thanks, Peter<br class="">
<br class="">
<br class="">
<br class="">
________________________________<br class="">
From: fieldtrip <<a href="mailto:fieldtrip-bounces@science.ru.nl" class="">fieldtrip-bounces@science.ru.nl</a>> on behalf of<span class="Apple-converted-space"> </span><a href="mailto:fieldtrip-request@science.ru.nl" class="">fieldtrip-request@science.ru.nl</a><span class="Apple-converted-space"> </span><<a href="mailto:fieldtrip-request@science.ru.nl" class="">fieldtrip-request@science.ru.nl</a>><br class="">
Sent: Monday, March 27, 2023 6:00 AM<br class="">
<br class="">
Hi Peter,<br class="">
<br class="">
ft_read_data is a so-called ‘intermediate’ level fieldtrip function and not typically called directly by the casual user.<br class="">
<br class="">
I think your use case calls for the following strategy:<br class="">
<br class="">
channellist = {‘channel1’;’channel2’;…’channelN’};<br class="">
for k = 1:numel(channellist)<br class="">
   cfg.channel = channellist{k}; % or something equivalent, at least instructing the reading function to grab a channel specific file<br class="">
   data{k} = ft_preprocessing(cfg);<br class="">
end<br class="">
<br class="">
alldata = ft_appenddata([], data{:});<br class="">
<br class="">
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 class="">
<br class="">
Best wishes,<br class="">
<br class="">
Jan-Mathijs<br class="">
<br class="">
<br class="">
<br class="">
On 23 Mar 2023, at 22:12, Peter Kaskan via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a><<a href="mailto:fieldtrip@science.ru.nl" class="">mailto:fieldtrip@science.ru.nl</a>>> wrote:<br class="">
<br class="">
Hello,<br class="">
<br class="">
I am writing a ft_preprocessing script; I can give it channel1.csc and proceed with filtering, defining trials etc.<br class="">
<br class="">
...but, how do I re-reference to another channel?<br class="">
<br class="">
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 class="">
<br class="">
Or do I need to create a montage, and how do I do that with n #s of separate neuralynx.csc channels?<br class="">
<br class="">
<br class="">
<br class="">
Thanks - Peter<br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 3<br class="">
Date: Wed, 12 Apr 2023 06:30:21 +0000<br class="">
From: "Schoffelen, J.M. (Jan Mathijs)"<br class="">
        <<a href="mailto:janmathijs.schoffelen@donders.ru.nl" class="">janmathijs.schoffelen@donders.ru.nl</a>><br class="">
<br class="">
Hi Peter,<br class="">
<br class="">
Apologies, I was a bit sloppy in my earlier code snippet. I think it should have read something like this<br class="">
<br class="">
channellist = {‘channel1’;’channel2’;…’channelN’};<br class="">
<br class="">
cfg = [];<br class="">
cfg.<someoptionsfor filtering etc><br class="">
for k = 1:numel(channellist)<br class="">
   %% NOT THIS: cfg.channel = channellist{k}; % or something equivalent, at least instructing the reading function to grab a channel specific file<br class="">
   cfg.dataset = sprintf(‘%s.ncs’,channellist{k});<br class="">
   data{k} = ft_preprocessing(cfg);<br class="">
end<br class="">
<br class="">
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 class="">
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 class="">
<br class="">
I hope that this helps to get you on your way.<br class="">
<br class="">
Good luck,<br class="">
Jan-Mathijs<br class="">
</div>
</span></font></div>
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">fieldtrip
 mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!8VkSVyWbeCmfBJiAtBB12ouWee--iAf4--1ZgohZyMP23AdtlAZbqHCY_eLiftS64yKk9nEy1Yt01h28F4J2m9v3ZwcSO0LI7wq-DQ$" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!8VkSVyWbeCmfBJiAtBB12ouWee--iAf4--1ZgohZyMP23AdtlAZbqHCY_eLiftS64yKk9nEy1Yt01h28F4J2m9v3ZwcSO0LI7wq-DQ$</a><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span></div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>