# 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.

17 Ansichten (letzte 30 Tage)
Siratul Srotoshwini am 11 Mai 2020
Kommentiert: Peng Li am 11 Mai 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 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Peng Li am 11 Mai 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 Kommentare3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
Peng Li am 11 Mai 2020
I guess you should use max(SSAS) instead of max(Y). Y is complex. SSAS based on your codes is amplitude spectrum.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!