Get Your Data On 2025-06-08 15:38:00

Wait 5 sec.

[This article was first published on Get Your Data On, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.Interpolation in the Frequency Domain Improved!h1 {font-size: 34px;} h1.title {font-size: 38px;} h2 {font-size: 30px;} h3 {font-size: 24px;} h4 {font-size: 18px;} h5 {font-size: 16px;} h6 {font-size: 12px;} code {color: inherit; background-color: rgba(0, 0, 0, 0.04);} pre:not([class]) { background-color: white } code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} code{white-space: pre;}if (window.hljs) { hljs.configure({languages: []}); hljs.initHighlightingOnLoad(); if (document.readyState && document.readyState === "complete") { window.setTimeout(function() { hljs.initHighlighting(); }, 0); }}.main-container { max-width: 940px; margin-left: auto; margin-right: auto;}img { max-width:100%;}.tabbed-pane { padding-top: 12px;}.html-widget { margin-bottom: 20px;}button.code-folding-btn:focus { outline: none;}summary { display: list-item;}details > summary > p:only-child { display: inline;}pre code { padding: 0;}.tabset-dropdown > .nav-tabs { display: inline-table; max-height: 500px; min-height: 44px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px;}.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before { content: "\e259"; font-family: 'Glyphicons Halflings'; display: inline-block; padding: 10px; border-right: 1px solid #ddd;}.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before { content: "\e258"; font-family: 'Glyphicons Halflings'; border: none;}.tabset-dropdown > .nav-tabs > li.active { display: block;}.tabset-dropdown > .nav-tabs > li > a,.tabset-dropdown > .nav-tabs > li > a:focus,.tabset-dropdown > .nav-tabs > li > a:hover { border: none; display: inline-block; border-radius: 4px; background-color: transparent;}.tabset-dropdown > .nav-tabs.nav-tabs-open > li { display: block; float: none;}.tabset-dropdown > .nav-tabs > li { display: none;}Interpolation in the Frequency DomainImproved!IntroductionThis post describes interpolation in the frequency domain (IFD) andan improvement to IFD. IFD is a method of interpolation that is easy touse and produces good results on most time series data (data samplesequally spaced in time). It is easy to use because it does not requireany prior knowledge of the data. Also, since IFD uses the Fast FourierTransform (FFT), it is fast (even on large data sets). The drawback toIFD is that it sometimes produces an interpolation that is not good atthe start and end of the sequence (referred to as “end effects”). Theimproved IFD reduces the end effects. While end effects are not alwaysan issue, it is always better to not have them.The first section briefly introduces interpolation. The next sectiondefines the standard IFD algorithm and shows examples of its use. Thefinal section shows an improved IFD that reduces end effects.Interpolation ExampleLet’s say we check a rain gauge at 7:00 and then once an hour forfive hours, resulting in the following measurements: 0.01 cm, 0.19 cm,0.31 cm, 0.40 cm, 0.52 cm, and 0.59 cm. We didn’t measure the rain at7:30, but we could estimate the rainfall at 7:30 using a linear splineto interpolate (connecting the points with straight lines).The figure below shows the five rainfall values from above and anillustration of interpolating a rainfall value at 730. The figure showsthe five measurements as black circles, the interpolating blue lineconnecting the points 700 and 800, and the interpolated point at 0730shown as a red circle. The red circle shows that the rainfall at 730 is0.1 cm.Interpolation in the Frequency DomainLinear spline interpolation is effective if the underlying data canbe modeled by a straight line. IFD works well regardless of the type ofdata.The steps in the algorithm for IFD are enumerated below.Find the discrete Fourier transform (DFT) of the data using thebuilt-in function fft, which is R’s implementation of theFFT. The data started in the time domain (data indexed by time). Afterthe transform, the data is in the frequency domain (data indexed byfrequency).Add zeros to the data. This is called zero padding, and it forcesthe inverse DFT (IDFT) in the next step to evaluate the data at morepoints. When adding zeros to the frequency domain data, the zeros mustgo in the middle. This step is slightly different for even and oddlength sequences.Perform the IDFT on the zero padded DFT sequence.These steps are explained below.Find the DFT of the SequenceTo illustrate this step, we use the rain fall values from above.First, we use the fft function to find the DFT of thesequence. Below, I’m going to stop saying, “Use the fftfunction to find the DFT.” I’ll just say find the FFT. Note: to take upless space on the screen, I’ll round the output to two decimalplaces.N