ARFilter Spectral Estimation

Forum for discussion on different signal processing algorithms
Locked
chazzd13
Posts: 14
Joined: 12 May 2010, 03:51

ARFilter Spectral Estimation

Post by chazzd13 » 30 Nov 2010, 21:45

Greetings!

Could you clarify for me how ARFilter obtains discrete spectral amplitude and spectral power? I looked at User Reference:ARFilter, but still don't have a clear understanding.

Furthermore, what is the significance, if any, in using one OutputType over another for BCI control?

Thank you for any information you can provide, and also thank you for this truly excellent system!

mellinger
Posts: 1064
Joined: 12 Feb 2003, 11:06

Post by mellinger » 01 Dec 2010, 08:38

Hi,

the ARFilter operates in two steps. First, it estimates AR coefficients using the MEM/Burg method. These AR coefficients are the denominator coefficients of a rational polynomial representing a filter transfer function, for a filter that shapes white noise into a spectrum that matches the signal's spectrum. In order to obtain that spectrum in the second step of operation, the filter transfer function is evaluated for discrete frequencies which are called bins. For each frequency bin, a number of equidistant points is used to determine average signal power in the bin (determined by the EvaluationsPerBin parameter).
Furthermore, what is the significance, if any, in using one OutputType over another for BCI control?
If linear classification is used, I would suggest spectral amplitude or power (which do not differ much). For more general classifiers such as support vector machines (which do not come with BCI2000), AR coefficients may be used as features.

HTH,
Juergen

chazzd13
Posts: 14
Joined: 12 May 2010, 03:51

Post by chazzd13 » 02 Dec 2010, 01:40

Thank you for the quick response, Juergen. I believe I understand up to that point. But can you provide more detail regarding the computation performed on a specific bin, particularly in the case of Spectral Amplitude?

The reason I am asking is that I am trying to recreate the ARFilter process in Matlab (using pburg) to perform offline simulations, and I want to make sure I am producing the control signal properly.

mellinger
Posts: 1064
Joined: 12 Feb 2003, 11:06

Post by mellinger » 02 Dec 2010, 08:51

Hi,

for offline simulations, BCI2000 comes with two tools which might be interesting to you:
A) Command line processing (http://www.bci2000.org/wiki/index.php/U ... Processing) allows you to apply BCI2000 filters to offline data, interrupt the processing at any point, and store the result in Matlab files.
B) There is a Matlab mex file called mem that does AR processing, using the same code as the ARFilter (http://www.bci2000.org/wiki/index.php/U ... _Files#mem)

If you still want to recreate the ARFilter in Matlab, here is the process for a single bin in case of Spectral Amplitude, in more detail:
1) Divide the bin's width into EvaluationsPerBin equidistant points.
2) Normalize all frequencies such that -Nyquist freq ... + Nyquist freq is mapped to -pi ... pi.
3) For each evaluation point, evaluate the AR polynomial at exp(i * normalized frequency), and divide total signal power by the squared absolute value of the result.
4) Sum up over all evaluation points to obtain the bin's signal power.
5) Take the square root to obtain the bin's signal amplitude.

Regards,
Juergen

Edit: Added exp function in 3)
Last edited by mellinger on 06 Dec 2010, 08:44, edited 1 time in total.

chazzd13
Posts: 14
Joined: 12 May 2010, 03:51

Post by chazzd13 » 03 Dec 2010, 01:56

Juergen, this is all extremely helpful. Thank you so much!

dyd1985
Posts: 23
Joined: 13 May 2010, 11:19

Re:

Post by dyd1985 » 14 Jun 2011, 12:29

mellinger wrote:Hi,

for offline simulations, BCI2000 comes with two tools which might be interesting to you:
A) Command line processing (http://www.bci2000.org/wiki/index.php/U ... Processing) allows you to apply BCI2000 filters to offline data, interrupt the processing at any point, and store the result in Matlab files.
B) There is a Matlab mex file called mem that does AR processing, using the same code as the ARFilter (http://www.bci2000.org/wiki/index.php/U ... _Files#mem)

If you still want to recreate the ARFilter in Matlab, here is the process for a single bin in case of Spectral Amplitude, in more detail:
1) Divide the bin's width into EvaluationsPerBin equidistant points.
2) Normalize all frequencies such that -Nyquist freq ... + Nyquist freq is mapped to -pi ... pi.
3) For each evaluation point, evaluate the AR polynomial at exp(i * normalized frequency), and divide total signal power by the squared absolute value of the result.
4) Sum up over all evaluation points to obtain the bin's signal power.
5) Take the square root to obtain the bin's signal amplitude.

Regards,
Juergen

Edit: Added exp function in 3)
This was extremely helpful also to me. Thank you so much.
I have another question, I'm using the mem() function to perform AR anlysis in MATLAB and as you said it performs the same processing as ARFilter in real-time. When you perform real-time experiments you can set the AR filter time window, but if you just use the mem() in MATLAB you don't set time any windows, I mean you process all your data at once. Is this going to produce significant differences in terms of spectral resolution and things like that between on-line and off-line results?

Thank you so much
Alessandro

mellinger
Posts: 1064
Joined: 12 Feb 2003, 11:06

Re: ARFilter Spectral Estimation

Post by mellinger » 17 Jun 2011, 14:08

Hi Alessandro,

the mem mex file allows you to specify windowing as well:
The mem command estimates a power spectrum using Burg's MEM algorithm.
The calling syntax is:
[spectrum, frequencies] = mem(signal, parms)
with <signal> having dimensions (values x channels),
<spectrum> having dimensions (values x channels x blocks,
and with <parms> being a vector of parameter values:
model order,
first bin center,
last bin center,
bin width,
evaluations per bin,
detrend option (optional, 0: none, 1: mean, 2: linear; defaults to none),
frequency (optional, defaults to 1),
sample block size (optional, defaults to size(signal,1)),
number of windows (optional, defaults to 1)
The "sample block size" parameter defines the number of samples between the beginning of subsequent overlapping windows. The "number of windows" parameter defines the length of the buffer over which the AR spectrum is computed, such that (buffer length in samples) = (sample block size) times (number of windows).

Regards,
Juergen

dyd1985
Posts: 23
Joined: 13 May 2010, 11:19

Re: ARFilter Spectral Estimation

Post by dyd1985 » 17 Jun 2011, 14:31

Thanks,
I appreciated it.
I'm sorry but still I can't get it. Let me try with an example. I have attached a snapshot of AR filter parameters' configuration. Let's assume that I want to use the same configuration in Matlab when calling the mem function. Would my parameters be:

Code: Select all

sampfreq = 512;
ModelOrder= 16;
FirstBinCenter= 0;
LastBinCenter= 30;
BinWidth= 1;
EvaluationsPerBin= 15;
detrend = 0;
sampleblock = 16;
numwindows = 16;
Because sampleblock * numwindows = 256. That is equal to time window over which the AR filter operates expressed as number of samples. I'm sorry but I'm really missing something here.

Alessandro
Attachments
Params.png

mellinger
Posts: 1064
Joined: 12 Feb 2003, 11:06

Re: ARFilter Spectral Estimation

Post by mellinger » 02 Sep 2011, 10:51

Dear Alessandro,

sorry for answering so late, it appears your post got lost.
Your configuration is right insofar as window size actually matches 0.5s.
Still, you need to decide on a reasonable sample block size because this parameter defines the interval in which spectra are computed. For each sample block, one spectrum is computed. This matches the behavior of the online system, which computes one spectrum for each sample block as well. So to use the same parameters as online, set the sample block size to the value of the Source->SampleBlockSize parameter in the online system.

Then, choose the "number of windows" parameter such that it matches 0.5s in terms of sample blocks.

Regards,
Juergen

caranico
Posts: 7
Joined: 11 Oct 2011, 04:33

Re: ARFilter Spectral Estimation

Post by caranico » 17 Nov 2011, 08:42

Hi,
i have the opposite problem.
during online analysis, i want to obtain with the ARFilter the same spectra as that in the offline analysis. It's too important for me because i want to determine a threshold value looking the spectra plot and the r^2 plot obteined in the offline analysis and use it during online operation. Could someone help me?


Nicoletta

dyd1985
Posts: 23
Joined: 13 May 2010, 11:19

Re: ARFilter Spectral Estimation

Post by dyd1985 » 17 Nov 2011, 10:52

caranico wrote:Hi,
i have the opposite problem.
during online analysis, i want to obtain with the ARFilter the same spectra as that in the offline analysis. It's too important for me because i want to determine a threshold value looking the spectra plot and the r^2 plot obteined in the offline analysis and use it during online operation. Could someone help me?


Nicoletta
Hey Nicoletta,

The ARFilter you use on-line is the same function you call from Matlab when performing the off-line analysis. Of course all the function parameters can be manually set, so in order to get the same r^2 values in both cases (on-line and off-line) you need to make sure to use the same parameters and you should be good to go.

Alessandro

caranico
Posts: 7
Joined: 11 Oct 2011, 04:33

Re: ARFilter Spectral Estimation

Post by caranico » 17 Nov 2011, 11:17

thank you Alessandro!!
the problem is that i control the value during the online operation and they differ a lot from the values obteined during the offline analysis. I think that the only parameters that could be different is "NumericWindow" because i don't understand where is setted in the matlab file that generate the offline analysis.
i want to underline that i'm using the implemented tool for the offline analysis and not the mem MEX file. Are you sure that the function is the same even in this case?
thank you so much!
Nicoletta

dyd1985
Posts: 23
Joined: 13 May 2010, 11:19

Re: ARFilter Spectral Estimation

Post by dyd1985 » 17 Nov 2011, 12:33

caranico wrote:thank you Alessandro!!
the problem is that i control the value during the online operation and they differ a lot from the values obteined during the offline analysis. I think that the only parameters that could be different is "NumericWindow" because i don't understand where is setted in the matlab file that generate the offline analysis.
i want to underline that i'm using the implemented tool for the offline analysis and not the mem MEX file. Are you sure that the function is the same even in this case?
thank you so much!
Nicoletta
Your on-line r^2 values can be different from off-line values for various reasons.
The Matlab offline analysis tool calls the mem() function when performing data analysis as described in previous posts.

Alessandro

caranico
Posts: 7
Joined: 11 Oct 2011, 04:33

Re: ARFilter Spectral Estimation

Post by caranico » 18 Nov 2011, 04:15

really i'm trying to compare the value of the spectrum amblitude between online and offline analysis. i want a threshold value of the spectrum on the basis of the r^2 that i visualize during offline analysis, but i don't implemet it during online
operation.
if they call the same function the spectra output of the ARFilter could be the same of the offline analysis's spectra.
thank you for your answer
Nicoletta

mellinger
Posts: 1064
Joined: 12 Feb 2003, 11:06

Re: ARFilter Spectral Estimation

Post by mellinger » 18 Nov 2011, 10:17

The OfflineAnalysis tool uses the same function to compute spectra, as the online system does, but it calls it with slightly different settings. More precisely, it chooses the model order of the AR algorithm to be:

Code: Select all

modelOrd = 18+round(samplefreq/100);
So you might set the model order parameter in the online system to the same value in order to get similar results.

Regards,
Juergen

Locked

Who is online

Users browsing this forum: No registered users and 1 guest