1 Introduction

Tidal heights or currents at a location with a single tidal constituent frequency ω can be described as follows:

$$ u(t)=a\cos \left(\omega \kern0.1em t-\phi \right) $$
(1)

where a and ϕ are the amplitude and the phase lag, respectively, and the value of ω can be assigned based on astronomic knowledge. The amplitude and phase lag at one location are constant in time; therefore, they are also collectively referred to as tidal harmonic constants (THCs). Often, interpolations of THCs must be performed. For example, given two pairs of THCs at two locations, say (a 1, ϕ 1) and (a 2, ϕ 2) at x 1 and x 2, we may want to interpolate them to obtain a new pair of THCs at a point somewhere in between.

An incorrect approach is to interpolate the amplitudes and phase lags linearly and separately. For amplitude, one might calculate as follows:

$$ a=\alpha {a}_1+\beta {a}_2 $$
(2)

where α and β are interpolation weights, and their sum is equal to one. For phase lag, one might calculate as follows:

$$ \left(\cos \phi, \sin \phi \right)=\left(\alpha \cos {\phi}_1+\beta \cos {\phi}_2,\alpha \sin {\phi}_1+\beta \sin {\phi}_2\right) $$
(3)
$$ \phi =\mathrm{atan}2\left(\sin \phi, \cos \phi \right) $$
(4)

where atan2 is an inverse function of the tangent and provides angles ranging from −π to π (e.g., Park et al. (2012)). However, this is not correct as we will see in the next section. This incorrect approach could even be carried over to intenerating tidal current ellipse parameters (Byun and Hart 2017). To clarify the confusion, this note is dedicated to presenting correct THC interpolants.

The next section will derive correct THC interpolants. The “Examples” section will provide examples for 1-D and 2-D interpolations to demonstrate how the interpolants are applied and to illustrate the differences from the results obtained using the incorrect interpolants as of Eqs. (2), (3), and (4). Five MATLAB functions for the THC interpolations are presented in Appendix.

2 Nonlinear and coupled interpolants for THCs

This section derives two interpolants for amplitudes and phase lags, respectively. The interpolants will be nonlinear and coupled in term of given amplitudes and phase lags (ap-parameters). The starting point for the derivation is a linear interpolation in terms of the time functions of tidal heights or currents as expressed by Eq. (1). It is emphasized here from the outset that to have a linear interpolation in the time domain, one has to perform a nonlinear interpolation in the ap-parameters domain (which may also be referred as the spectrum domain). This is understandable because the ap-parameters work together nonlinearly to affect tidal heights and currents.

Suppose that at x = x 1 and x = x 2 (assuming x 2 > x 1), two pairs of THCs, (a 1,  ϕ 1) and (a 2,  ϕ 2), are known, with which we can describe tidal height (or a current component) at these two locations as follows:

$$ {u}_1(t)={a}_1\cos \left(\omega \kern0.1em t-{\phi}_1\right), $$
(5)
$$ {u}_2(t)={a}_2\cos \left(\omega \kern0.1em t-{\phi}_2\right). $$
(6)

Also, suppose that we would like to know u(t) at x somewhere in between x 1 and x 2 by a linear interpolation of u 1(t) and u 2(t), i.e.,

$$ u(t)=\alpha {u}_1(t)+\beta {u}_2(t) $$
(7)

where α and β are interpolation weights, with α = (x 2 − x)/(x 2 − x 1) and β = 1 − α (interpolation in the time domain). Further, assume that we do not wish to perform interpolation for every point of time; rather, we wish to perform interpolation once and directly on the two pairs of THCs to obtain a new pair of THCs at x (interpolation in the spectrum domain). When the new pair of THCs interpolated from the spectrum domain is inserted into Eq. (1), the resulting time series u(t) will be identical to the one interpolated in the time domain using Eq. (7). This is the mathematical setup for the problem. Now, let us solve it.

In fact, it can be easily solved by expanding Eq. (7) as follows:

$$ u=\left(\alpha {a}_1\cos {\phi}_1+\beta {a}_2\cos {\phi}_2\right)\cos \omega \kern0.1em t+\left(\alpha {a}_1\sin {\phi}_1+\beta {a}_2\sin {\phi}_2\right)\sin \omega \kern0.1em t $$
(8)

Equation (1) can be rewritten as follows:

$$ u(t)=a\cos \phi \cos \omega \kern0.1em t+a\sin \phi \sin \omega \kern0.1em t. $$
(9)

By equating the coefficients of cosωt and sinωt from the right-hand sides of the above two equations, we obtain the following:

$$ a\cos \phi =\alpha {a}_1\cos {\phi}_1+\beta {a}_2\cos {\phi}_2 $$
(10)
$$ a\sin \phi =\alpha {a}_1\sin {\phi}_1+\beta {a}_2\sin {\phi}_2 $$
(11)

from which we can solve for a and ϕ as follows:

$$ \phi =\kern1em \mathrm{atan}2\left(\alpha {a}_1\sin {\phi}_1+\beta {a}_2\sin {\phi}_2,\kern1em \alpha {a}_1\cos {\phi}_1+\beta {a}_2\cos {\phi}_2\right) $$
(12)
$$ a=\frac{\alpha {a}_1\sin {\phi}_1+\beta {a}_2\sin {\phi}_2\;}{\sin \phi}\kern0.5em $$
(13)
$$ \kern0.5em \overset{or}{=}\ \frac{\alpha {a}_1\cos {\phi}_1+\beta {a}_2\cos {\phi}_2\;}{\cos \phi}\kern0.5em $$
(14)

Note that by using atan2 (in MATLAB) instead of atan in Eq. (12), the amplitude a values in Eqs. (13) and (14) are guaranteed to be positive. Equations (12) and (13) (or Eq. (14)) are the correct interpolants to interpolate THCs. The time series reconstructed from so interpolated THCs will observe the linear interpolation in the time domain as specified in Eq. (7). This will not be the case if Eqs. (2) to (4), or any other formulas, are used as interpolants instead.

When 2-D interpolations are required, the 1-D interpolation can be applied in one direction first, and the results can be further interpolated in another direction. This process will be illustrated in examples 2 and 3 in the next section.

This paper is meant as a short note paper and could end here now. However, to help readers better intuit the problem and observe the consequences of correct and incorrect interpolations graphically, some examples are provided in the next section. The examples will also bring in MATLAB functions for THC interpolation, which should be useful for ocean modelling community.

3 Examples

This section shows three examples, one for a 1-D interpolation and two for 2-D interpolations. Five MATLAB functions listed in Appendix for the THC interpolations will also be briefly introduced.

3.1 Example 1: 1-D interpolation

Let ω = 2π/T with T = 12 h for the semi-diurnal frequency, let a 1 = 1.50 m and ϕ 1 = 45.00 deg at x 1 = 0, let a 2 = 2.00 m, and ϕ 2 =  − 45.00 degat x 2 = 1 (the unit of the coordinates is understood because it is not relevant to the interpolation problem here). Suppose at x i  = 0.6, we want to know the THCs by interpolation. First, we need to calculate the interpolation weights of α and β according to the following:

$$ \alpha =\frac{x_2-{x}_i}{x_2-{x}_1},\kern0.5em $$
(15)
$$ \beta =1-\alpha =\frac{x_i-{x}_1}{x_2-{x}_1}. $$
(16)

By substituting the given x 1, x 2, and x i , we have α = 0.35 and β = 0.65. With the given (a 1,  ϕ 1) and (a 2,  ϕ 2), we then have the following:

$$ \phi =\mathrm{atan}2\left(\hbox{-} 0.5480,\kern0.5em 1.2905\right)=\kern0.5em -\kern0.5em 0.4016\kern0.5em =-\kern0.5em 23.0089\deg\ \overset{\mathrm{or}}{=}336.9911\deg $$
(17)
$$ \mathrm{a}=-0.5480/\left(-0.3909\right)=1.4020\ \mathrm{m} $$
(18)

In comparison, using the interpolants of Eqs. (2)–(4), we obtain values of a = 1.8250 m and \( \phi =-16.6992\kern0.2em \deg \overset{\mathrm{or}}{=}343.3008\kern0.2em \deg \), which differ greatly from the correct values.

Figure 1 shows the four time series of u 1 and u 2 and two versions of the interpolated u i that represent the correct and incorrect versions. The green curve (the correct interpolation) always remains between the two data curves (blue and black), which is most evident when the green curve runs through the points where the black and blue curve intersect. This is what we expect from a liner interpolation in the time domain between the two data curves. If linear interpolation is performed for every point of time according to Eq. (7), the result will be the same as the green curve. However, the red curve (the incorrect interpolation) sometimes travels even beyond the envelope of the two data curves; in fact, it violates the liner interpolation required by Eq. (7) all the time.

Fig. 1
figure 1

Four time series of u 1 and u 2 and two versions of u i that represent the correct and incorrect interpolations. The correct interpolation (green) is reconstructed from the amplitude and phase lags interpolated using Eqs. (12) and (13). The incorrect interpolation (red) is reconstructed using Eqs. (2)–(4)

List 1 and List 2 in Appendix are two MATLAB functions interp1_w and THCinterp1, which are used for this example. The function interp1_w calculates the interpolation weights of the given coordinates for a set of data points (x) and coordinates for the interpolation points (x i ). The function THCinterp1 implements the 1-D interpolation using Eqs. (12) and (13).

3.2 Example 2: 2-D interpolation of amplitudes and phase lags

This example demonstrates how the 1-D interpolants can be extended for a 2-D interpolation. The top two panels of Fig. 2 show amplitudes (left panel) and phase lags (right panel), with the original THC data defined on the grid points printed in blue. The interpolation problem here is to interpolate the original THC data on to the centers of the cells as indicated by the circles. The MATLAB function THCinterp2mat in List 3 of Appendix is used for interpolation. It applies the 1-D interpolants of Eqs. (12) and (13) twice. The first application is in the x-direction, where the amplitudes and phase lags on each of the horizontal lines are interpolated to the middle points of each segment marked by the “x” on the horizontal lines. With the interpolated amplitudes assigned on the “x” points, the 1-D interpolation is applied again but in the y-direction. In terms of spatial coverage, this bi-directional approach is the same as a standard bi-linear interpolation in the sense that they both apply a one-dimensional interpolant twice. However, in terms of interpolants used, the bi-directional approach proposed here is different from the standard bi-linear interpolation. The former uses a nonlinear interpolant, and the latter uses a linear interpolant.

Fig. 2
figure 2

2-D interpolation of tidal harmonic constants. The top left and right panels show amplitudes and phase lags, respectively. The original data are shown in blue on the corners of the cells, and interpolated data are shown in green and red in the centers of the cells. The green values are correctly interpolated using Eqs. (12) and (13), and the red values are incorrectly interpolated using Eqs. (2) and (4). Using the correct and incorrect amplitudes and phase lags shown in centers of the two shaded cells, we can reconstruct two versions of time series. The correct one in green and the incorrect one in red are shown together with the four data time series reconstructed using the original data shown on the four corners of the same cells. The incorrectness of the red curve becomes evident when it moves out of scope of the four data curves. The green curve consistently remains in between the four data curves.

The interpolated results are printed in green beneath the circle points. For comparison, the results obtained using the incorrect 1-D interpolants of Eqs. (2)–(4) in the above bi-directional approach are also printed in red above the circles. To see how the time series will differ using these correct and incorrect THCs, let us focus on the shaded cell on the second row and fourth column of the top two panels. From the correctly and incorrectly interpolated amplitudes and phase lags shown in the middle of the cell, we can reconstruct two versions of the time series. We can also use the amplitudes and phase lags shown on the four corners of the cell to reconstruct four data time series. All the time series are shown in the bottom panel in green, red and gray, respectively. Since the interpolation point is in the center of the cell, the correct interpolated value is an arithmetical average of the four gray curves at each time step, as is the case with the green curve. The red curve is clearly incorrect.

The function THCinterp2mat assumes that xx and yy are gridded data coordinates and the interpolation points of xxi and yyi are also gridded. There are also cases where we need to interpolate from gridded data points to irregular points. The MATLAB function THCinterp2 provided in List 4 in Appendix satisfies this need. This function also works for cases where the interpolation points are gridded points as well; however, the computational speed will be slightly slower than using THCinterp2mat. Interpolations from irregular points to irregular points can be also considered but are not addressed further here.

3.3 Example 3: 2-D interpolation of tidal current ellipse parameters

For tidal current, we can generally neglect its weak vertical component and focus on its two strong horizontal components, u and v. Referring to Eq. (1), we see that to describe u and v, we need two pairs of parameters, (a u , ϕ u ) and (a v , ϕ v ). Interpolations on these ap-parameters can be performed with Eqs. (12) and (13), following the procedures illustrated by the above two examples.

On the other hand, by plotting v against u, we will see an ellipse. Therefore, tidal currents can also be described by ellipse parameters (ep-parameters). The ap-parameters and ep-parameters can be converted into each other by using the ap2ep and ep2ap MATLAB functions developed by Xu (2000, 2002). One might work out a set of interpolants that can be directly applied to ep-parameters, but such a set might be very complicated. It is better to convert ep-parameters to ap-parameters first, then using Eqs. (12) and (13) as the interpolants, and then convert the results back to the ep-parameters. The MATLAB function THCepinterp2 shown in List 5 in Appendix assumes these steps.

Figure 3 illustrates an interpolation of tidal ellipses. Four data ellipses are provided at four corners of a grid cell. The ellipse drawn on the center of the cell is interpolated from the four data ellipses. The interpolation can be performed by calling THCepinerp2 in this way:

Fig. 3
figure 3

Tidal current ellipse parameter interpolation. The data ellipses distributed at the four corners of the grid cells and the interpolated ellipse at the center of the cell are shown. The interpolation is performed by the function THCepinerp2 as provided in List 5 of Appendix

$$ \mathrm{EPi}=\mathrm{THCepinerp}2\left(\mathrm{xx},\mathrm{yy},\mathrm{EP},\mathrm{xi},\mathrm{yi}\right) $$
(19)

where

$$ \mathrm{xx}=\left[\begin{array}{cc}0& 1\\ {}0& 1\end{array}\right],\kern1.5em \mathrm{yy}=\left[\begin{array}{cc}0& 0\\ {}1& 1\end{array}\right], $$
(20)

are two matrices containing the coordinates of the four grid points, and the EP is a MATLAB structure with the ep-parameters of the data ellipses as its fields:

$$ {\displaystyle \begin{array}{l}\mathrm{EP}.\mathrm{SEMA}=\left[\begin{array}{cc}0.8333& 0.5912\\ {}1.1587& 0.6428\end{array}\right],\kern1.75em \mathrm{EP}.\mathrm{INC}=\left[\begin{array}{cc}62.9095& 108.5705\\ {}50.4532& 135.0000\end{array}\right],\\ {}\\ {}\kern0.75em \mathrm{EP}.\mathrm{ECC}=\left[\begin{array}{cc}0.4220& -0.6338\\ {}0.3688& 0.5090\end{array}\right],\kern1em \mathrm{EP}.\mathrm{PHA}=\left[\begin{array}{cc}203.5677& 204.2242\\ {}104.2663& 141.8655\end{array}\right],\end{array}} $$
(21)

where the four fields EP.SEMA, EP.INC, EP.ECC, and EP.PHA contain the lengths of the semi-major axes, the orientations (inclinations) of the semi-major axes, the eccentricities,Footnote 1 and the phase angles of the four data ellipses, respectively. The phase angle of a tidal ellipse indicates a time that is expressed as an angle (= time × frequency) when the tidal current reaches its maximum speed. The interpolation point is the center of the cell, which means that x i  = 0.5 and y i  = 0.5.

As we can see, the interpolated ellipse is much smaller than any of the four data ellipses. This seems surprising but it is actually correct, because the u- and v-time series represented by the four ellipses are out of phase to a large degree. Figure 4 shows time series of u-components (top panel) and v-components (bottom panel) reconstructed from the data ellipses (in gray) and from the interpolated ellipse (in green). Since the interpolation point is in the center of the cell, the green curve for the u-component should simply be an arithmetic average of the four gray curves of the u-components; so is the green curve for the v-component. As we can see, the four time series at the four corners of the cell have very different phases, which causes their average in the middle of the cell to have a much smaller amplitude. This example demonstrates the importance of treating tidal ellipse interpolation appropriately.

Fig. 4
figure 4

Time series of u and v reconstructed from the four original tidal ellipses in gray and the interpolated ellipse in green. Because the interpolation point is at the center of the cell, the green curve is an average of the four gray curves

The semi-major axes of the ellipses are shown in the range of [0, 180°) in Fig. 3. The semi-minor axes are shown 90° from the semi-major axes, and they are either counter-clockwise or clockwise depending on whether the eccentricity is positive or negative. The inclinations of the semi-major axes do not have to be in the direction as shown. Their opposite directions could have well been chosen as the inclinations. However, to choose the inclinations to be in the range of [0, 180°) is conventional, the so-called the northern axis convention (Foreman 1978, p. 13). The ap2ep and ep2ap functions have two versions. The one provided by Xu (2000) allows inclinations in the range of [0, 380°), whereas the revised version by Xu (2002) adopts the northern axis convention. Both versions will give the same ap-parameters however. Therefore, no matter which version one may prefer, the interpolation will not be affected.

4 Conclusions

The amplitude and phase parameters (ap-parameters) for tidal heights and tidal currents cannot be interpolated in space as though they are independent quantities—errors arise when they are interpolated separately and linearly. This note paper provides correct nonlinear and coupled interpolation interpolants: Eqs. (12) and (13) (or (14)), together with examples and MATLAB functions. When these interpolants are used, the time series reconstructed from the interpolated ap-parameters are identical to those obtained by interpolating the tidal height or current time series.

Similarly, the tidal current ep-parameters cannot be interpolated linearly and separately. First, they should be converted to ap-parameters. Then, the nonlinear and coupled interpolants can be used to interpolate the ap-parameters, followed by converting the results back to ep-parameters.

The MATLAB functions listed in Appendix provide tools to interpolate THCs. These functions relieve uses from the complexity of the interpolations and provide an easy user interface. The function THCepinterp2 is a tool for interpolating tidal ep-parameters, a procedure that can otherwise be quite complicated and prone to error.