Path: news.mathworks.com!not-for-mail
From: "Miroslav Balda" <miroslav.nospam@balda.cz>
Newsgroups: comp.soft-sys.matlab
Subject: Re: data fitting / data analysis - spline?
Date: Thu, 4 Sep 2008 21:01:25 +0000 (UTC)
Organization: Miroslav Balda
Lines: 30
Message-ID: <g9pib5$je2$1@fred.mathworks.com>
References: <g9k761$d2h$1@fred.mathworks.com>
Reply-To: "Miroslav Balda" <miroslav.nospam@balda.cz>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220562085 19906 172.30.248.37 (4 Sep 2008 21:01:25 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Sep 2008 21:01:25 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 360709
Xref: news.mathworks.com comp.soft-sys.matlab:488662



"Mario " <nospam@yahoo.com> wrote in message
<g9k761$d2h$1@fred.mathworks.com>...
SNIP

Hi Mario,

Nobody answered yet, newertheless there is a solution in
Fourier transform and a filtration in frequency domain. Test
this code:

load dataxy; % the downloaded data - signal
x = xy(:,1);
y = xy(:,2);
m = length(x);
A = [ones(m,1),x];
c = A\y % coeffitients of best linear fit
yc = y - A*c; % detrended signal
Yc = fft(yc); % DFT of the signal
n  = 20; % chosen number of low frequency components
Yf = [Yc(1:n); zeros(m-2*n,1); Yc(end-n+1:end)];% filt. DFT
yf = real(ifft(Yf)); % filtered signal
yr = yf + A*c; % regressed y
plot(x,y, x,yr,'r')
grid

The bigger is n the better approximation you get.
Hope this helps.

Mira