Effacer les filtres
Effacer les filtres

plot specific frequency of signal

1 vue (au cours des 30 derniers jours)
mary keshtkar
mary keshtkar le 8 Mar 2023
I would like to plot the 0 to 50 Hz of ecg signal by FFT. How Can I change it that plot the 0 to 50 Hz frequencies.
this is my code
a1 =importdata ('ecg.txt');
Fs = 500; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(a1);
nfft = 2^nextpow2(L);
y=fft(a1,nfft)/L;
y1=abs(y);
f=(0:nfft/2)*Fn*2/nfft;
figure
plot (f,y1(1:numel(f))
title ('‘Frequency Domain’')
xlabel('f(Hz)')
ylabel('|y1(f)|')
grid

Réponses (1)

Star Strider
Star Strider le 8 Mar 2023
Modifié(e) : Star Strider le 8 Mar 2023
Are you certain that 500 Hz is the correct sampling frequency for this trace?
That would calculate to a heart rate of 335 bpm!
That aside, one way to analyse it —
a1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1317805/ecg.txt');
% EKG file found in: I would like to calculate heart rate by determining threshold for amplitude
% https://www.mathworks.com/matlabcentral/answers/1925115-i-would-like-to-calculate-heart-rate-by-determining-threshold-for-amplitude?s_tid=srchtitle
Fs = 500; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(a1);
Duration_sec = L/Fs
Duration_sec = 12
R = islocalmax(a1, 'MinProminence',0.75);
HR = nnz(R)/Duration_sec * 60 % BPM
HR = 335
nfft = 2^nextpow2(L);
y=fft((a1-mean(a1)).*hann(L),nfft)/L;
y1=abs(y);
f=(0:nfft/2)*Fn*2/nfft;
figure
plot (f,y1(1:numel(f)))
title ('‘Frequency Domain’')
xlabel('f(Hz)')
ylabel('|y1(f)|')
grid
t = linspace(0, L-1, L)/Fs; % Time Vector
figure
plot(t, a1)
hold on
plot(t(R), a1(R), '^r')
hold off
grid
xlabel('Time (s)')
ylabel('Amplitude (mV)')
figure
plot(t, a1)
grid
xlabel('Time (s)')
ylabel('Amplitude (mV)')
xlim([0 1])
.

Catégories

En savoir plus sur ECG / EKG dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by