I'm trying to find the maximum peak on a power spectral density plot created in Matlab. I can create the plot just fine but am having difficulty correctly marking it. I use the find peaks and max function to find it but Matlab cannot correctly mark it. It finds the correct height but marks it a little to the left or right. Here is the code:
data = load ('EEGData(test1).txt', '-ascii');
figure(1)
plot(data)
Y =fft(data,251);
Pyy = Y.*conj(Y)/251;
f = 1000/251*(0:127);
figure(2)
plot(f,Pyy(1:128))
title('Power spectral density')
xlabel('Frequency (Hz)')
[a,b] = findpeaks(Pyy(1:128));
MAX = max(a);
hold on
plot(f(b), MAX,'or')
any help would be greatly appreciated.