# How to stitch epoched data back into continuous raw data ?

**URL:** <https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156>\
**Category:** Support & Discussions\
**Tags:** preprocessing, eeg, visualization, evoked, ica\
**Created:** [January 16, 2024, 2:35pm UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156 "2024-01-16T14:35:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumit\_Yempalle](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Sumit\_Yempalle](https://mne.discourse.group/u/Sumit_Yempalle)\
**Post date:** [January 16, 2024, 2:35pm UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156/1 "2024-01-16T14:35:03Z")

</div>

Hello,

I am analyzing a continuous eeg data, I am not looking for a particular event based response (e.g. ERP stimulus), but rather something ike sleep analysis.

I have followed the following steps till now :

1. Import the raw signal
2. Apply a bandpass filter
3. Using the interactive plot of mne library, manually annotate bad portions of the signal by labelling them ‘bad\_signals’
4. Create an events array to epoch the continuous signal into equal length epochs
5. Compute ICA on the epoched data
6. Reject the unwanted components and then apply the ica object to the raw data to clean artifacts

I wish to calculate the PSD of the cleaned data. However, I am confused if I should stitch the epoched signal back into continuous signal to compute the PSD.

I tried to use the mne.concatenate\_epochs() method and stored the result into a raw object. But when I plot it, I can still see the epochs. How do I get a continuous signal without any annotations now ?

Any help regarding this will be very useful! Thanks!

---

<div class="post-metadata">

**Author:** ![jstout211](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jstout211/32/180_2.png) [@jstout211](https://mne.discourse.group/u/jstout211)\
**Post date:** [January 16, 2024, 5:08pm UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156/2 "2024-01-16T17:08:32Z")

</div>

If you apply your ica object (fit on epochs - ica.fit(epo) ) to the raw data (ica.apply(raw)) - this will give you your continuous data back.

If you try to stitch back together epochs, you will have jump discontinuities. The “bad\_signals” annotations will be dropped from your epochs - so you will have a jump at the borders of the missing epoch. Also when creating epochs, there is a default prestim DC offset - which will cause jump discontinuities in your stitched back together data. The timing may also be off if you reject one or more epochs.

-Jeff

---

<div class="post-metadata">

**Author:** ![jstout211](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jstout211/32/180_2.png) [@jstout211](https://mne.discourse.group/u/jstout211)\
**Post date:** [January 16, 2024, 5:10pm UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156/3 "2024-01-16T17:10:24Z")

</div>

Also - there is a way to get a PSD from epochs: [The Spectrum and EpochsSpectrum classes: frequency-domain data — MNE 1.6.1 documentation](https://mne.tools/stable/auto_tutorials/time-freq/10_spectrum_class.html#sphx-glr-auto-tutorials-time-freq-10-spectrum-class-py)

---

<div class="post-metadata">

**Author:** ![Sumit\_Yempalle](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Sumit\_Yempalle](https://mne.discourse.group/u/Sumit_Yempalle)\
**Post date:** [January 17, 2024, 11:08am UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156/4 "2024-01-17T11:08:44Z")

</div>

Hi Jeff,

Thanks for the suggestion! My raw data has some very large amplitude artefacts caused due to head movements, which I have decided to ignore in my analysis. Hence I annotated those portions and proceeded ahead with the ICA.

If I apply ica object (fit on epochs - ica.fit(epo) ) to the raw data (ica.apply(raw)) , I am unable to remove those large head movement artefacts. However, if I pass the annotated signal into ica.apply(annotated), will it automatically reject the bad signal parts ?

Could you suggest a suitable approach ?

---

<div class="post-metadata">

**Author:** ![Sumit\_Yempalle](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Sumit\_Yempalle](https://mne.discourse.group/u/Sumit_Yempalle)\
**Post date:** [January 17, 2024, 11:09am UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156/5 "2024-01-17T11:09:06Z")

</div>

Great! Shall check this out! Thanks!

---

<div class="post-metadata">

**Author:** ![Sumit\_Yempalle](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Sumit\_Yempalle](https://mne.discourse.group/u/Sumit_Yempalle)\
**Post date:** [January 17, 2024, 11:11am UTC](https://mne.discourse.group/t/how-to-stitch-epoched-data-back-into-continuous-raw-data/8156/6 "2024-01-17T11:11:41Z")

</div>

In order to create a good ICA decomposition, I used ‘reject\_by\_annotation = True’ while fitting the epoched raw data that has the bad-signal annotations.
