fieldtrip icon indicating copy to clipboard operation
fieldtrip copied to clipboard

Amplitude Envelope Correlation implementation

Open crisglav opened this issue 2 years ago • 4 comments

I believe that the connectivity measure Amplitude Envelope Correlation (AEC) originally described originally in Hipp et al 2012, Nat Neuroscience is not implemented in Fieldtrip exactly as in that paper, using the Hilbert transform to estimate the envelope of the signals. I think it could be a good idea to include it in fieldtrip code. For instance, when calling ft_connectivity(). We have written a function (@stefanches7 and me) based on the original equations of Hipp et. al and the Brainstorm implementation of AEC. Here you can find the code and an example dataset to try it: https://syncandshare.lrz.de/getlink/fiN9J5KWBoHzQUajKK8ZnScG/aec_connectivity

Ideally we would like to integrate our implementation with the already existing in Fieldtrip (ft_conectivity_powcorr_ortho)

crisglav avatar Apr 21 '22 11:04 crisglav

I have looked at the differences between my code and ft_connectivity_powcorr_ortho and I came up with some points:

  • What kind of input should be given to ft_connectivity_powcorr_ortho? It is stated that it should be 'source' or 'freq'. In ft_connectivityanalysis (line 902) it is assumed that the data contains a 'cumtapcnt' field independent of being 'source' or 'freq'. In my case the source data does not contain that field. In the case of giving it a a frequency datatype it should be the fourier complex spectra, right?
  • What is exactly meant by power envelope? In ft_connectivity_powcorr_ortho the power envelope is computed by taking the absolute squared value of the Y signal orthogonalized with respect to X (https://github.com/fieldtrip/fieldtrip/blob/8482d8312d479d7a8723dab6b56336cd6e6dcd6a/connectivity/ft_connectivity_powcorr_ortho.m#L80). To my knowledge the power envelope is computed by taking the absolute value of the hilbert transform of a signal. Are these two ways of computing the envelope related?
  • First orthogonalizing, then taking the envelope is not the same as first taking the envelope and then orthogonalizing, I am right? I have noticed that I am first computing the hilbert transform and then orthogonalizing the Hilbert-transformed signals. In ft_connectivity_powcorr_ortho the signals are first orthogonalized and they are abs()^2. I think this makes a different and probably I made a mistake here.
  • How is the time dimension handled? I am orthogonalizing, taking envelope and correlating independently for each trial. In ft_connectivity_powcorr_ortho orthogonalization is done independently for each trial but then correlations are averaged across all trials. Therefore the output connectivity matrix size is Nchan*Nchan and in my case it would be Nchan*Nchan*Ntrials.

This is how far I got. I am sorry if I am stating something wrong, but for me is quite easy to get lost in these equations. Best, Cristina

crisglav avatar Apr 21 '22 12:04 crisglav

Besides from that, we seem to have detected a bug in powcorr_ortho case. It is first the optarg the field of data.cumtapcnt field that is not necessarily present (ft_connectivityanalysis:902) in the normal case, and it is not being filled in anywhere to my best knowledge. It also seems to me that it is not straightforward for the end-user as to how "AEC" and "powcorr_ortho" concepts are connected. What is your take on that @schoffelen @robertoostenveld and others?

stefanches7 avatar May 06 '22 11:05 stefanches7

AEC -> amplitude envelope correlation

powcorr_ortho -> correlation of power after orthogonalisation

Power is amplitude-squared, so if the amplitude timecourses are wrangled as to make them orthogonal on a observation-by-observation basis, then the only difference between the two is that AEC is computed from an unsquared quantity, and powcorr is not. Which one is better? no Clue.

schoffelen avatar Jun 24 '22 10:06 schoffelen

I have looked at the differences between my code and ft_connectivity_powcorr_ortho and I came up with some points:

  • What kind of input should be given to ft_connectivity_powcorr_ortho? It is stated that it should be 'source' or 'freq'. In ft_connectivityanalysis (line 902) it is assumed that the data contains a 'cumtapcnt' field independent of being 'source' or 'freq'. In my case the source data does not contain that field. In the case of giving it a a frequency datatype it should be the fourier complex spectra, right?

Input data should always be complex valued data that contains both amplitude and phase information, irrespective of whether it is derived from source level or sensor level data.

  • What is exactly meant by power envelope? In ft_connectivity_powcorr_ortho the power envelope is computed by taking the absolute squared value of the Y signal orthogonalized with respect to X (https://github.com/fieldtrip/fieldtrip/blob/8482d8312d479d7a8723dab6b56336cd6e6dcd6a/connectivity/ft_connectivity_powcorr_ortho.m#L80 ). To my knowledge the power envelope is computed by taking the absolute value of the hilbert transform of a signal. Are these two ways of computing the envelope related?

The Hilbert transform is a way to get the frequency domain representation of a band-limited signal (i.e. after applying a bandpass filter to a time series). This yields a complex valued signal that represents the amplitude and phase of a band limited process. Another way to obtain the frequency domain representation of a signal is to apply an FFT, and then select the numbers for a single frequency bin. Power is amplitude-squared.

  • First orthogonalizing, then taking the envelope is not the same as first taking the envelope and then orthogonalizing, I am right? I have noticed that I am first computing the hilbert transform and then orthogonalizing the Hilbert-transformed signals. In ft_connectivity_powcorr_ortho the signals are first orthogonalized and they are abs()^2. I think this makes a different and probably I made a mistake here.

The whole point of the approach is to orthogonalise first, and then compute the 'envelope', i.e. take the projection of the complex-valued numbers onto the line that is orthogonal to the other signal.

  • How is the time dimension handled? I am orthogonalizing, taking envelope and correlating independently for each trial. In ft_connectivity_powcorr_ortho orthogonalization is done independently for each trial but then correlations are averaged across all trials. Therefore the output connectivity matrix size is NchanNchan and in my case it would be NchanNchan*Ntrials.

ft_connectivity_powcorr itself does not know whether one of the dimensions means time or trials (although in the current implementation it may make certain assumptions), and it takes the second dimension of the input as the one across which to integrate for the correlation computation.

This is how far I got. I am sorry if I am stating something wrong, but for me is quite easy to get lost in these equations. Best, Cristina

schoffelen avatar Jun 24 '22 10:06 schoffelen

Hi Cristina @crisglav ,

What is the status of this? Are you waiting for input from our end?

schoffelen avatar Oct 04 '22 14:10 schoffelen

Hi Cristina @crisglav

What is the status of this? Are you waiting for input from our end? If not, I suggest to close this issue. We don't have the resources to address this at the moment. Feel free to reopen when appropriate

schoffelen avatar Nov 05 '22 12:11 schoffelen

Closing for now, primary stakeholder @crisglav has been unresponsive. Please feel free to re-open if there is anything to actively do here.

schoffelen avatar Feb 08 '23 10:02 schoffelen