# Simple way of averaging evoked responses over	channels?

**URL:** <https://mne.discourse.group/t/simple-way-of-averaging-evoked-responses-over-channels/598>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [July 13, 2013, 4:58pm UTC](https://mne.discourse.group/t/simple-way-of-averaging-evoked-responses-over-channels/598 "2013-07-13T16:58:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [July 13, 2013, 4:58pm UTC](https://mne.discourse.group/t/simple-way-of-averaging-evoked-responses-over-channels/598/1 "2013-07-13T16:58:57Z")

</div>

Hi,

I have a collection of epochs for a single type of event, and I've been  
using this script here to average and visualize them:

[http://martinos.org/mne/auto\_examples/plot\_topo\_compare\_conditions.html](http://martinos.org/mne/auto_examples/plot_topo_compare_conditions.html)

Now I'm trying to average the responses over the gradiometer channels of  
a given lobe (left temporal, right temporal etc.) with roughly the  
following algorithm:

1. For each pair of gradiometer channels in the lobe: sum the vectors  
(Take data for single channel of the pair, rise it to the power of 2, do  
the same for the data of the other channel in the pair. Sum the previous  
values and take a square root of them).

2. Average the data received in step 1.

3. Vizualize the result as a single graph.

I didn't find a straightforward example about this in the docs, so I'm  
trying to code something to make it work. However, the problems are the  
following:

- How do you get the channel data to average in step 1? Specifically,  
how do you get the data for a specific gradiometer channel? For example,  
if I know I need to get the data for gradiometer channel 0222, how can  
it be done?

- If you need the data for the paired gradiometer channel of the channel  
x (in case of the channel 0222 this would probably be 0223), how do you  
get it? How do the indexes in evoked.data actually work in this regard?

Currently I have the following code. ChannelList is a list of all  
channels in a lobe, from which the gradiometer channels are then  
separated. The format of the channelList is  
['0223','0222','0212','0213','0133', ...etc.].

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;evoked = epoch.average()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Get all the channels names in evoked  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch\_names = evoked[0].ch\_names  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch\_names = \_clean\_names(ch\_names)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Check that the channels we want to show actually are in the  
evoked  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# channel list  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;channelListSet = set(channelList)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch\_namesSet = set(ch\_names)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;channelsToAverage = channelListSet.intersection(ch\_namesSet)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Get only the gradiometer channels  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;channelsToAverageGrad = None  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for a in channelsToAverage:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (a[-1] == 2 or a[-1] == 3):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;channelsToAverageGrad.append(a)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;averagedFinal = None  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# TODO Get index from channel names, to get the data from evoked.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Then do the actual vector summing and averaging  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for chname in channelsToAverageGrad:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch\_idx = ch\_names.index(chname)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;evoked.data[ch\_idx:(ch\_idx+1),:]
