<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Dear Stephen,</p>
<p><br>
</p>
<p>Thanks very much for the input! I am now padding with NANs and think this is indeed a good solution. Robert Oostenveld also very helpfully pointed out that if I run ft_definetrial and have trials with empty samples, running ft_redefinetrial directly after would
 actually automatically fill those empty samples with NANs because of how it reads data, so I also didn't have to manually modify my raw data.</p>
<p><br>
</p>
<p>Thanks everyone for the help!<br>
</p>
<p><br>
</p>
<p>Best wishes,<br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">Emma Ward, MSc </div>
<div style="font-family:Tahoma; font-size:13px">PhD Candidate</div>
<div style="font-family:Tahoma; font-size:13px">Donders Centre for Cognition, Radboud University</div>
<div style="font-family:Tahoma; font-size:13px"><br>
</div>
<div style="font-family:Tahoma; font-size:13px">e-mail: e.ward@donders.ru.nl</div>
<div style="font-family:Tahoma; font-size:13px">website: <a href="https://sites.google.com/view/emma-k-ward" id="NoLP">https://sites.google.com/view/emma-k-ward</a></div>
</div>
</div>
</div>
</div>
<div style="color: rgb(33, 33, 33);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> fieldtrip <fieldtrip-bounces@science.ru.nl> on behalf of Stephen Whitmarsh <stephen.whitmarsh@gmail.com><br>
<b>Sent:</b> 10 September 2020 19:54<br>
<b>To:</b> FieldTrip discussion list<br>
<b>Subject:</b> Re: [FieldTrip] Padding before start of recorded data</font>
<div> </div>
</div>
<div>
<div dir="ltr">Dear Emma,
<div><br>
</div>
<div>Concerning the practicalities, i.e. your second question, I think that does just require a simple manual hack of the data, as that data doesn't exist and ft_preprocessing will add zero's/mirrored data for you. As you suggest, you could add the data after
 you do the trial segmentation (i.e. ft_preprocessing / ft_redefinetrials), making sure you add to both the data.trial{n} and data.time{n} field. It would just be once early in your pipeline, so not too much of a hassle I think.</div>
<div><br>
</div>
<div>However, my opinion on the 'legitimacy' of adding zero's or mirroring the data would be negative, however. This data you want to add does not exist in reality, and by mirroring the data, or padding with zeros you are creating artificial data that will
 bleed into the analyses of your baseline. You simply can't claim an estimate of power where you don't have real data. </div>
<div><br>
</div>
<div>My 2 cents would be to try to:</div>
<div>1) add nan's instead of zero's or mirroring, so that subsequent wavelet/mtmconvol frequency analsises will return nan's when estimating power using those timepoints.</div>
<div>2) to deal with filter ringing you can try to demean or detrend your data first, or apply a taper, but keep in mind that detrending could create some subtle effects on slow ERP components. Just take a good look at the effects it has on the raw data and
 ERPs, as it might not even be necessary to go to too much length for two trials.</div>
<div>This way you might be able to salvage as much as possible the baseline, by using e.g. only the second half of the baseline?</div>
<div><br>
</div>
<div>I hope this helps,</div>
<div>Stephen</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Op do 10 sep. 2020 om 19:13 schreef Ward, E.G.E. (Emma) <<a href="mailto:e.ward@psych.ru.nl">e.ward@psych.ru.nl</a>>:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Dear mailing list,<br>
</p>
<p><br>
</p>
<p>I am currently preparing infant EEG data for a wavelet analysis, specifically to look at gamma and theta, and have a question about trial length and padding.<br>
</p>
<p><br>
</p>
<p>I have 0.5s baseline followed by 2s trials in which the stimulus is present onscreen. We were planning to define trials that are extra long, that is, with one second of true data before the baseline period and one second of true data after the stimulus offset,
 in order to avoid edge artifacts in filtering and wavelet analysis. (This in addition to more mirror padding for the wavelet transform step itself.) <span style="font-size:12pt">But, I have one or two participants for whom the beginning of the first
</span><span style="font-size:12pt">stimulus </span><span style="font-size:12pt">is too close to the beginning of the recording, with no space for the extra second in front of the baseline period.</span></p>
<p><br>
</p>
<p>Because this is infant data and we don't have so many trials, I would like to avoid losing the first trial in these cases, if possible. I am therefore thinking about a solution in which, only for infants whose first trial was too close to the beginning of
 the recording, I do some kind of additional padding at the beginning of the first trial. <br>
</p>
<p><br>
</p>
<p>My questions are:</p>
<p><br>
</p>
<p>1) is this a legitimate and useful approach? The extra time being cut is really just data padding anyway, but for these one or two infants the padding method would then be different (perhaps taking the first sample of the first trial and filling back to
 the desired length, or mirroring the pre-stimulus data we do have, or something else if someone has a suggestion).
<br>
</p>
<p><br>
</p>
<p>2) if this approach is indeed legitimate and useful, how could I best go about it? My ft_definetrial is currently happily defining trials with begin samples before 0, it's only when I get to my ft_preprocessing step that I get an error for the participant
 with not enough data, but I don't yet see an easy way to incorporate this adjustment into the preprocessing, whereas in my trialfun I'm already looping over trials to make the trl matrix, and can include a "if trialBeginSample < 0..." type statement.<br>
</p>
<p><br>
</p>
<p>It is of course also entirely possible that defining extra-long trials is for some reason less advisable than padding using cfg.pad and cfg.padding during my other steps, so if that's the case I'm also happy to hear it.<br>
</p>
<p><br>
</p>
<p>Thanks for any suggestions or thoughts you might have!<br>
</p>
<p><br>
</p>
<p>Best wishes,<br>
</p>
<p><br>
</p>
<div id="gmail-m_2015864465848421771Signature">
<div name="divtagdefaultwrapper">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">Emma Ward, MSc </div>
<div style="font-family:Tahoma; font-size:13px">Postdoctoral researcher, FU Berlin<br>
</div>
<div style="font-family:Tahoma; font-size:13px">e-mail: <a href="mailto:e.ward@donders.ru.nl" target="_blank">
e.ward@donders.ru.nl</a> (will soon change)<br>
</div>
<div style="font-family:Tahoma; font-size:13px">website: <a href="https://sites.google.com/view/emma-k-ward" id="gmail-m_2015864465848421771NoLP" target="_blank">https://sites.google.com/view/emma-k-ward</a></div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202" rel="noreferrer" target="_blank">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
</blockquote>
</div>
</div>
</div>
</body>
</html>