Ignore:
Timestamp:
Apr 30, 2014, 3:56:19 PM (11 years ago)
Author:
sommeria
Message:

signal spectrum updated : allow restrictions in index

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/transform_field/signal_spectrum.m

    r753 r759  
    7373%% get the variable to process
    7474Var= DataIn.(Param.TransformInput.VariableName);%variable to analyse
     75if isfield(Param.TransformInput,'IndexRange')
     76    IndexRange=Param.TransformInput.IndexRange;
     77    switch size(IndexRange,1)
     78        case 3
     79            Var=Var(IndexRange(1,1):IndexRange(1,2),IndexRange(2,1):IndexRange(2,2),IndexRange(3,1):IndexRange(3,2));
     80        case 2
     81            Var=Var(IndexRange(1,1):IndexRange(1,2),IndexRange(2,1):IndexRange(2,2));
     82        case 1
     83            Var=Var(IndexRange(1,1):IndexRange(1,2));
     84    end
     85end
    7586np=size(Var);%dimensions of Var
    7687if ~isvector(Var)
    7788    Var=reshape(Var,np(1),prod(np(2:end)));% reshape in a 2D matrix with time as first index
    7889end
    79 Var=Var-ones(np(1),1)*nanmean(Var,1); %substract mean value (excluding NaN)
     90Var=Var-ones(np(1),1)*nanmean(Var,1); %substract mean value (excluding NaN) 
    8091
    8192%% look for 'time' coordinate
     
    117128        if ~isempty(ind_bad)||check_interp
    118129            sample=interp1(Time(ind_good),sample,(Time(1):dx:Time(end))); %interpolated func
     130            sample(isnan(sample))=[];
    119131        end
    120132        spec=pwelch(sample,WindowLength);% calculate spectrum with Welch method
     
    144156legend({'spectrum','cospectrum t t-1'})
    145157get(gca,'Unit')
     158sum(specmean)
     159sum(cospecmean)
    146160if NbPos~=size(Var,2)
    147161    disp([ 'warning: ' num2str(size(Var,2)-NbPos) ' NaN sampled removed'])
Note: See TracChangeset for help on using the changeset viewer.