Simulating a Local Field Potential in MATLAB
Have you ever wondered: is my filter working? In neurophysiology, we are often faced with mashing together data, and in the process, sampling rates and filter settings can get lost. You are always one parameter away from interpreting a beta oscillation (13-30 Hz) as a delta oscillation (1-4 Hz), which can lead research far from the truth.
To check whether a filter is working properly, a ground truth local field potential (LFP) or “wideband” signal should be used, where the timing and frequencies are known. Here, I have created an LFP generator with control over all aspects of timing, frequency and amplitude.
Ground Truth LFP M-file
The LFP generator combines sinusoids based on the input parameters to generate a single waveform as the output. The variable, t
, represents the time course and is the same length as the lfp
.
An Example
My primary reason for creating this was to test if the spectrogram function I use is accurate in both the time and frequency domain. For instance, most analyses require my filter to be non-causal (i.e., centered on the input phenomena with zero-lag). Here is an example of how to use groundTruthLFP.m.
The LFP I constructed is 10 seconds long with a sampling rate of 1,000 Hz. The first frequency I added was at 4 Hz, from 0-10 seconds with unity amplitude. The third frequency was 30 Hz, from 0-5 seconds with an amplitude of 3. Then, Iran the lfp
through my spectrogram function to see if the output matches the signal I designed.
Altogether, it looks really good. You can get a feel for the rolloff properties of the filter and causality. Most importantly, the frequencies and timing are spot on.
Caveats
This function does not pay any special attention to the phase of the input signal. It begins all sinusoids at the time specifed in oscillationOnOff
at 0π. Therefore, waves of similar frequency will have phase interactions that may lead to noticeable segments of constructive and destructive interference in the output. For example, notice how the following example has nearby input frequencies, resulting to a non-trivial spectrogram.
This example highlights just one of considerations when analyzing LFPs from the brain, where signals arriving from different brain structures may have no phase coordination, but are ultimately summed together. That is, the fun.
Recent Comments
Archives
- April 2023
- January 2023
- November 2022
- May 2022
- March 2022
- January 2022
- December 2021
- April 2021
- December 2020
- October 2020
- August 2020
- July 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- January 2019
- December 2018
- November 2018
- August 2018
- July 2018
- April 2018
- March 2018
- November 2017
- October 2017
- February 2017
- October 2016
- August 2016
- July 2016
- November 2015
- October 2013
- February 2013
- January 2013
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- February 2012
- December 2011