Finding sample frequency?

2 views (last 30 days)
Mordecai
Mordecai on 12 Mar 2017
Commented: Star Strider on 12 Mar 2017
Alright so I have a text file of 600 samples from a ECG.
Using this code, I found the peaks:
%Find ECG peaks
close all, clear all, clc
sig=load('ecg.txt'); %Load
plot (sig) %plot
xlabel('Samples')
ylabel('Electrical Activity')
title('ECG Signal')
hold on, plot(sig,'ro')
Peak=0; %Peak Value
Beat_count=0 %Number of Heartbeat
for i=2:length(sig)-1
if(sig(i)>sig(i-1) && sig(i)>sig(i+1) && sig(i)>1.7)
disp ('Peak found')
i, Peak=sig(i)
Beat_count=Beat_count+1
end
I also created a graph comparing samples to electrical activity.
The question says: "Plot a circle around each of the P wave peaks that you have found." So I'm guessing I need to take this a step further, but I'm stuck. It also says: (*hint: In the time vector, tmax can be determined by subtracting 1 from the sample size and dividing by the sample frequency.) But how can I find the sample frequency without time? Or am I overthinking this and the graph above is all I need?
  2 Comments
Chad Greene
Chad Greene on 12 Mar 2017
Sounds like your professor has given you a time vector. Is sig a vector or is it 2D? As an aside, I suspect you only need to plot red circles at the peaks, not at every sig data point. So instead of
plot(sig,'ro')
try
plot(sig(sig>1.8),'ro')
Star Strider
Star Strider on 12 Mar 2017
You must be provided the sampling frequency or sampling interval. There is no way to determine it from the data alone. To detect the P-waves, you have to use the findpeaks function and the intersect function to find the points between 0.5 and 0.7. Those will be the P-waves, at least in the EKG segment you posted.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!