## ARFilter Spectral Estimation

### ARFilter Spectral Estimation

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!

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!

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).

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.Furthermore, what is the significance, if any, in using one OutputType over another for BCI control?

HTH,

Juergen

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.

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)

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.

### Re:

This was extremely helpful also to me. Thank you so much.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)

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

### Re: ARFilter Spectral Estimation

Hi Alessandro,

the mem mex file allows you to specify windowing as well:

Regards,

Juergen

the mem mex file allows you to specify windowing as well:

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).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)

Regards,

Juergen

### Re: ARFilter Spectral Estimation

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:

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

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;
```

Alessandro

### Re: ARFilter Spectral Estimation

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

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

### Re: ARFilter Spectral Estimation

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

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

### Re: ARFilter Spectral Estimation

Hey Nicoletta,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

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

### Re: ARFilter Spectral Estimation

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

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

### Re: ARFilter Spectral Estimation

Your on-line r^2 values can be different from off-line values for various reasons.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

The Matlab offline analysis tool calls the mem() function when performing data analysis as described in previous posts.

Alessandro

### Re: ARFilter Spectral Estimation

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

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

### Re: ARFilter Spectral Estimation

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:
So you might set the model order parameter in the online system to the same value in order to get similar results.

Regards,

Juergen

Code: Select all

`modelOrd = 18+round(samplefreq/100);`

Regards,

Juergen

### Who is online

Users browsing this forum: No registered users and 1 guest