Creating time vector using number of samples
2 views (last 30 days)
I have the following parameters:Total number of samples: 5000, samplerate: 2500.I created my time vector as usual: t=0:1/2500:5000-1/2500. But the time vector is a lot bigger than my related data vector which makes plotting impossible. Am I misunderstanding the meaning of sample number?
Voss on 2 Jul 2022
Defining t like this:
is creating a time vector that has samplerate=2500 [2500 samples/second, say] for 5000 seconds, essentially. (Or 2500 samples/hour for 5000 hours or 2500 samples/day for 5000 days, etc. - I don't know that samplerate is per second necessarily, but it doesn't matter), which gives you a vector with 2500*5000 samples:
But you are given that the number of samples is 5000, not that the end time is 5000, so the time vector should be:
t = 1/2500*(0:5000-1) % 5000 samples, spaced 1/2500 apart
More Answers (1)
Aniruddh Maini on 2 Jul 2022
As per your question NumSamples = 5000 and SampleRate = 2500
That means, in one seconds the signal will be sampled 2500 times or we will get 2500 samples each second, and we have to get 5000 samples in total.
So let's say
At t = 0 sec we get a sample
At t = 0 + (1/2500) we get another sample
At t = 0+(1/2500)+(1/2500) we get another sample.
and so on...
So from the observation we can say that total time required to get 5000 samples is (1/2500)*(5000-1)
Since we are getting 5000 samples between t = 0 and t = (1/2500)*(5000-1), so the SampleTime vector can be found as
timeVector = 0:1/2500:(1/2500)*(5000-1) or alternatively as
timeVector = linspace(0,(1/2500)*(5000-1),5000)
Hope it helps.