Home > NoiseTools > nt_mmx.m

# nt_mmx

## PURPOSE

[y,abscissa]=nt_mmx(x, N) - calculate min-max pairs

## SYNOPSIS

function [y,abscissa]=nt_mmx(x,N)

## DESCRIPTION

    [y,abscissa]=nt_mmx(x, N) - calculate min-max pairs

      y: array or matrix of min-max pairs

      x: data
      N: target number of pairs (default: 1000 (or size(x,1) if smaller)

      To plot x cheaply: plot(mmx(x)).
      To get only maxima: y=mmx(x); y(2:2:end);

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_mmx [y,abscissa]=nt_mmx(x, N) - calculate min-max pairs

This function is called by:

- nt_mmx [y,abscissa]=nt_mmx(x, N) - calculate min-max pairs
- nt_plot_mmx nt_plot_mmx - plot data using min-max pairs

## SOURCE CODE

    0001 function [y,abscissa]=nt_mmx(x,N)
    0002 %[y,abscissa]=nt_mmx(x, N) - calculate min-max pairs
    0003 %
    0004 %  y: array or matrix of min-max pairs
    0005 %
    0006 %  x: data
    0007 %  N: target number of pairs (default: 1000 (or size(x,1) if smaller)
    0008 %
    0009 %  To plot x cheaply: plot(mmx(x)).
    0010 %  To get only maxima: y=mmx(x); y(2:2:end);
    0011
    0012 if nargin<2; N=1000; end
    0013
    0014 if ndims(x)==3;
    0015     y=nt_mmx(x(:,1,1)); % to get size
    0016     y=zeros(size(y,1),size(x,2),size(x,3));
    0017     for k=1:size(x,3)
    0018         [y(:,:,k),abscissa]=nt_mmx(x(:,:,k),N);
    0019     end
    0020     return
    0021 end
    0022
    0023 [m,n]=size(x);
    0024
    0025 if m<2*N
    0026     y=zeros(2*m,n);
    0027     for k=1:n
    0028         xx=x(:,k);
    0029         xx=[xx,xx]';
    0030         xx=xx(:);
    0031         y(:,k)=xx;
    0032     end
    0033 else
    0034     N=ceil(m/floor(m/N));
    0035     K=ceil(m/N);
    0036     y=zeros(2*N,n);
    0037     for k=1:n
    0038         xx=x(:,k);
    0039         xx(m:K*N)=xx(m);
    0040         xx=reshape(xx,K,N);
    0041         xx=[min(xx,[],1);max(xx,[],1)];
    0042         xx=xx(:);
    0043         y(:,k)=xx;
    0044     end
    0045 end
    0046
    0047 abscissa=linspace(0, m, 2*N);
    0048