open-ephys / plugin-GUI

Software for processing, recording, and visualizing multichannel electrophysiology data
https://open-ephys.org/gui
GNU General Public License v3.0
192 stars 684 forks source link

Notch Filter #555

Open PostDocKala opened 1 year ago

PostDocKala commented 1 year ago

Hi, I was wondering how one can enable the notch filter on the Open Ephys GUI? I can't seem to find the setting anywhere.

medengineer commented 1 year ago

Hi,

There is no notch filter in the most recent versions of the GUI. If you are trying to remove noise from a narrow frequency band (eg 60Hz interference) we recommend using the Common Average Reference plugin for this instead.

Phosphoenix commented 11 months ago

Hi,

How should you use it? Say there is a 60 Hz interference on all channels, then I should select all channels in reference channels and in affected channels, right?

Thanks.

jsiegle commented 11 months ago

That's right...assuming the 60 Hz noise occurs on all channels, they should all be selected as both "reference" and "affected."

florian6973 commented 3 months ago

Any update?

jsiegle commented 3 months ago

We're not planning to add a Notch Filter plugin. Are you seeing 60 Hz noise in your data that's not removed by the Common Avg Ref?

florian6973 commented 3 months ago

Yes indeed, since some electrodes have different impedances, the CAR does not remove the noise well.

Moreover, when disabling some channels in the Channel Map (located before the CAR component in the signal chain), OpenEphys crashes when restarting the recording, if I do not manually update the Reference channels in the CAR. Is it expected please?

End of the log

[open-ephys][debug] ProcessorGraph starting acquisition...
[open-ephys][ddebug] RHD Rec Controller (112) received message to start acquisition.
[open-ephys][ddebug] Bandpass Filter (115) received message to start acquisition.
[open-ephys][ddebug] Common Avg Ref (114) received message to start acquisition.
[open-ephys][ddebug] LFP Viewer (113) received message to start acquisition.
[open-ephys][ddebug] LFP Viewer (116) received message to start acquisition.
[open-ephys][debug] Only one stream, setting as synchronized.
[open-ephys][ddebug] Record Node (117) received message to start acquisition.
[open-ephys][ddebug] Spike Viewer (118) received message to start acquisition.
[open-ephys][ddebug] Spike Detector (119) received message to start acquisition.
[open-ephys][ddebug] Channel Map (120) received message to start acquisition.
[open-ephys][debug] 
0: juce::SystemStats::getStackBacktrace + 0x93
1: ofSerialDeviceInfo::~ofSerialDeviceInfo + 0x19fde
2: juce::Time::getYear + 0x6a
3: UnhandledExceptionFilter + 0x1ec
4: RtlCopyMemory + 0x2bbd
5: _C_specific_handler + 0x97
6: _chkstk + 0x12f
7: RtlFindCharInUnicodeString + 0xa96
8: KiUserExceptionDispatcher + 0x2e
9: InfoObject::getGlobalIndex + 0x0
10: getPluginInfo + 0xbe9
11: GenericProcessor::processBlock + 0x4b
12: juce::GenericAudioProcessorEditor::paint + 0x154f
13: juce::GenericAudioProcessorEditor::paint + 0x92e
14: juce::AudioProcessorGraph::processBlock + 0xe1
15: juce::AudioProcessorPlayer::audioDeviceIOCallback + 0x52b
16: juce::AudioDeviceManager::audioDeviceIOCallbackInt + 0x215
17: juce::MidiOutput::run + 0x839
18: juce::Thread::threadEntryPoint + 0x6c
19: juce::Thread::threadEntryPoint + 0x15c
20: recalloc + 0xa3
21: BaseThreadInitThunk + 0x1d
22: RtlUserThreadStart + 0x28
anjaldoshi commented 3 months ago

Yes indeed, since some electrodes have different impedances, the CAR does not remove the noise well.

You can handle the case of mismatched impedances by using multiple CAR plugins for each set of electrodes.

Moreover, when disabling some channels in the Channel Map (located before the CAR component in the signal chain), OpenEphys crashes when restarting the recording, if I do not manually update the Reference channels in the CAR. Is it expected please?

Thanks for bringing this to our attention. We were able to repro this crash on our end. As a quick fix, I patched the CAR plugin and generated a new DLL for it. You can update the plugin on your end locally by simply extracting the below zip file and then replace the plugin DLL located in the plugins directory next to you GUI executable with the new one. If you installed the GUI at the default location, the plugins folder can be found here C:\Program Files\Open Ephys\plugins

CommonAverageRef.zip

florian6973 commented 3 months ago

Thank you so much for your prompt fix, it works like a charm now!

Indeed, however given the number of different electrodes we have, this is not very practical... What would be the difficulties to implement a Notch Filter by ourselves please, as a plugin?

jsiegle commented 3 months ago

This would actually be pretty straightforward – you could copy the code for the FilterNode plugin and change the filter type from BandPass to BandStop: https://github.com/open-ephys/plugin-GUI/blob/8c6453954b431a1f48f18b8fc3ddd1282eeda56d/Plugins/FilterNode/FilterNode.cpp#L38

Instructions for creating a new plugin can be found here.

florian6973 commented 3 months ago

Thanks for your help! Here is the repo https://github.com/florian6973/notch-filter-plugin Clearly the longest part was to setup compilation... Would you like it to distribute it or not please?

I used a 4th order filter but it was crashing with 2nd.

florian6973 commented 3 months ago

Here is what it looks like: https://drive.google.com/file/d/1d_4tWGzD4yRvkzVA_71-nD4zC20koLwT/view?usp=sharing

jsiegle commented 3 months ago

Thanks for putting this together! I think it would be reasonable for us to release this, with the caveat that it should only be used if other methods of reducing noise fail.

I just created a forl so we can distribute it via the Plugin Installer: https://github.com/open-ephys-plugins/notch-filter

florian6973 commented 2 months ago

Fantastic, thank you very much! So it should be available in the plugin installer tool of the next OE version?

jsiegle commented 2 months ago

Plugins are released independently of the core application, so it will show up in the plugin installer once we set it up to build automatically. We'll let you know when it's ready!