Re: Problems on the Savitzky-Golay smoothing filter [message #66474] |
Thu, 21 May 2009 00:28  |
mengran
Messages: 5 Registered: March 2009
|
Junior Member |
|
|
On 5月20日, 下午11时01分, Allard de Wit <allard.de...@wur.nl> wrote:
> On May 20, 12:59 pm, mengran <mengra...@gmail.com> wrote:
>
>
>
>> Hi,everybody,
>> I have got a annoying problem about the implementing the
>> Savitzky-Golay filter to smooth the time series RS data in the IDL.
>> Actually, I know the function of the Savitzky-Golay filter in IDL is
>> SAVGOL.But the question is the result I got is either a horizon line
>> or the same as the original line(In other words, the filter seems not
>> to work at all), when I changed the parameters of the SAVGOL function.
>> (when the DEGREE = NL + NR(PARA OF THE SAVGOL FUNCTION), THE RESULT
>> IS THE SAME AS THE ORIGINAL, OTHERWISE, THE RUSULT IS A HORISON LINE)
>> My pro is as follows. The class1 to class9 from txt files are
>> the samples of the time series RS data.
>> Is there sth wrong with my code ? Or the RS data that I used
>> is not appropriate for the Savitzky-Golay filter, and I take a wrong
>> method to smooth data ? I need your suggestions, thanks a lot !
>
>> PRO Savgol_example
>
>> ;RESTORE, 'C:\WorkSpace\Default\myPlotTemplate.sav'
>> rootPath = 'C:\WorkSpace\Default\class'
>
>> n = 1 & filename = strarr(9)
>> for i = 0, 8 do begin
>
>> filename[i] = strjoin([rootPath, strtrim(n, 2),'.txt'])
>> n++
>
>> endfor
>> for i = 0,8 do begin
>
>> plotTemplate = ASCII_TEMPLATE(filename[1])
>> y1 = READ_ASCII(filename[1], TEMPLATE = plotTemplate, COUNT =
>> $ count,NUM_RECORDS = 46 )
>> x = indgen(46)
>> iPlot,x,y1.FIELD1, NAME = 'Original Curve', $
>> COLOR=[255, 0, 0], SYM_INDEX = 4, yrange = [0,+8000], VIEW_TITLE =
>> strmid(filename[1], 21, 6)
>> void = ITGETCURRENT(TOOL=oTool)
>> void = oTool->DoAction('Operations/Insert/Legend')
>
>> ; savgol
>> savgolFilter = SAVGOL(2, 2, 0,4)
>> iPlot,x,CONVOL(y1.FIELD1, savgolFilter), /OVERPLOT, $
>> COLOR=[0, 0, 255], THICK=2, $
>> NAME='Savitzky-Golay'
>> void = oTool->DoAction('Operations/Insert/LegendItem')
>> ;SAVE, plotTemplate, FILENAME='C:\WorkSpace\Default
>> \myPlotTemplate.sav'
>
>> endfor
>
>> END
>
> Hi Mengran,
>
> I have an implementation of the Savitsky-Golay filter in IDL/ENVI
> based on this paper:
>
> Jin Chen, Per. Jonsson, Masayuki Tamura, Zhihui Gu, Bunkei
> Matsushita, Lars Eklundh. 2004.
> A simple method for reconstructing a high-quality NDVI time-series
> data set based on
> the Savitzky-Golay filter. Remote Sensing of Environment 91: 332-344
>
> If you are interested I can send you the code.
>
> Allard
Hi Allard,
Thank you very much! Could you please send me the code that you
mentioned above?
Mengran
|
|
|
Re: Problems on the Savitzky-Golay smoothing filter [message #66483 is a reply to message #66474] |
Wed, 20 May 2009 08:01   |
wita
Messages: 43 Registered: January 2005
|
Member |
|
|
On May 20, 12:59 pm, mengran <mengra...@gmail.com> wrote:
> Hi,everybody,
> I have got a annoying problem about the implementing the
> Savitzky-Golay filter to smooth the time series RS data in the IDL.
> Actually, I know the function of the Savitzky-Golay filter in IDL is
> SAVGOL.But the question is the result I got is either a horizon line
> or the same as the original line(In other words, the filter seems not
> to work at all), when I changed the parameters of the SAVGOL function.
> (when the DEGREE = NL + NR(PARA OF THE SAVGOL FUNCTION), THE RESULT
> IS THE SAME AS THE ORIGINAL, OTHERWISE, THE RUSULT IS A HORISON LINE)
> My pro is as follows. The class1 to class9 from txt files are
> the samples of the time series RS data.
> Is there sth wrong with my code ? Or the RS data that I used
> is not appropriate for the Savitzky-Golay filter, and I take a wrong
> method to smooth data ? I need your suggestions, thanks a lot !
>
> PRO Savgol_example
>
> ;RESTORE, 'C:\WorkSpace\Default\myPlotTemplate.sav'
> rootPath = 'C:\WorkSpace\Default\class'
>
> n = 1 & filename = strarr(9)
> for i = 0, 8 do begin
>
> filename[i] = strjoin([rootPath, strtrim(n, 2),'.txt'])
> n++
>
> endfor
> for i = 0,8 do begin
>
> plotTemplate = ASCII_TEMPLATE(filename[1])
> y1 = READ_ASCII(filename[1], TEMPLATE = plotTemplate, COUNT =
> $ count,NUM_RECORDS = 46 )
> x = indgen(46)
> iPlot,x,y1.FIELD1, NAME = 'Original Curve', $
> COLOR=[255, 0, 0], SYM_INDEX = 4, yrange = [0,+8000], VIEW_TITLE =
> strmid(filename[1], 21, 6)
> void = ITGETCURRENT(TOOL=oTool)
> void = oTool->DoAction('Operations/Insert/Legend')
>
> ; savgol
> savgolFilter = SAVGOL(2, 2, 0,4)
> iPlot,x,CONVOL(y1.FIELD1, savgolFilter), /OVERPLOT, $
> COLOR=[0, 0, 255], THICK=2, $
> NAME='Savitzky-Golay'
> void = oTool->DoAction('Operations/Insert/LegendItem')
> ;SAVE, plotTemplate, FILENAME='C:\WorkSpace\Default
> \myPlotTemplate.sav'
>
> endfor
>
> END
Hi Mengran,
I have an implementation of the Savitsky-Golay filter in IDL/ENVI
based on this paper:
Jin Chen, Per. Jonsson, Masayuki Tamura, Zhihui Gu, Bunkei
Matsushita, Lars Eklundh. 2004.
A simple method for reconstructing a high-quality NDVI time-series
data set based on
the Savitzky–Golay filter. Remote Sensing of Environment 91: 332–344
If you are interested I can send you the code.
Allard
|
|
|
Re: Problems on the Savitzky-Golay smoothing filter [message #66488 is a reply to message #66483] |
Wed, 20 May 2009 05:03   |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
mengran wrote:
> Hi,everybody,
> I have got a annoying problem about the implementing the
> Savitzky-Golay filter to smooth the time series RS data in the IDL.
> Actually, I know the function of the Savitzky-Golay filter in IDL is
> SAVGOL.But the question is the result I got is either a horizon line
> or the same as the original line(In other words, the filter seems not
> to work at all), when I changed the parameters of the SAVGOL function.
> (when the DEGREE = NL + NR(PARA OF THE SAVGOL FUNCTION), THE RESULT
> IS THE SAME AS THE ORIGINAL, OTHERWISE, THE RUSULT IS A HORISON LINE)
> My pro is as follows. The class1 to class9 from txt files are
> the samples of the time series RS data.
> Is there sth wrong with my code ? Or the RS data that I used
> is not appropriate for the Savitzky-Golay filter, and I take a wrong
> method to smooth data ? I need your suggestions, thanks a lot !
> savgolFilter = SAVGOL(2, 2, 0,4)
Hi Mengran,
so, print, savgolFilter --> 0.000000-8.04663e-007
1.00000-8.04663e-007 0.000000
meaning that the outer points have no effect, the central point has a
weight of 1 and the 2 middle points have a weight fairly close to
zero... so, from this, we can already suspect the smooth curve to be
similar to the original one.
Now, in convol, it is said that the kernel is "converted to the proper
type", in function of your input. So, if you are plotting integers, the
kernel is first converted to long... so the weights become 0,0,1,0,0
... and convol returns the same values as in the input!
Moreover, when you play with the degree, you get the following filters:
IDL> print, SAVGOL(2, 2, 0,3)
-0.0857143 0.342857 0.485714 0.342857 -0.0857143
IDL> print, SAVGOL(2, 2, 0,2)
-0.0857143 0.342857 0.485714 0.342857 -0.0857143
..once rounded, they are all zero... giving a nice horizontal line at zero!
Therefore, I would bet it is a problem with the input type... try to
convert it to float or double before applying the filter
Jean
|
|
|
|