# Can some one please tell me how to find the maximum amplitude frequency of the ecg signal? I have attached below my code. I keep getting maximum frequency at 0 Hz.

11 visualizaciones (últimos 30 días)
Siratul Srotoshwini el 11 de Mayo de 2020
Comentada: Peng Li el 11 de Mayo de 2020
function [freq,SSAS,freq_max] = tutorial10
% Read in the data file
filename = 'data.csv'; % Filename
delimiterIn = ','; % Entries are comma delimited
ecgData = importdata(filename,delimiterIn,headerlinesIn); % Read the file into an array called ecgData
% Calculate (but don't plot) single-sided amplitude spectrum (this includes points along frequency axis, and amplitude axis)
% Determine frequency which exhibits maximum amplitude
% Set up for FFT
T = 1./360; % Sample time
Fs = 1/T; % Sampling frequency
L = length(ecgData); % Length of signal (total samples)
t = (0:L-1)*T; % Time vector
%Calculate the FFT of the ecg data
NFFT = 2^nextpow2(L); % Next power of 2 from length of signal
Y = fft(ecgData,NFFT);
ecgData =ecgData -mean(ecgData);
SSAS =2*abs(Y(1:NFFT/2+1));
%Construct the points along the frequency axis
freq = Fs*linspace(0,1,NFFT/2+1);
max_a= max(Y);
idx = find(Y == max_a);
freq_max = freq(idx)
% Create filter
Fcutoff=30;
order=2;
cutoff=2*Fcutoff/Fs;
end
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Peng Li el 11 de Mayo de 2020
try
Y = fft(ecgData - mean(ecgData), NFFT);
It is expected that the DC contains most of the energy of the signal. You could explictly remove this DC component, or you can try something like detrend to remove the nonstationary trend which is usually quite common in physiological data.
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Siratul Srotoshwini el 11 de Mayo de 2020
I keep getting this error? Can you please tell whats wrong? Thanks.
Peng Li el 11 de Mayo de 2020
I guess you should use max(SSAS) instead of max(Y). Y is complex. SSAS based on your codes is amplitude spectrum.

Iniciar sesión para comentar.

### Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by