How to find sampling rate from a signal vector and a time vector?
266 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
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)
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
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
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
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 ?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!