plot specific frequency of signal
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Star Strider
on 8 Mar 2023
Edited: Star Strider
on 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
R = islocalmax(a1, 'MinProminence',0.75);
HR = nnz(R)/Duration_sec * 60 % BPM
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])
.
0 Comments
See Also
Categories
Find more on ECG / EKG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!