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

조회 수: 403 (최근 30일)
Becky CNS
Becky CNS 2018년 3월 6일
댓글: Chibuzo 2023년 11월 17일
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.

답변 (2개)

Jos (10584)
Jos (10584) 2018년 3월 6일
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
Jos (10584)
Jos (10584) 2018년 3월 6일
That is indeed the average sampling rate (as t starts at zero!)
sr = Nsamples / TotalSamplingtime = numel(t) / (t(end)-t(1))
Chibuzo
Chibuzo 2023년 11월 17일
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.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2018년 3월 6일
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
karima neffati
karima neffati 2019년 7월 16일
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 2021년 6월 3일
karima
ECG=load('filename.mat');
K=ECG.data;
plot(K)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by