This upgraded version of the script requires Spike2 v7.20 or later.
Waveforms should be recorded with a sampling rate of at least 500Hz and preferably 5kHz or higher. The best results will be obtained if you record a dedicated waveform channel that clearly shows the ongoing mains frequency oscillation in addition to your data channels. This could be simply the mains pick-up from an unshielded cable. The script can use this signal to generate an event channel of timing marks at the onset of each mains cycle. These time marks are then used to calculate the mains interference signal to subtract from each waveform to clean it up.