Defining and Computing Features

Features can be defined using a convenient cell array structure that contains a series of MATLAB commands to execute. For example, the calculation of AR features according to Section 10.4.10 is given by:
    % define AR model order, proportional to segment size:
    nfeat=length(Ns);
    PMAX=32;
    Ps    =   ceil(Ns/max(Ns)*PMAX);

    % define feature module function calls and inversion calls -
    % each set of calls must assume input data is in 'x' and
    % outpus are 'z' and 'jout'
    for i=1:nfeat,
        func_str{i}{1}='E0=1; % indicate that we use sig2, not r0';
        func_str{i}{2}=['P=' num2str(Ps(i)) ';'];
        func_str{i}{3}='[a,jout]=module_ar_mlx(x,0,P,E0);';
        func_str{i}{4}='[k,jout]=module_ar2rc(a,jout);';
        func_str{i}{5}='[z,jout]=module_bilinear(k,jout);';

        inv_str{i}{1}='E0=1; % indicate that we use sig2, not r0';
        inv_str{i}{2}=['N=' num2str(Ns(i)) ';'];
        inv_str{i}{3}='k=module_bilinear_synth(z);';
        inv_str{i}{4}='r=module_acf2rc_synth(k,E0);';
        inv_str{i}{5}='y=module_acf_synth(r,N);';
        inv_str{i}{6}='x=module_dftmsq_synth(y,N);';
    end;
Notice that both the feature chain and inversion chain are defined. Once the chains are defined, you can use the function software/mrhmm_compute_features.mto compute the features. Let X be a cell array, with a time-series (called an event) in each entry. Then, the call
 [Z,J]=mrhmm_compute_features(X,func_str,Ns,K,shfts,max_segment_size);
produces the cell array output Z such that Z{isamp}{ifeat} is a dim-by-n array of output features, where isamp is the index of the time-series event, ifeat is the feature index (first index into func_str), and dim is the feature dimension (P+1 for AR features). Each of the n columns of the output array is the feature vector for a different time shift in increments of shfts(ifeat) samples. The J-function output J{isamp}{ifeat} is similarly defined, but is of dimension 1-by-n. The variable max_segment_size is also provided as a check to insure that all data events are of a length divisible by max_segment_size.