0

I am analyzing ECG data using MATLAB. The data is made up of two columns, one the time in milliseconds and the other contains the volts (mV) and is imported into MATLAB from a CSV file.

I use the built-in fft function in MATLAB (i.e fft(mV)). Now that I have the transformed data, I don't know how to plot it.

I know that I need the frequency data but I'm having trouble understanding where that comes from and what the other axis even is.

Amro
  • 123,847
  • 25
  • 243
  • 454
tfiggs
  • 9
  • 2
  • 1
    Checkout [the example](http://www.mathworks.com/help/matlab/ref/fft.html?refresh=true#buuutyt-9) in the documentation. It has a pretty thorough demonstration of how to plot the FFT result. – Suever Apr 13 '16 at 19:28
  • 1
    Here are more examples: http://stackoverflow.com/a/6698729/97160, http://stackoverflow.com/a/2113968/97160 – Amro Apr 13 '16 at 19:36

1 Answers1

0

When you say "the time in milliseconds", I hope you have sampled at an even interval when performing an FFT. If you have not then you have two choices.

You can interpolate the data between the points so as to "guess" where the graph would eb at the time in the time domain.

OR

You can re-sample at a regular interval. Returning the time in milliseconds is not really necessary for this as the interval must be equal, but it could functions as a validator to prove that the data is correct.

Once you have you data with a regular sampling period then you can use this to obtain the FFT.

function [ X, f ] = ctft( x, T )
% x = sample array
% T = sampling period

% X = fft amplitude
% f = frequency 

N = length(x);
X = fftshift(fft( x, N ))*( (2*pi) / N );
f = linspace( -1, 1-1/N, N)/(2*T);
deanshanahan
  • 318
  • 5
  • 14
  • Haven't been at my computer since I asked, but yes, the sampling was done at a regular interval. I believe the sampling period was 4ms but i'll need to check. – tfiggs Apr 15 '16 at 14:44
  • Then use T=0.004s and x equal to you input and use the code In my answer about. Plot(f,X) and away you go! – deanshanahan Apr 15 '16 at 17:55