<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Thanks Michael and Yuval,<br>
    <br>
    That clarify the theoretical points.<br>
    Clearly the point 2 and 3 of my original message would give the same
    results.<br>
    <br>
    Jean-Michel<br>
    <br>
    Le 24/03/11 16:58, Yuval Harpaz a écrit :
    <blockquote
      cite="mid:AANLkTikXcO_O9Oh1q3sB9F=SZn+sdj9CL=bF9SNhdctk@mail.gmail.com"
      type="cite">
      <div dir="ltr">Thanks Michael for the detailed explanation. sorry
        for misunderstanding you before, making you work hard to explain
        yourself.<br>
        thanks again, yuval<br>
        <br>
        <div class="gmail_quote">On 24 March 2011 16:24, Michael Wibral
          <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:michael.wibral@web.de">michael.wibral@web.de</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">
            <div>
              <div style="min-height: 200px;">Dear Yuval,<br>
                <br>
                 you are completely right with what you wrote but you
                might have misunderstood my post (as I say exactly the
                same):<br>
                <br>
                What I wrote is exactly this: concatenation of trials
                followed by cov computation or trial wise cov
                computation followed by averaging is the same, BUT
                different from averaging and then computing cov (just as
                you point out).<br>
                <br>
                Also note that i did NOT write that cov computation is
                linear BUT bi-linear (see also the wikipedia article on
                covariance), hence you have to honor distributivity in
                both arguments (and since you average both arguments,
                that's were the problem comes in!).<br>
                <br>
                Let's denote cov computation by C<.|.>, then<br>
                <br>
                (1a)    C<a+b|c>=(C<a|c> + C<b|c> )  
                   (this is  linearity in first argument)<br>
                (1b)    C<a+b|c+d>=(C<a|c> + C<b|c> +
                C<a|d> + C<b|d> )     (this is  bi-linearity
                when considering both arguments)<br>
                <br>
                concatenating signal vectors a, b and c,d into …[a b]
                and [c d] means:<br>
                (1c) C<[a b]|[c d]> = (C<a|c> + C<b|d>
                )   <br>
                <br>
                For numerical factors 1/m, 1/n as they arise in
                averaging the following holds:<br>
                C<1/m*a| 1/n*b> =1/m*1/m*C<a|b><br>
                <br>
                <br>
                (i.e. concatenation or single trial cov computation and
                later averaging are the same. This is because the dot
                product that is used to compute the covariance for two
                signals vectors reads like this: [a b c d] * [e f g
                h]=ae+bf+cg+dh=[a b] * [e f] + [c d]*[gh], so whether
                you multiply the vectors in pieces and later add results
                or rather multiply them as a whole doesn't matter. What
                matters is that a, b, ... stay exactly the same in both
                cases)<br>
                <br>
                <br>
                Now to trial averging and cov computation (see 3) versus
                cov computation and averaging afterwards (see 4):<br>
                <br>
                for two trials a,b and two channels c1,c2:<br>
                <br>
                (4)   
                C<AVG(c1a|c1b)|AVG(c2a,c2b)>=1/2*1/2*(C<c1a|c2a>+C<c1b|c2b>+C<c1a|c2b>+C<c1b|c2a>)
                   (here things get multiplied across trials, the two
                factors 1/2 come from each separate averaging in the
                first and second argument)<br>
                (5)    AVG(C<c1a|c2a>,C<c1b|c2b>) 
                =1/2*(C<c1a|c2a>+C<c1b|c2b>)  (here things
                do only get multiplied within trials, we have only the
                outer averaging, hence only a factor of 1/2)<br>
                <br>
                Michael<br>
                <br>
                <br>
                <span style="font-size: 9pt;"><span style="font-family:
                    verdana,geneva;"><span style="background-color:
                      transparent;"><span style="color: rgb(0, 0, 0);"><span
                          style="color: rgb(0, 0, 0);"></span></span></span></span></span><span
                  style="font-size: 9pt;"><span style="font-family:
                    verdana,geneva;"><span style="background-color:
                      transparent;"><span style="color: rgb(0, 0, 0);"><span
                          style="color: rgb(0, 0, 0);"><br>
                        </span></span></span></span></span><span
                  style="font-size: 9pt;"><span style="font-family:
                    verdana,geneva;"><span style="background-color:
                      transparent;"><span style="color: rgb(0, 0, 0);"><span
                          style="color: rgb(0, 0, 0);">
                          <blockquote style="border-left: 2px solid
                            blue; margin-left: 5px; padding-left: 5px;
                            padding-top: 5px;">
                            <hr>
                            <b>Von:</b> "Yuval Harpaz" <<a
                              moz-do-not-send="true"
                              href="mailto:yuvharpaz@gmail.com"
                              target="_blank">yuvharpaz@gmail.com</a>><br>
                            <b>Gesendet:</b> Mar 24, 2011 10:41:02 AM
                            <div>
                              <div class="h5"><br>
                                <b>An:</b> "Email discussion list for
                                the FieldTrip project" <<a
                                  moz-do-not-send="true"
                                  href="mailto:fieldtrip@donders.ru.nl"
                                  target="_blank">fieldtrip@donders.ru.nl</a>><br>
                                <b>Betreff:</b> Re: [FieldTrip]
                                Different way of calculating the
                                covariance for LCM<br>
                                <br>
                                <div>Dear Michael, Jean-Michel and
                                  FieldTrip users.<br>
                                  To my experience and understanding it
                                  does matter if you first asses the
                                  covariance and then average or the
                                  other way around.<br>
                                  First, as far as my understanding
                                  goes, if we have some brain activity
                                  such as alpha, which is not phase
                                  locked to the event then in the
                                  covariance will not 'catch' too much
                                  covariability there after averaging,
                                  compared to unaveraged data where it
                                  should. if the process of calculating
                                  covariance and averaging id linear
                                  then I must be wrong here.<br>
                                  anyway, beamforming on averaged and
                                  unaveraged base covariance matrices
                                  give different results in fieldtrip.
                                  this is because the covariance
                                  matrices are not the same with or
                                  without averaging.<br>
                                  <br>
                                  I ran the following test to check it
                                  all. I took the same structure as in
                                  the example above, and I tested the
                                  covariance matrix after<br>
                                  1. running it with
                                  cfg.keeptrials='yes'; then I averaged 
                                  (across trials) the 3d matrix to get
                                  2d matrix.<br>
                                  2. running it without keeping trials;
                                  it gives a 2d covariance matrix.<br>
                                  3. averaging the data with this
                                  command:
                                  mD1st=ft_timelockanalysis([],D1st). no
                                  filters baseline correction or
                                  anything.<br>
                                  then I ran timelockanalysis again to
                                  compute the covariance (no keeptrials
                                  of course).<br>
                                  <br>
                                  the result is that 1. and 2. gave the
                                  same result but not 3.<br>
                                  <br>
                                  It seems to me that the process is not
                                  linear, at least in fieldtrip, and
                                  that one doesn't need to specify
                                  keeptrials for unaveraged data because
                                  it calculates the covariance for every
                                  trial and then averages the cov
                                  matrices.<br>
                                  <br>
                                  If I am wrong here I will appreciate
                                  further help with this issue.<br>
                                  <br>
                                  thanks<br>
                                  yuval<br>
                                  <br>
                                  <br>
                                  <div class="gmail_quote">On 23 March
                                    2011 21:27, Michael Wibral <span><<a
                                        moz-do-not-send="true"
                                        href="mailto:michael.wibral@web.de"
                                        target="_blank">michael.wibral@web.de</a>></span>
                                    wrote:<br>
                                    <blockquote class="gmail_quote"
                                      style="margin: 0pt 0pt 0pt 0.8ex;
                                      border-left: 1px solid rgb(204,
                                      204, 204); padding-left: 1ex;"><br>
                                      Dear Fieldtrip users interested in
                                      covariance computation,<br>
                                      dear Yuval,<br>
                                      <br>
                                      I would like to my opinion on
                                      covariance computation up for
                                      discussion here.<br>
                                      <br>
                                      Covariance is a (bi-)linear
                                      measure (like an inner (scalar)
                                      product) and should in principle
                                      be commutative mathematically with
                                      other linear procedures as long as
                                      you respect the distributative law
                                      from elementary math. Hence,<br>
                                      <br>
                                      (1) averaging single trial
                                      covariances or computing the
                                      covariance of concatenated trials
                                      should give the same result if a
                                      am not mistaken. In these two
                                      approaches samples from your two
                                      time course are in the end
                                      multiplied with each other one by
                                      one. Whichever route of these two
                                      you take does not matter at all.<br>
                                      This holds as long as you treat
                                      baseline correction and filtering
                                      (!) exactly the same way in both
                                      cases - otherwise you'll
                                      additionally get the baseline
                                      covariance over trials as a term
                                      in the covariance matrix or
                                      filtering related differences.
                                      This latter point maybe important
                                      if you post hoc decide on a band
                                      width to confine your beamformer
                                      analysis to and do not go back to
                                      the raw data for the band pass
                                      filtering.<br>
                                      <br>
                                      (2) In contrast, when you compute
                                      covariance from a precomputed
                                      trial average then every sample at
                                      time t in one trial on channel A
                                      will in the course of the
                                      calculations be implicitely
                                      multiplied with samples at time t
                                      at EVERY other trial on channel B.
                                      So this covariances focuses on
                                      covariance structures that are
                                      consistent irrespective of the
                                      correct pairings of trials.<br>
                                      <br>
                                      It's a little bit like first
                                      computing the power spectrum and
                                      averaging to get total activity
                                      (induced+evoked) - this would
                                      correspond to procedure (1) , or
                                      first averaging and then computing
                                      spectral power in order to get the
                                      power of evoked activity alone -
                                      this would correspond to procedure
                                      (2).<br>
                                      <br>
                                      This said, when you're interested
                                      in the sources of all task related
                                      oscillatory activity - not only
                                      the activity phase locked to a
                                      stimulus you should pick option
                                      (1).<br>
                                      <br>
                                      <br>
                                      Please let me know If I overlooked
                                      something important.<br>
                                      Michael<br>
                                      <br>
                                      <br>
                                      <br>
                                      <br>
                                      ---------------------<br>
                                      Von: "Jean-Michel Badier" <<a
                                        moz-do-not-send="true"
                                        href="mailto:jean-michel.badier@univmed.fr"
                                        target="_blank">jean-michel.badier@univmed.fr</a>><br>
                                      Gesendet: Mar 23, 2011 9:42:53 AM<br>
                                      An: "Email discussion list for the
                                      FieldTrip project" <<a
                                        moz-do-not-send="true"
                                        href="mailto:fieldtrip@donders.ru.nl"
                                        target="_blank">fieldtrip@donders.ru.nl</a>><br>
                                      Betreff: Re: [FieldTrip] Different
                                      way of calculating the covariance
                                      for LCM<br>
                                      <div>
                                        <div><br>
                                          <br>
                                          Thanks Yuval,<br>
                                          <br>
                                          <br>
                                           Le 22/03/11 10:55, Yuval
                                          Harpaz a écrit :<br>
                                          <br>
                                          So just run the commands on an
                                          unaveraged dataset.<br>
                                          <br>
                                          <br>
                                          <br>
                                          Yes but that would be correct
                                          if there was only one trial in
                                          the     data set (see the
                                          message from Luisa).<br>
                                          <br>
                                          <br>
                                          <br>
                                          Another option to consider is
                                          the one used by Dr.        
                                          Robinson when performing
                                          SAMerf (we have his tool
                                          [here], works         for our
                                          4D machine).<br>
                                          <br>
                                          <br>
                                           Thanks for it I will test it.<br>
                                          <br>
                                          <br>
                                          The idea is to calculate the
                                          covariance on all trials,
                                          calculate         weights by
                                          this covariance (keep filter
                                          in LCMV) and then apply      
                                            these weights on the
                                          averaged data. I found it
                                          useful because         the
                                          covariance is better for
                                          longer datasets, and the
                                          averaging         in the end
                                          increases the signal to noise
                                          ratio. I do not know        
                                          exactly how to do it in
                                          fieldtrip.<br>
                                          <br>
                                          <br>
                                          On 22 March 2011 10:43,
                                          Jean-Michel           Badier
                                          <[<a moz-do-not-send="true"
href="mailto:jean-michel.badier@univmed.fr" target="_blank">jean-michel.badier@univmed.fr</a>]>
                                          wrote:<br>
                                          <br>
                                          <br>
                                          Dear Yuval,<br>
                                          <br>
                                           I have to admit that I did
                                          not look at the matlab        
                                                routines.<br>
                                           In item 2 I suppose that the
                                          covariance is calculated for  
                                                      each trial then
                                          averaged. In item 3 I would
                                          like to              
                                          calculate the covariance from
                                          all the signal (the trials    
                                                    being concatenated).<br>
                                          <br>
                                           Jean-Michel<br>
                                          <br>
                                           Le 22/03/11 05:47, Yuval
                                          Harpaz a écrit :<br>
                                          <br>
                                          <br>
                                          <br>
                                          Dear Jean Michel<br>
                                          As far as I know you can do it
                                          on an averaged                
                                                  data structure (item
                                          1) or do the same with the    
                                                              data
                                          structure before averaging
                                          (3). I did not                
                                                  understand what you
                                          meant by 2.<br>
                                          <br>
                                          Yuval<br>
                                          <br>
                                          <br>
                                          On 21 March 2011 22:58,      
                                                             
                                          Jean-Michel Badier <[<a
                                            moz-do-not-send="true"
                                            href="mailto:jean-michel.badier@univmed.fr"
                                            target="_blank">jean-michel.badier@univmed.fr</a>]>
                                          wrote:<br>
                                          <br>
                                          <br>
                                          Dear                          
                                              fieldtrip users,<br>
                                          <br>
                                           There are different ways of
                                          estimating the                
                                                        covariance for
                                          LCMV calculation.<br>
                                           If I am correct:<br>
                                          <br>
                                           1. As suggested in one of the
                                          tutorial one                  
                                                      can apply the
                                          calculation of the            
                                                            covariance
                                          directly on the average data  
                                                                     
                                          (for the different periods of
                                          interest                      
                                                  that are at least a
                                          base line and the            
                                                            period of
                                          interest).<br>
                                          <br>
                                           2. Estimate the covariance
                                          from the                      
                                                  average of the
                                          covariance rather than the    
                                                                   
                                          covariance of the average
                                          using                        
                                                cfg.keeptrials = "yes"<br>
                                          <br>
                                           3. Estimate the covariance
                                          from the whole                
                                                        trials
                                          concatenated together.<br>
                                           Is there an easy way to do
                                          that in                      
                                                  fieldtrip (beside
                                          create a new data set of      
                                                                  one
                                          trial constituted of all the
                                          trials)?<br>
                                          <br>
                                           Thanks<br>
                                          <br>
                                           Jean-Michel<br>
                                          <br>
                                          <br>
                                          --  Jean-Michel              
                                                               Badier
                                          PhD<br>
                                           Laboratoire de              
                                                                   
                                          MagnétoEncéphaloGraphie INSERM
                                          U751. Aix                    
                                                              Marseille
                                          Université 33 (0)4 91 38 55 62
                                           [<a moz-do-not-send="true"
                                            href="mailto:jean-michel.badier@univmed.fr"
                                            target="_blank">jean-michel.badier@univmed.fr</a>]<br>
                                           Service de                  
                                                                     
                                          Neurophysiologie Clinique. CHU
                                                                       
                                                    Timone 264 Rue      
                                                                       
                                              Saint-Pierre, 13005      
                                                                       
                                              Marseille-France<br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
 _______________________________________________<br>
                                           fieldtrip mailing list<br>
                                          [<a moz-do-not-send="true"
                                            href="mailto:fieldtrip@donders.ru.nl"
                                            target="_blank">fieldtrip@donders.ru.nl</a>]<br>
                                          [<a moz-do-not-send="true"
                                            href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
                                            target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a>]<br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                           --<br>
                                          <br>
                                          Y.Harpaz<br>
                                          <br>
                                           a link to the BIU MEG lab:<br>
                                          [<a moz-do-not-send="true"
                                            href="http://faculty.biu.ac.il/%7Egoldsa/index.html"
                                            target="_blank">http://faculty.biu.ac.il/~goldsa/index.html</a>]<br>
                                          <br>
                                          <br>
                                          <br>
                                           _______________________________________________
                                          fieldtrip mailing list [<a
                                            moz-do-not-send="true"
                                            href="mailto:fieldtrip@donders.ru.nl"
                                            target="_blank">fieldtrip@donders.ru.nl</a>]
                                          [<a moz-do-not-send="true"
                                            href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
                                            target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a>]<br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
 _______________________________________________<br>
                                           fieldtrip mailing list<br>
                                          [<a moz-do-not-send="true"
                                            href="mailto:fieldtrip@donders.ru.nl"
                                            target="_blank">fieldtrip@donders.ru.nl</a>]<br>
                                          [<a moz-do-not-send="true"
                                            href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
                                            target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a>]<br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                           --<br>
                                          <br>
                                          Y.Harpaz<br>
                                          <br>
                                           a link to the BIU MEG lab:<br>
                                          [<a moz-do-not-send="true"
                                            href="http://faculty.biu.ac.il/%7Egoldsa/index.html"
                                            target="_blank">http://faculty.biu.ac.il/~goldsa/index.html</a>]<br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                        </div>
                                      </div>
                                       _______________________________________________
                                      fieldtrip mailing list [<a
                                        moz-do-not-send="true"
                                        href="mailto:fieldtrip@donders.ru.nl"
                                        target="_blank">fieldtrip@donders.ru.nl</a>]
                                      [<a moz-do-not-send="true"
                                        href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
                                        target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a>]<br>
                                      <span style="color: rgb(136, 136,
                                        136);"><br>
                                        <br>
                                        <br>
                                        --<br>
                                        <br>
                                        <br>
                                        <br>
                                        <!--<br>
                                                       @page { size:
                                        21cm 29.7cm; margin: 2cm }<br>
                                                       P {
                                        margin-bottom: 0.21cm }<br>
                                        --><br>
                                      </span>
                                      <div>
                                        <div>Jean-Michel Badier<br>
                                          <br>
                                          Laboratoire               de
                                          MagnétoEncéphaloGraphie<br>
                                          INSERM               U751. Aix
                                          Marseille Université<br>
                                          33               (0)4 91 38 55
                                          62<br>
                                          [<a moz-do-not-send="true"
                                            href="mailto:jean-michel.badier@univmed.fr"
                                            target="_blank">jean-michel.badier@univmed.fr</a>]<br>
                                          <br>
                                          Service                     de
                                          Neurophysiologie Clinique. CHU
                                                        Timone<br>
                                          264               Rue
                                          Saint-Pierre, 13005
                                          Marseille-France<br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                          <br>
                                        </div>
                                      </div>
                                      <br>
_______________________________________________<br>
                                      fieldtrip mailing list<br>
                                      <a moz-do-not-send="true"
                                        href="mailto:fieldtrip@donders.ru.nl"
                                        target="_blank">fieldtrip@donders.ru.nl</a><br>
                                      <a moz-do-not-send="true"
                                        href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
                                        target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
                                    </blockquote>
                                  </div>
                                  <br>
                                  <br>
                                </div>
                              </div>
                            </div>
                          </blockquote>
                        </span></span></span></span></span></div>
            </div>
            _______________________________________________<br>
            fieldtrip mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>
            <a moz-do-not-send="true"
              href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip"
              target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
          </blockquote>
        </div>
        <br>
        <br>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
fieldtrip mailing list
<a class="moz-txt-link-abbreviated" href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a>
<a class="moz-txt-link-freetext" href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></pre>
    </blockquote>
    <br>
    <br>
    <div class="moz-signature">
      <address>-- </address>
      <meta http-equiv="CONTENT-TYPE" content="text/html;
        charset=windows-1252">
      <title></title>
      <meta name="GENERATOR" content="NeoOffice 2.2 (Unix)">
      <meta name="CREATED" content="20080916;13142500">
      <meta name="CHANGED" content="20080916;14013400">
      <style type="text/css">
        <!--
                @page { size: 21cm 29.7cm; margin: 2cm }
                P { margin-bottom: 0.21cm }
        -->
        </style>
      <address style="margin-bottom: 0cm;">Jean-Michel Badier</address>
      <address style="margin-bottom: 0cm;"><br>
      </address>
      <address style="margin-bottom: 0cm;" align="LEFT"><font
          color="#000000"><font face="Times Roman, serif"><font size="3">Laboratoire
de
              MagnétoEncéphaloGraphie</font></font></font></address>
      <address style="margin-bottom: 0cm;" align="LEFT"><font
          color="#000000"><font face="Times Roman, serif"><font size="3">INSERM
U751. Aix
              Marseille Université</font></font></font></address>
      <address style="margin-bottom: 0cm;" align="LEFT"><font
          color="#000000"><font face="Times Roman, serif"><font size="3">33
(0)4
              91 38 55 62 </font></font></font></address>
      <address style="margin-bottom: 0cm;" align="LEFT"><a
          href="mailto:jean-michel.badier@univmed.fr"><font
            color="#000af1"><font face="Times Roman, serif"><font
                size="3"><u>jean-michel.badier@univmed.fr</u></font></font></font></a></address>
      <address style="margin-bottom: 0cm;" align="LEFT"><br>
      </address>
      <address style="margin-bottom: 0cm;" align="LEFT"><font
          color="#000000"><font face="Times Roman, serif"><font size="2"><font
                color="#000000"><font face="Times Roman, serif"><font
                    size="2">Service
                    de Neurophysiologie Clinique. </font></font></font>CHU
              Timone</font></font></font></address>
      <address style="margin-bottom: 0cm;" align="LEFT"><font
          color="#000000"><font face="Times Roman, serif"><font size="2">264
Rue
              Saint-Pierre, 13005 Marseille-France</font></font></font></address>
      <p style="margin-bottom: 0cm;" align="LEFT"><br>
      </p>
      <p style="margin-bottom: 0cm;"><br>
      </p>
    </div>
  </body>
</html>