I have a problem with a basic time/frequency property implemented in a Matlab script. The property is:
I've tried to implement this in a Matlab script. I've supposed a sinusoidal signal with 5Hz of frequency value, Sampling frequency equal to 800Hz and I want to delay this signal by 1.8 seconds. So I've implemented this script:
Fs = 800;
Time_max = 4; % seconds
t = 0:(1/Fs):Time_max;
delay = 1.8; % One second of delay
f = 5; %Hz
y = sin(2 * pi * f * t);
figure
subplot(2,1,1)
plot(t,y);
xlabel('time (s)')
legend('Original');
%FFT
SIZE = 2^nextpow2(length(y));
Y = fft(y,SIZE);
df = Fs/SIZE;
f= -Fs/2:df:Fs/2 - df;
for k = 1:SIZE
Y(k) = Y(k)*exp(-(1i*2*pi*f(k)*delay));
end
subplot(2,1,2)
plot(real(ifft(Y)),'r')
legend('Shifted');
And the output plot is :
Where is the problem? How can I achieve the correct time delay?
Thanks