# EEG Power at specific time points

I'm in the process of building features for an EEG machine learning problem and have been doing some reading about what features may be useful. Turns out, that alpha band (8-12Hz) power can make a good distinction between my categories. The nuance is that for 1 category, alpha power rises and then falls over the time series, but for the other category alpha power begins low and then rises

I have a butterworth filtered signal which gives me a fairly clean alpha wave, but is it possible to determine power of this band at every time point over the series?

If I can get away with doing the calculations on just the filtered signal then that'd be ideal, without having to resort to running an FFT (the eventual goal is to do this online and my concern is speed)

Could it simply be the squared amplitude at every time point? Or do I need to run a specific FFT/time-frequency type analysis for this?

I've been trying to find some Python code for this but haven't had much luck because I mostly am not sure the best way forward

The Goertzel algorithm allows you to compute individual terms of the Discrete Fourier Transform, and is more efficient than the FFT. However, if you wish to later compute the spectrum of other bands besides alpha, Goertzel will turn out to be more computationally expensive than the FFT.

Unless you are seriously limited by computational power, in principle, you can compute the Fast Fourier Transform in quasi-real-time, using a sliding window (also known as the Short Time Fourier Transform, or STFT). The Discrete Wavelet Transform is also sometimes used for real-time EEG power estimation. To find the power in the alpha band, you can look at the corresponding frequency bins of the STFT for either the original or the filtered signal.

The output of the STFT will be delayed by the length of your window (as you need all the samples inside the window to arrive before computing the power in that time bin). However, with a window length of 512 samples under 8kHz sampling rate, for example, this amounts to 0.064 seconds delay, which is fairly close to 0.0 seconds!

The STFT (Short-Time Fourier Transform) is effectively a computation of the FFT one 'chunk' or 'time-frame' of the signal at a time. Often these chunks are overlapped by some amount, such as 50%, meaning that if the window length is 512 samples, then halfway through the first frame (at the 256th sample), you already begin to process samples that contribute to the second time-frame.

The purpose of using overlapping frames is to avoid artefacts caused by taking square slices of the signal. (Computing the power of one sample at a time, like you suggest, amounts to convolving your signal with a square window, which is equivalent to convolving the frequency representation of your signal with a sinc function. This causes spectral leakage, or 'ringing' artfeacts. Thus, it is common to use a sliding window with smooth edges, such as a Hamming window, to reduce these artefacts.)

Note that the choice of window length will affect your spectro-temporal resolution. A longer window will have better frequency resolution, but worse temporal resolution, and vice-versa. This phenomenon is known as the Gabor limit, or Heisenberg-Gabor limit.