Suppose a signal corresponds to day values over a year (365 days). It is composed of all zeros except for a few sparse values which corresponds to isolated peaks all separated by the same interval (30 days). I obtain the frequency spectrum with the Fast Fourier Transform function.
how to get rid of the high 0Hz peak? EDIT: this is related to the non-zero-mean nature of the signal. See this post for more details.
The first peak is then at 12Hz, which is somehow expected. However, peaks are also present at 24Hz, 36Hz, 48Hz ... . Is it an aliasing problem? How to get rid of it?
Below is my code. It was tested in Octave but it should also work in Matlab
close all
clear all
T = 1/365; % period
samp_freq = 1/T; % sample frequency
t=0:T:2; % overall time span is two years
% build signal
x= zeros(length(t),1);
for i=1:length(t)
if mod(i,30) == 0
x(i) = 100;
else
x(i) = 0;
end
end
figure(1)
plot(t,x)
grid
xlabel("Time [years]")
ylabel("Signal amplitude")
y=fft(x);
N = length(x);
for i=1:N
f(i) = (i-1)*samp_freq/N;
end
figure(2)
plot(f,abs(y))
xlabel("Frequency")
ylabel("Signal amplitude")
figure(3)
plot(f(1:80),abs(y(1:80)))
xlabel("Frequency")
ylabel("Signal amplitude")