Description: This sounds at first like a trivial task, but in practice took something that works correctly and faster for larger datasets (i.e. without using a simple find or related statement each time within a for loop). Thus I am submitting this here in case it might the time of anyone else with similar needs who comes across this.
Help comments for the function: %function [OutVals fout]=AvgAcrossFreqs(InVals,fraw,fstep,fk,f0cut,CalcType) % % Will Avg InVals across the freq vals give in fraw into the output % frequency bins separated by fstep with range given by fk, and initial bin % determined by f0cut. % % This could of course be applied generally to average any one value over % another, but was written with the intention of averaging coherence or % spectral power values across frequencies in a data format with multiple % repetitions (for example multiple subjects or experiment sessions). % % Inputs % InVals: The values to be averaged across. Could be a single % numeric array, of dimension NReps x nRawf, or could be % a 1D cell array of any number of such a numeric array. % fraw: A 1D vector of length nRawf (matching the 2nd % dimension of numeric arrays of InVals) indicating the % input freequency correspnding to each val of InVals. % Assuemd to be in Hz though any freq unit could be used % if the other inputs are consistent with that unit. % fstep: The frequency resolution (in Hz) of the output that the % InVals are averaged into. Defaults to 1/8. % fk: A 1x2 or 2x1 vector indicating the output frequency % range to use. Defaults to [0 100]. % f0cut: Indicates the upper cutoff frequency used for the % first bin. ... so the first output bin frequency will % avg InVals from fk(1) up to f0cut, and each output bin % will increase in fstep steps from there. Defaults to % fstep/2. % CalcType: Indicates how to do the averaging. This can be a % scalar, or if InVals is a cell array, a 1D vector with % each value corresponding to each cell in InVals. This % can also be a scalar if InVals is a cell array, in % which case the value will apply to all cells of InVals. % case: % 1 corresponds to a basic nanmean. (for coh mags, abs % vals should be done to the input BEFORE CALLING % this function.) (This is the Default) % 2: any function. % 3: sum function % 4: angle of the sum across frequencies % 5: angle of the sum across repetitions and % frequencies. Note that this affects the size of % OutVals, by forcing it to have 1 row/rep. % % Outputs % OutVals: A numeric array or CellArray corresponding to InVals. % Each numeric array will have dimensions nReps x nfout. % (Or possible 1 x nfout if CalcType is set to 5). % fout: The output frequencies, corresponding to the center % frequency of each frequency bin in OutVals. % % Matthew Nelson 2010 % nelsonmj@caltech.edu http://www.its.caltech.edu/~nelsonmj/
License: Shareware Related: inputs, consistent, correspnding, assuemd, Resolution, defaults, increase, steps O/S:BSD, Linux, Solaris, Mac OS X File Size: 10.0 KB Downloads: 1

