-3

I am trying to run the given code below

w = fft(y);
a1 = abs(w);
a2= a1(0:length(w)/2-1);
g = (0:(length(w)/2)-1)*fs/length(w);
figure;
subplot(2,1,1)
plot(g,a2);
title('FFT of X(k): Original signal');
xlabel('frequency(hz)');
ylabel('amplitude of frequency');

at the

a2 = a1(0:length(w)/2-1); 

matlab shows an error

"Subscript indices must either be real positive integers or logicals."

I have no idea what's going wrong.

Vega
  • 27,856
  • 27
  • 95
  • 103
lyona
  • 1

1 Answers1

1

Index should one-based, so it should be 1:length(w)/2 and not 0:length(w)/2-1

isp-zax
  • 3,833
  • 13
  • 21