How to plot a ECG signal in time scale?

Hello all, I am working on an ECG signal, i wish to know how to plot the ECG signal in respect of time scale. I am having 76801 samples with sampling rate 256Hz, i.e. 5 min of the signal. Please suggest a code if possible. Thanx in advance Arijit

Answers (2)

You can use linspace to create a time vector for your EKG:
t = linspace(0, 76800, 76801)/256; % Time Vector (Intervals In Seconds)
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency (Check)

12 Comments

Thanx Star for the answer.Actually i am trying to plot the ECG in with x axis denoting time(sec) and y axus amplitude..instead in the workspace i have 76800 samples..can you please clarify how to plot it.The function you provided did not match this case.
My pleasure.
Your original Question said ‘I am having 76801 samples with sampling rate 256Hz, i.e. 5 min of the signal’ so I created ‘t’ to have 76801 elements. I am not surprised that the mismatch threw an error.
With the 76800 clarification, you can also calculate your time vector as:
L = 76800; % Length Of Signal
Fs = 256; % Sampling Frequency
t = 0 : 1/Fs : (L-1)/Fs; % Time Vector
Then, if ‘EKG’ is your signal vector, plot it as:
figure(1)
plot(t, EKG)
grid
Star Strider,thank you very much, the code is very helpful. is it the case when the signal is from physionet(fs=360hz, t=10sec l=2000)??
The maths do not work in your example, since 2000/360=5.55... not 10, seconds.
If they did, you could simply plug your time data into my code to get the result you want.
is it better (or can you ) use (0:numel(val)-1) function instead of the number of samples? that way you don't have to change the number if you have a different input.
It depends on what ‘val’ is. (I have no idea what it is.)
This:
t = linspace(0, numel(EKG), numel(EKG))/Fs; % Time Vector (Intervals In Seconds)
will adapt to any signal length, where ‘EKG’ is the vector of EKG samples, and ‘Fs’ is the sampling frequency.
yeah "val" is just the default name of the vector when i plot, ekg is more appropriate. Thanks btw !
My pleasure.
..."val" is just the default name of the vector when i plot...
I had no way of knowing that. Reasonably precise definitions are always appropriate!
I just meant that if you take an ecg from say physionet and just load, eg. (load'100m.mat') it into matlab by default the array will be called "val", which i assume is short for values or something, but this is default for matlab.
It is always good MATLAB programming practice to load a .mat file to a variable. This creates a structure array that can then be addressed specifically to access the EKG record, the time vector, and other information. It also allows control over what gets loaded into the workspace as variables.

Sign in to comment.

hello Mr star
Mr Star can i ask you please how to convert an ecg signal to image ??
i have a saved ecg file with(x:samples,y:amplitude,fs=2155 )

Categories

Find more on Signal Processing Toolbox in Help Center and File Exchange

Asked:

on 21 Dec 2016

Commented:

on 19 Feb 2020

Community Treasure Hunt

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

Start Hunting!