# plot specific frequency of signal

7 views (last 30 days)
mary keshtkar on 8 Mar 2023
Edited: Star Strider on 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

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 —
% EKG file found in: I would like to calculate heart rate by determining threshold for amplitude
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]) .