Skip to content

sig.data

Olivier Lartillot edited this page Sep 20, 2018 · 2 revisions

Description

The sig.data class adds a syntactic layer on top of Matlab that makes operators' code simpler. It it internally called by all operators available to users in SigMinr, AudMinr and audio-based approaches in MusMinr, as well as by sig.read.

Properties

A sig.data object contains the following properties:

  • content: the actual data as a numeric array or cell array.
  • dims: a description of the dimensions of the array represented in content.
  • layers
  • multioutput

Syntax

sig.data(content,_dims)

Methods

apply

sig.data.apply applies a routine to a data, reformatting it if necessary so that its dimensions correspond to the given dimensions specification.

Syntax

d.apply(routine,args,dimfunc,maxdimfunc,type) where

  • d is the sig.data object to which the routine will be applied
  • routine is the function handler to the routine
  • args is a cell array of secondary arguments also sent to the routine
  • dimfunc is a cell array of dimension names, corresponding to the required format of the data, as considered in the routine. Dimension names are indicated in the dimension order commonly used in Matlab (raw, column, etc.)
  • maxdimfunc is the maximal number of dimensions accepted for the data as considered in the routine. If d has a higher number of dimensions, d is decomposed into a series of subarrays of dimension maxdimfunc.
  • type indicates whether the data content is an array (type == '()') or a cell array (type == '{}')

If args is of the form {arg1,arg2,etc.}, routine should be of the form:

function out=routine(d,arg1,arg2,etc.)

Examples

aud.brightness

function out = routine(d,f,f0)
    e = d.apply(@algo,{f,f0},{'element'},3);
    out = {e};
end


function y = algo(m,f,f0)
    y = sum(m(f > f0,:,:)) ./ sum(m);
end

In thealgo routine, the m matrix is of maximal dimension 3, and the first dimension correspond to 'element'.

sig.rms

function out = after(x,option)
    if iscell(x)
        x = x{1};
    end
    if ~option.median
        if find(strcmp('element',x.Ydata.dims))
            dim = 'element';
        else
            dim = 'sample';
        end
        x.Ydata = sig.compute(@routine_norm,x.Ydata,x.Ssize,dim);
    end
    out = {x};
end

function d = routine_norm(d,Ssize,dim)
    d = d.apply(@afternorm,{Ssize},{dim},Inf);
end


function d = afternorm(d,l)
    d = sqrt(d/l);
end

In theafternorm routine, the d matrix can be of any dimension, and the first dimension correspond to 'element' if this dimension exists in x, or 'sample' in the other case.

Clone this wiki locally