Clear Filters
Clear Filters

fft problem - how do I fix the edges?

10 views (last 30 days)
Steven_ut
Steven_ut on 30 Mar 2015
Commented: Steven_ut on 31 Mar 2015
for our school project we received 44 years of data of a water level at some place. We were asked to predict a week and 2 weeks from now, so we fft'd the data and our approximation is quite good, but since fft uses data from -infinite to infinite the approximation dies out at the edges, and the edges are actually THE places we're looking at (since a week out of 44 years is really at the edge).
This is our code:
clear, clc
load('Bath')
L = length(data);
T = L/24;
fourier = abs(fft(data)/L);
w = linspace(0,L/T,L);
k = 1;
for i = 1:0.5*length(w)
if fourier(i) > 0.2
s(k) = w(i);
k = k + 1;
end
end
length(s)
t = linspace(0,T,L);
y = 0;
for i = 2:length(s)
p = s(i)*2*pi;
c = [sin(p*t') cos(p*t')];
A = c\data;
y = y + c*A;
end
figure(1)
plot(t,data)
hold on
plot(t,y,'m-')
hold off
figure(2)
plot(t,(data-y))

Answers (2)

Thomas Koelen
Thomas Koelen on 30 Mar 2015
Edited: Thomas Koelen on 30 Mar 2015
The Fourier Transform relies on the assumption that your time domain data is periodic, so you can just repeat your time domain data - no explicit extrapolation is necessary. Of course this may not give you what you expect if your individual component periods are not exact sub-multiples of the DFT input window duration. This is one reason why we typically apply window functions such as the Hanning Window prior to the transform.
  2 Comments
Steven_ut
Steven_ut on 30 Mar 2015
I'm not that good with MatLab yet to understand what all this meant, sorry.. Though I am curious about what you said about Hanning Window
Thomas Koelen
Thomas Koelen on 30 Mar 2015
I'm saying, that the fourier transform only works when your signal is periodic in time. So you could just extrapolate your signal instead of the fourier transform.

Sign in to comment.


Image Analyst
Image Analyst on 30 Mar 2015
What is your plot of? The time data or the spectrum? Why not just extract the water level at this day of the year (the day of the year that you want to predict) from all 44 prior years and then average them?
  5 Comments
Image Analyst
Image Analyst on 30 Mar 2015
So it looks like you have a dominant frequency around 2, then another one around 22. I imagine the 2 corresponds the the main tidal frequency - what is it, around 12 hours or so? Then what is the higher frequency one at 22 for? Is that just the little ripples and waves that occur on top of the slowly varying tides?
Steven_ut
Steven_ut on 31 Mar 2015
We were told that for real data the other half of the graph is symmetric and shouldn't be included into our calculation. So there's a dominant frequency at 2, those are the tides because of the moon, and the rest is because of other planets and such, maybe even humans. As you can see in our code, we include all frequencies whose amplitudes are bigger than 0.2, what will result in length(s) = 2742, so 2742 frequencies.

Sign in to comment.

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!