How to interpret the following complex demodulation code?

2 views (last 30 days)
Hi all,
I am still pretty new to MATLAB and using it to analyze EEG data. Following is a code passed on to me which performs complex demodulation on EEG data. However, I am trying to really understand what this code does based on the set paramters so can someone please help me by explaining what exactly is this piece of code doing with my EEG data?
[b, a] = butter(PARAM.cdemod_forder, PARAM.cdemod_filter_lowpass / EEG.srate, 'low');
carArray = exp(-2*pi * li * PARAM.cdemod_freq * (0:size(EEG.data,2) - 1)) / EEG.srate);
x = double(EEG.data(iChan, :, iTrial)) .* carArray;
x = filtfilt(b, a, x);
Following are the paramter info:
PARAM.cdemod_forder = 4
PARAM.cdemod_filter_lowpass = 5
EEG.srate = 250
PARAM.cdemod_freq = 13.5
iChan and iTrial are just variables within a for loop basically the selected channels and trials from the EEG data.
Your help is very much appreciated. Please let me know if the question is not clear or if you require further information on it.
Thanks,
Mo

Answers (1)

dfl
dfl on 6 Jul 2019
Edited: dfl on 6 Jul 2019
Hi Mo, here's what is happening:
line 1 makes a butterworth lowpass filter
line 2 makes a complex sinusoid at the demodulation frequency
line 3 multiplies the EEG signal with the complex sinusoid (multiplication in the time domain is convultion in the frequency domain... resulting in a frequency shift). This shifts the spectral components at the demodulation frequency down to zero (DC).
line 4 uses the demodulation filter (from line 1) to lowpass filter the signal (removing the high frequency components) around the positive and negative frequencies near the band edge.
The filtfilt command does forward/backward filtering, which ends up filtering twice (essentially doubling the filter order) but ends up with no phase shift.

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!