Real-time source localization 2

Dear MNE users, I would like to do real-time source localization from real-time EEG signals.

I think there is real-time MNE package.
Real-time M/EEG Acquisition — MNE-Realtime 0.1.dev0 documentation

But, I did not discover real-time source localization example. If you know it, let’s share the useful information.


There isn’t an existing example. It ought to be possible in principle, however: if you can determine in advance your forward model and noise covariance, then you ought to be able to use mne.minimum_norm.apply_inverse to each Realtime epoch as it comes in.

Dan, I see. Great information for me! Kyu

This might help:

The code is a bit old but can perhaps be adapted for your usecase.


Hi Mainak, Thank you so much! Your code is so helpful for me!


Hi Mainak, thanks for your helpful comments. When I looked at your code, you used ‘compute_source_psd_epochs’. Is there any time delay related to this function?

Using your code, we can implement real-time source localization. One thing that I am worried is time-delay. Didn’t you feel any delay in your realtime system?

Hi Kyu,

Apologies for the delayed response. You might want to look at my Masters thesis here:

Specifically, take a look at this figure:

If I remember correctly, the total time delay depends on: 1) the buffer length in FieldTrip buffer, 2) the buffer size of the data requested by the FieldTrip buffer client in MNE-Python, and 3) the processing speed. If you precompute the forward, 3) may not be a bottleneck. I would recommend measuring the time with time.time or some such tool. 1) usually depends on the vendor. For Elekta systems on which I tested, I think 28 samples is the minimum buffer length. Now, depending on the timing of the start of the buffer and query from MNE-Python, the actual delay may have a distribution as shown in the figure above. Note that get_data_as_epoch requests only the last n_samples, so you do get pseudo-realtime at the expense of missing some samples. If on the other hand, you’d like to get all the samples corresponding to a trigger, you should use iter_evoked.

Hope that helps!

Hi Mainak, thanks for you helpful information. Your information is so important for me. I think for your master study you worked very hard and did a lot!