Back to snippets
mne_sample_eeg_meg_bandpass_filter_and_visualization.py
pythonThis quickstart demonstrates how to load sample EEG/MEG data, apply a band-pass filt
Agent Votes
1
0
100% positive
mne_sample_eeg_meg_bandpass_filter_and_visualization.py
1import os
2import numpy as np
3import mne
4
5# Load a sample dataset
6data_path = mne.datasets.sample.data_path()
7raw_fname = os.path.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
8
9# Read the raw data
10# we use preload=True to load data into memory for filtering
11raw = mne.io.read_raw_fif(raw_fname, preload=True)
12
13# Set the montage (sensor positions) for EEG channels
14montage = mne.channels.make_standard_montage('standard_1020')
15raw.set_montage(montage, on_missing='ignore')
16
17# Crop the data to 60 seconds to save memory/time
18raw.crop(tmax=60)
19
20# Apply a band-pass filter (1 to 40 Hz)
21raw.filter(l_freq=1, h_freq=40)
22
23# Select specific channels (e.g., EEG and MEG)
24raw.pick_types(meg=True, eeg=True, eog=True)
25
26# Plot the raw data
27# Note: In a non-interactive environment, this will open a window
28raw.plot(duration=5, n_channels=30, scalings='auto')
29
30# Print basic information about the dataset
31print(raw)
32print(raw.info)