TomasLenc / acf_tools

Utilities for working with autocorrelation to capture periodicity in a signal.
GNU General Public License v3.0
2 stars 0 forks source link

aperiodic fit, reference range #3

Closed cedlenoir closed 9 months ago

cedlenoir commented 1 year ago

Cedric: I tried the new version on the data of XP1 (audio vs vibro) using 2 "max_freq" (9 Hz or fs/2) for the fitting (other parameters set to default), as you can see below the acf change.

XP1 max_freq_9Hz max_freq_nyquist

XP2 maxfreq_9Hz maxfreq_nyquist

plots of the magnitude spectra and the fitted 1/f (in linear scale), for grand average actual data XP1 ap fit test1 ap fit test2

Tomáš: Honestly, I assumed that going so high would be counterproductive because there is often this "knee" that Donoghe describe, and also bumps from alpha etc....

But the plots you did seem quite clear, although I'd like to see how it fits when you zoom in onto the lower frequency range, let's say 0 to 10 Hz?

TomasLenc commented 1 year ago

I mean, I'm looking again, and for this particular example there's no need to zoom in on anything...it's obviously a wrong fit when max_freq is 9 Hz...

@cedlenoir you told me these plots are "group data", but how exactly did you do it? Is it a 1/f fitted to grand average spectra across participants?

cedlenoir commented 1 year ago

Yes, exactly. I should look then subject by subject.

TomasLenc commented 1 year ago

Yes, exactly. I should look then subject by subject.

I mean, it depends - for the bootstrap approach, this grand average is what's going to be fitted right? So it's quite informative indeed!

But maybe looking at individual subjects may reveal something interesting so it doesn't hurt to check? :)

cedlenoir commented 1 year ago

With Sylvie, we thought that it makes sense to select the frequency range differently for each modality, given that for responses to auditory stimuli most of the energy shows off in the 0-5 Hz and in the 5-25 Hz range for vibrotactile. Then one option, would be to filter the time domain data (i.e., low pass at 10 Hz for audio, and band pass 5-30 Hz for vibro) and then run the acf. Obviously the ap fitting of the 5-30 Hz is poor. Would it be an option to crop the spectra depending on the range of interest? would acf work on that? Here are below the ap fit on the average data

audio min_freq = 0.1; max_freq = 10; image

vibro min_freq = 5; max_freq = nyquist; image

TomasLenc commented 1 year ago

Okay I'm not sure I understood exactly what you meant, so my reply has 2 parts :)


(1) Control frequency range used for 1/f fitting:

It doesn't matter where the response is - all response peaks are removed from the spectrum before fitting 1/f parameters. So unless you have a specific reason to assume that the noise is systematically different across modalities, there is no reason to worry about the nature of the response.

All you need is to find good parameters that will allow you to fit the noise. And in your case, the noise should have similar characteristics across conditions, as you didn't change the eeg system or anything like that across conditions right?

The parameters min_freq and max_freq set the minimum and maximum in the spectrum that the fitting algorithm is going to use. The rest is ignored. So you don't need filters or "cropping" the spectrum - simply set the min_freq higher to ignore whatever is below, and/or set max_freq lower to ignore whatever is above.


(2) Control frequency range used to compute ACF:

Now, if I understand correctly, your question was not necessarily about fitting 1/f, but rather you were discussing whether one could use a restricted range of the spectrum in order to calculate the autocorrelation function? I guess the idea is that including portions of the spectrum with little response (e.g. above 5 Hz for audio) unnecessarily injects noise into the ACF estimate?

Ooft, I am not sure. I guess, in principle, we could add an option to simply zero out response harmonics in particular frequency range of the complex spectrum, after correcting for 1/f and before computing ACF. We already zero out frequencies that are not harmonics of the "base" response frequency, which improves the SNR.

But to be completely honest, I would probably play around with the 1/f fitting procedure to make it work well. I'm not so sure whether the responses are really sooo noisy that you'd be forced to massage the data the way I described just above....or?

TomasLenc commented 1 year ago

So it seems that selecting the fitting range for FOOOF-like approach is a trade-off between two problems.

On one hand, if the higher frequency limit is low (e.g. 9 Hz), there can be an overfit of higher frequencies. Hence, these frequencies are completely eliminated once the esimated 1/f is subctracted out from the response. Screenshot from 2023-07-10 13-08-58

On the other hand, setting the upper fitting limit frequencies a bit higher (e.g. 30 Hz) prevents the overestimate at higher frequencies. However, it can result in a slight overestimate at lower frequencies. This, again, eventually leads to suppression of these low frequencies once 1/f is subtracted, hence distorting the response (potentially inflating meter-related periodicities!). Screenshot from 2023-07-10 13-09-53

Here is a zoomed-in lower end of the spectrum when fitting 1/f between 0.1-30 Hz:

Screenshot from 2023-07-10 13-20-05

and between 0.1-9 Hz:

Screenshot from 2023-07-10 13-20-28