3.0

3.0 | 2 ratings Rate this file 113 downloads (last 30 days) File Size: 7 KB File ID: #19099

Tidal fitting toolbox

by Aslak Grinsted

 

07 Mar 2008 (Updated 13 Mar 2008)

No BSD License  

fit tidal components to an observed series of sea level and use them for prediction

Download Now | Watch this File

File Information
Description

* Fitting of tidemodels to e.g. sea level data.
* Predictions of tide based on tide model.

Uses familar syntax from polyfit/polyval: tidalfit/tidalval

 % TIDALFIT: Fits a tidal model to data
 
  tidalfit uses the HAMELS (ordinary least squares)
  technique to fit tidal components to the detrended data. Additionally it
  can also do robust fitting.
 
  Please include an acknowledgement to Aslak Grinsted if you use this code.
 
  USAGE: tidal=tidalfit(data[,parameter,value])
 
  INPUT:
  ------
  data: A two column vector.
  \ - first column should be a serial date number (See help datenum)
  \ - second column should be the y-values (i.e. sea level)
  \ (missing values and nans are OK.)
 
  OPTIONAL PARAMETERS:
  --------------------
  Components: cell-array of strings with names of the which
  \ components should be included in the fit? (ALL is default)
  \ Note: The routine will only attempt to fit components
  \ that have period<data_timespan/4 and period>dt*2.
  FittingMethod: 'OLS' for ordinary least squares or 'ROBUST' for robustfitting.
  \ (default=OLS)
  RobustFitOptions: cell of options for robustfit. (See help robustfit.)
  \ only used if FittingMethod='ROBUST'. (default={})
  DetrendData: should the data be detrended prior to fitting? (default=true)
 
  Note: optional parameters can be specified using abbreviations. e.g. RFO for RobustFitOptions.
 
  OUTPUT:
  -------
  If no output arguments are specified the routine will display the results
  visually.
 
  tidal: A struct-array containing the fitted model parameters.
  \ .name: name of tidal component (see e.g. http://www.mhl.nsw.gov.au/www/tide_glossary.htmlx)
  \ .period:period of tidal component in days
  \ .speed: frequency of tidal component in degrees per solar hour
  \ .amp: amplitude of fitted component
  \ .phase: phase of fitted component
 
  Components that are not included in the fit will have NaN in .amp and .phase.
  
 
  Note: In addition to the tradtional tidal components some components that
  accounts for the annual cycle are included. Called S3A, S4A, S5A, with
  periods of a year/3, year/4, year/5, ...
 
  EXAMPLE:
   data=datenum(1971,1,1):datenum(2008,1,1);
   data=[data;randn(size(data))]';
   tidal=tidalfit(data,'fm','robust');
   future=[datenum(2008,1,1):datenum(2009,1,1)'];
   plot(future,tidalval(tidal,future));

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Secrets of the Tide: Tide & Tidal Current Analysis ...

Required Products Statistics Toolbox
MATLAB release MATLAB 7 (R14)
Zip File Content  
Other Files tidalfit.m,
tidalval.m,
dispmtx.m,
parseArgs.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
10 Mar 2008 Carlos Adrián Vargas Aguilera

The help needs some improvements, for example, it is important to say that you use POLYFIT to fill NaN's, and other things, such as why define constants from a product of constants?. But, my question is: do you know the T_TIDE toolbox by Rich Pawlowicz? It will be usefull to compare both toolboxes.

11 Mar 2008 Aslak Grinsted

I do not use polyfit to fill nans (i use it to detrend the data prior to fitting). and i do not use the t_tide toolbox. The reason i acknowledge him is because i used some ideas i got from one of his pdf's.

11 Mar 2008 w s

I think that the first rating is too low. IMO this submission meets is all criteria of a GOOD submission. There is a help, commenting and vectorized code. I did not check on correctness of results since I am not familiar with tidal modelling.

Why is it only good?

First, there are some lines that Aslak probably forgot to remove before submitting the file, e.g.

if nargin<1
    data=readsl('d242a.dat');
end

This should be removed since neither the function nor the file are available.

Second, as the first reviewer noticed the help needs some improvement. I did not understand the output until looking at the code itself, where a reference to a huge number of parameters is given. This should be given in the help itself.

Third, there is no error checking. tidalfit also works with tidalfit(magic(5)) which most likely produces nonsense.

11 Mar 2008 Carlos Adrián Vargas Aguilera

That's why the 2 stars: "Needs Improvements", It doesn't mean that it shouldn't be downloaded, but if you do so, you'll have to do a little research on some web pages written somewhere by the author to know exactly how the analysis is done. That's all.
 In my opinion the program should speak by itself. There are several Toolboxes on Tides on the web and they are totally explained, why this one not? When it does it, then an "Excellent" won't be a problem.

11 Mar 2008 w s

Carlos, you are absolutely right. I think in general, however, one should not take the rating texts too verbal. Everything, that is not excellent needs improvement. Hence a fair and good actually do not exist. I just tried to find something inbetween since there are many poor submissions that are rated a two. And this one here is much better.

12 Mar 2008 Aslak Grinsted

Thanks for the comments. I've just improved the code and help significantly along the lines of the propositions.

13 Jun 2009 madamode mode

can any budy help me with this program pleas

Please login to add a comment or rating.
Updates
12 Mar 2008

Cleared all mlint messages.

13 Mar 2008

mathworks didn't update the file correctly last time, so i have to re-upload it again. (It is still the old zip file but description has changed.)

Tag Activity for this File
Tag Applied By Date/Time
tidal model Aslak Grinsted 22 Oct 2008 09:52:24
tides Aslak Grinsted 22 Oct 2008 09:52:24
sea level Aslak Grinsted 22 Oct 2008 09:52:24
fitting Aslak Grinsted 22 Oct 2008 09:52:24
prediction Aslak Grinsted 22 Oct 2008 09:52:24
tidal analysis Aslak Grinsted 22 Oct 2008 09:52:24
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com