fft problem - how do I fix the edges?
10 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148464/image.png)
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))
0 个评论
回答(2 个)
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 个评论
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
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
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oceanography and Hydrology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!