How to find sampling rate from a signal vector and a time vector?

267 visualizaciones (últimos 30 días)
Becky CNS
Becky CNS el 6 de Mzo. de 2018
Comentada: Chibuzo el 17 de Nov. de 2023
I have signal vectors and corresponding time vectors. Is there a specific way to calculate the sampling rate and the number of samples just from this info?
(I can look at the time vector and manually count how many samples per second but I need a more concrete way to do this)
Also, looking up other answers I found accepted answers to other questions as this: Sr = maxvalue-minvalue/length-1 but for values and length of the time or signal vector? And how will that give me the sampling frequency?
Or I read that Sr = 1/sample period but I also don't understand how that can be the case? In the example I am working on this would give me 0.001, is that the size of the steps in a second? How do I then get from that to the sampling frequency?
I'm getting confused by all the different equations and functions for sampling frequency, I just need to know what is correct.

Respuestas (2)

Jos (10584)
Jos (10584) el 6 de Mzo. de 2018
The sampling rate is the number of samples collected per second. In most typical cases, this is (roughly) a fixed (single) value during the time you are sampling.
For a given sampling frequency F, the differences between time points of each sample (dT) is 1/F, hence, when you know dT , you also know F (=1/dT).
You can estimate dT based on your data as, for instance, the average/median or mode value of the differences between the time stamps.
t = [0.00 0.31 0.59 .90 1.21 1.48 1.81] % time stamps in in seconds
dt = mean(diff(t))
F = 1 / dt % Hz
  3 comentarios
Jos (10584)
Jos (10584) el 6 de Mzo. de 2018
That is indeed the average sampling rate (as t starts at zero!)
sr = Nsamples / TotalSamplingtime = numel(t) / (t(end)-t(1))
Chibuzo
Chibuzo el 17 de Nov. de 2023
There's such thing as discrete random sampling where the sampling time follows some sort of probability distribution. Such approach can be investigated.
Another approach might be to use
sr = mode(diff(t))
That is, taking the sampling interval that occurs the most.
The signal points due to resampling at this sr can be obtained via interpolation.

Iniciar sesión para comentar.


Star Strider
Star Strider el 6 de Mzo. de 2018
I usually calculate the sampling interval as:
Ts = mean(diff(t));
where ‘t’ is the time vector, assuming the sampling interval is regular.
I use the standard deviation of diff(t) as:
St = std(diff(t));
as a measure of the regularity of the sampling intervals.
If necessary (a value of St greater than 1E+5 of mean(t)), I use the Signal Processing Toolbox resample function to resample it to a constant sampling frequency, using linspace to define the sampling times.
Then, once that is resolved to my satisfaction, the sampling frequency is:
Fs = 1/Ts;
and I go from there.
  2 comentarios
karima neffati
karima neffati el 16 de Jul. de 2019
mr star please can yu help me?
i confused between signal details of ecg, i have a mat file and i wand to convert it to image ?
subramanian K S
subramanian K S el 3 de Jun. de 2021
karima
ECG=load('filename.mat');
K=ECG.data;
plot(K)

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by