Search code examples
matlabfrequency

FFT of ECG signal in MATLAB


This is the input signal : original

    plot(abs(fft(ecg)))

fft

I have also tried

    fvtool(x_vals)

which gave me :

another

However I want the x axis in Hz. So essentially I want to see the frequency spectrum of this signal in Hz.

Thanks!


Solution

  • function [f amp] = getspectrum( Mdata, Mf )
    
    %  Mdata    data 
    %  Mf       sampling rate / frequency (Hz)
    
    NFFT = 2 ^ nextpow2(length(Mdata)); 
    Y = fft(double(Mdata), NFFT) / length(Mdata);
    f = (double(Mf) / 2 * linspace(0, 1, NFFT / 2))'; % Vector containing frequencies in Hz
    amp = 2 * abs(Y(1:(NFFT / 2))); % Vector containing corresponding amplitudes
    

    I hope this might be of help.