Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Shape of outputs, FFT

20 views
Skip to first unread message

Simon Beyer

unread,
May 16, 2024, 4:26:12 AM5/16/24
to TVB Users
Dear TVB users,

I am trying to simulate EEG and analyze the powerspectrum within the framework of TVB, but I have trouble understanding the outputs I generate (or rather their shape) using the Fast fourier transform.

The result of the EEG simulation has the shape (10667, 4, 61, 1). In my understanding this equates to (datapoints, state variables, sensors, DONT KNOW).

When I do the FFT and use the "compute.power()" method from the fourier_spectrum class, the output has the shape:
power.shape = (1024, 4, 61, 1, 6)
In my understanding this equates to (frequency bins, state variables, sensors, DONT KNOW, DONT KNOW).

Could you maybe explain to me what the "dont know"s in the shapes of the outputs are? I couldn't find it out be searching through the documentation and sourcecode :')

All the best,
Simon

WOODMAN Michael

unread,
May 21, 2024, 9:07:27 AM5/21/24
to tvb-...@googlegroups.com

hi


Are you doing this through the web UI or scripting?  If it's a script, can you share a piece of code?  In the first case, the last dimension is the modes of the model, you can ignore this safely.  In the second case, with last dimension size 6, I'm not sure what that is.


If you intend to do extensive EEG-based analyis, you may want to move those time series to MNE-Python.


cheers,

Marmaduke


From: tvb-...@googlegroups.com <tvb-...@googlegroups.com> on behalf of Simon Beyer <simon....@gmail.com>
Sent: Thursday, May 16, 2024 10:26:12 AM
To: TVB Users
Subject: [RESEAUX SOCIAUX] [TVB] Shape of outputs, FFT
 

Ce mail provient de l'extérieur, restons vigilants

--
You received this message because you are subscribed to the Google Groups "TVB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/c20e75e3-83fd-4555-bac9-d8a2ca5a9e24n%40googlegroups.com.

Lia Domide

unread,
May 21, 2024, 9:32:10 AM5/21/24
to TVB Users
Hi Simon,

If you are using TVB web interface, you have this information in the datatype overlay appearing when you click on a TS_EEG result (attached picture).
Then, you see Model in the place you put DONT KNOW, same as the other answer you got.

Best,
Lia. 



TS_Metadata.jpg

Simon Beyer

unread,
May 22, 2024, 3:54:13 AM5/22/24
to TVB Users
Thanks for your answers, I am using the scripting interface. Another issue I encountered was, that I couln't use a windowing function, because calling it with a string like (e.g. 'hanning) triggers an error ( AttributeError: 'str' object has no attribute 'value' ).
This are the relevant bits of code, I think (or should I post the entire script?):


sim = simulator.Simulator(coupling = coupl,
                         integrator = integ,
                         connectivity = SC,
                         conduction_speed = 4,
                         simulation_length = 10000,
                         model = mod,
                         monitors = [mon_EEG]
                         )

results = sim.run()
.
.
.

from tvb.analyzers.fft import compute_fast_fourier_transform
from tvb.datatypes.time_series import TimeSeriesEEG
from tvb.simulator.lab import *

# Example data loading
# data should have shape (10667, 4, 61, 1)
# eeg_data should then be (10667, 61) when extracting the first state variable
eeg_data = results[0][1] # This simplifies the data to (10667, 61)

# Create TimeSeriesEEG with all required configurations
time_series_eeg = TimeSeriesEEG()
time_series_eeg.data = eeg_data
time_series_eeg.time = time
time_series_eeg.sensors = sensorsEEG
time_series_eeg.title = "EEG Time Series Data"
time_series_eeg.labels_ordering = ['Time', 'State Variables', 'EEG Sensors', 'Mode']
time_series_eeg.sample_period = 1.0 / 1024  # Sample period in seconds
time_series_eeg.sample_period_unit = 's'  # Unit of sample period
time_series_eeg.start_time = time[0]  # Assuming time[0] is the start time, adjust if necessary
time_series_eeg.labels_dimensions = {
    'State Variables': ['Variable1'],  # Adjust according to actual variables
    'EEG Sensors': list(sensorsEEG.labels),
    'Mode': ['Default']  # Adjust if there are multiple modes
}
time_series_eeg.configure()

.
.
.

# FFT Parameters
from tvb.datatypes.spectral import FourierSpectrum

#WindowingFunctionsEnum.HAMMING

segment_length = 2.0  # 2 seconds for a 0.5 Hz frequency resolution
window_function = None  # No window due to bug
detrend = True  # Typically you might detrend, but depends on your data preprocessing

# Compute FFT
fourier_spectrum = compute_fast_fourier_transform(time_series_eeg,
                                                  segment_length,
                                                  window_function,
                                                  detrend)

.
.
.

fourier_spectrum.compute_power()

print(power.shape)

OUTOUT: (1024, 4, 61, 1, 6)


Best regards,
Simon

Lia Domide

unread,
May 22, 2024, 5:06:22 AM5/22/24
to TVB Users
Hi Simon,

How about setting the window_finction to an instance of  WindowingFunctionsEnum ?

from tvb.datatypes.spectral import WindowingFunctionsEnum
window_function = WindowingFunctionsEnum.HAMMING

I an not test this directly at the moment, but by looking at the code it seem like the expected value type. 
Then, it would be a problem with the python doc, to notify the correct type.

Best,
Lia.

Reply all
Reply to author
Forward
0 new messages