help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: detrend() in Matlab and Octave


From: Ben Abbott
Subject: Re: detrend() in Matlab and Octave
Date: Thu, 23 Dec 2010 10:17:53 -0500

On Dec 23, 2010, at 10:04 AM, Søren Hauberg wrote:

> ons, 22 12 2010 kl. 20:28 -0500, skrev Ben Abbott:
>>> The existing Octave 'detrend' should then remain with a different name -
>>> because it has features the Matlab one doesn't have.
>>> 
>>> Regards,
>>> Sergei.
>> 
>> No need. There isn't an inherent incompatibility for the differing features.
> 
> I've just pushed a changeset that also allows you to set the polynomial
> order as a string. That means you can do
> 
>  detrend (x, "constant")
>  detrend (x, "linear")
>  detrend (x, p)
> 
> where 'p' is any positive integer. The latter is the API used by Octave
> so far, while the two first allow for compatibility. So Octave 3.4
> should be compatible with Matlab while still supporting the "old" Octave
> interface.
> 
> Søren
> 
> P.S. Matlab also allows you to remove piecewise linear trends. I have
> not implemented this; it is left as an exercise to the reader ;-)

I took a look at Matlab's syntax for specifying break-points for a linear 
piecewise fit ...

        detrend (x, "linear", bp)

There seems to be a error/bug (?) in Matlab's implementation.

        x = rand (1, 7);
        dx = detrend (x);
        for n = 1:numel(x)
            dx(end+1,:) = detrend (x, 'linear', n);
        end
        dx

The first and second rows are identical, as would be expected. I'd expect the 
last row to be the same as the 1st/2nd. Instead it is the second to last that 
is the same.

dx =

   -0.3411    0.1029    0.1909    0.3028    0.0580   -0.2558   -0.0577
   -0.3411    0.1029    0.1909    0.3028    0.0580   -0.2558   -0.0577
   -0.0000   -0.1245    0.0317    0.2118    0.0353   -0.2103    0.0560
   -0.0514    0.1029   -0.0988    0.1290    0.0001   -0.1978    0.1161
   -0.1242    0.1511    0.0704    0.0135   -0.0625   -0.2076    0.1592
   -0.2298    0.1400    0.1538    0.1914   -0.1276   -0.2558    0.1279
   -0.3411    0.1029    0.1909    0.3028    0.0580   -0.2558   -0.0577
   -0.3219    0.1106    0.1871    0.2874    0.0311   -0.2943   -0.0000

Am I missing something? or is this a Matlab bug?

Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]