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

Réponses (2)

Star Strider
Star Strider le 21 Déc 2016
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 commentaires

Arijit Ghosh
Arijit Ghosh le 21 Déc 2016
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
Good mind
Good mind le 17 Oct 2017
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)??
Star Strider
Star Strider le 17 Oct 2017
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.
Good mind
Good mind le 17 Oct 2017
thank you
Star Strider
Star Strider le 17 Oct 2017
My pleasure.
Kristofer Soler
Kristofer Soler le 18 Fév 2020
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.
Kristofer Soler
Kristofer Soler le 18 Fév 2020
yeah "val" is just the default name of the vector when i plot, ekg is more appropriate. Thanks btw !
Star Strider
Star Strider le 18 Fév 2020
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!
Kristofer Soler
Kristofer Soler le 19 Fév 2020
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.
Star Strider
Star Strider le 19 Fév 2020
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.

Connectez-vous pour commenter.

karima neffati
karima neffati le 16 Juil 2019

0 votes

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 )

Catégories

En savoir plus sur Signal Processing Toolbox dans Centre d'aide et File Exchange

Commenté :

le 19 Fév 2020

Community Treasure Hunt

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

Start Hunting!

Translated by