fft problem - how do I fix the edges?

10 次查看(过去 30 天)
Steven_ut
Steven_ut 2015-3-30
评论: Steven_ut 2015-3-31
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))

回答(2 个)

Thomas Koelen
Thomas Koelen 2015-3-30
编辑:Thomas Koelen 2015-3-30
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 个评论
Steven_ut
Steven_ut 2015-3-30
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 2015-3-30
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.

请先登录,再进行评论。


Image Analyst
Image Analyst 2015-3-30
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 个评论
Image Analyst
Image Analyst 2015-3-30
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 2015-3-31
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by