1

So i've got an exisiting ekg signal that I have to take get the fourier transform for, and plot the phase (angle) and magnitude. My code looks like this:

x1 = 3.5*ecg(2700);
y1 = sgolayfilt(kron(ones(1,13),x1),0,21);
n = (1:30000)';
del = round(2700*rand(1));
mhb = y1(n+del);
ts = 0.00025;
t = [ts: ts: 7.5];
%plot(t,mhb)
%xlabel('Time(sec)')
%ylabel('Amp'); grid on 

Xf = fft(mhb(t));

w = [-(n/2):1:(n/2)-1]*(1/(ts*n));
w = [-(n/2):1:(n/2)-1]*(1/(ts*n));

subplot(211), plot(w, fftshift(abs(Xf))), grid 
subplot(212), plot(w, fftshift(angle(Xf))), grid

It's telling me this error: "Subscript indices must either be real positive integers or logicals." I'm pretty sure thats correct, unless I'm doing something completely incorrect. Any help would be appreciated.

  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 16:05

1 Answers1

0

Notice that t is real array with the values (lets look at the first few):

>> t(1:10)

ans =

    0.0003    0.0005    0.0008    0.0010    0.0013 ... and so on

So the argument of your fft is mhb(t), but you are calling the values of mhb (also an array) with values of t as indices.

This gives you the error:

>> mhb(t)
Subscript indices must either be real positive integers or logicals.

So you need to do something like:

mhb(1:length(t));

Does that clear things up?

Bruce Dean
  • 2,798
  • 2
  • 18
  • 30
  • Ah yes, that does make sense. Thanks, clears up that error :) – Borys Ostapienko Nov 19 '13 at 01:43
  • It does make sense theoretically, however still not producing any signals for some reason. The syntax is off a bit. Might be another built in function instead of length – Borys Ostapienko Nov 19 '13 at 01:45
  • I would go back and check your signal to make sure you are FFT'ing what you think you are, just double check all of your inputs. Also, there may be some other mapping from your t values to the indices of the mhb array, that could be a little more complex, although its not clear from your setup what that might be. I think the original problem you asked about is solved though. – Bruce Dean Nov 19 '13 at 01:49