Path: news.mathworks.com!not-for-mail
From: "Carlos Adrian Vargas Aguilera" <nubeobscura@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: data fitting / data analysis - spline?
Date: Wed, 10 Sep 2008 02:12:02 +0000 (UTC)
Organization: Universidad de Guadalajara
Lines: 39
Message-ID: <ga7adi$g1f$1@fred.mathworks.com>
References: <g9k761$d2h$1@fred.mathworks.com> <g9pib5$je2$1@fred.mathworks.com>
Reply-To: "Carlos Adrian Vargas Aguilera" <nubeobscura@hotmail.com>
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 1221012722 16431 172.30.248.37 (10 Sep 2008 02:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 10 Sep 2008 02:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869698
Xref: news.mathworks.com comp.soft-sys.matlab:489469



"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <g9pib5$je2$1@fred.mathworks.com>...
> "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
> 


This is an ideal filter, but is the worst way to do a filtering. You are applying a weighting/multiplication rectangular window in frequency domain, which is a smoothing/convolution SINC window in the time domain with huge sidelobes and Gibb's phenomena.

Take a look to WINSINC here at the FileExchange:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8574

Carlos Vargas