Home > eeg > egis > spline > bayes_sphcoff.m

bayes_sphcoff

PURPOSE ^

function [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,xelec,yelec,zelec,v,lambda)

SYNOPSIS ^

function [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,xelec,yelec,zelec,v,lambda)

DESCRIPTION ^

function [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,xelec,yelec,zelec,v,lambda)

    calculates spherical harmonic coefficients based on jerry's notes on Bayesian formulation for linear systems

    nmax = maximum order allowed for spherical harmonic sequences. 
            recommended (maximum order for full rank model)
                        129 channel EGI system nmax = 8
    xelec = x locations of electrode array
    yelec = y locations of electrodes
    zelec = z location of electrodes
    v = data
    lambda = smoothing parameter (one day this will become noise)

    outputs
    sp_coff = spherical harmonic coefficients
    error_check = error estimate
    sp_mat = spherical harmonic matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,xelec,yelec,zelec,v,lambda)
0002 %function [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,xelec,yelec,zelec,v,lambda)
0003 %
0004 %    calculates spherical harmonic coefficients based on jerry's notes on Bayesian formulation for linear systems
0005 %
0006 %    nmax = maximum order allowed for spherical harmonic sequences.
0007 %            recommended (maximum order for full rank model)
0008 %                        129 channel EGI system nmax = 8
0009 %    xelec = x locations of electrode array
0010 %    yelec = y locations of electrodes
0011 %    zelec = z location of electrodes
0012 %    v = data
0013 %    lambda = smoothing parameter (one day this will become noise)
0014 %
0015 %    outputs
0016 %    sp_coff = spherical harmonic coefficients
0017 %    error_check = error estimate
0018 %    sp_mat = spherical harmonic matrix
0019 if ~(nargin == 5|nargin == 6)
0020     error('improper parameter list')
0021 end;
0022 
0023 [azelec,elelec,relec] = cart2sph(xelec,yelec,zelec);
0024 elelec = (pi/2)*ones(size(elelec,1),size(elelec,2)) - elelec;
0025 
0026 icount = 1;
0027 
0028 for j=1:nmax
0029     sp_mat(icount:icount+2*j,:) = sph_elec(xelec,yelec,zelec,j);
0030     icount = icount+2*j+1;
0031 end;
0032 
0033 if icount~= (nmax+1).^2 
0034     error('Dope')
0035 end;
0036 
0037 ls_mat = sp_mat*sp_mat';
0038 
0039 if nargin == 6
0040     for i = 1:size(ls_mat,1)
0041         ls_mat(i,i) = ls_mat(i,i) + lambda;
0042     end;
0043 end;
0044 
0045 lv_mat = sp_mat*v';
0046 
0047 sp_coff = ls_mat\ lv_mat;
0048 
0049 error = sp_mat'*sp_coff - v';
0050 
0051 error_check(1) = sum(abs(error))/129;
0052

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003