Spline question,more then 1 samplerate

1 view (last 30 days)
m j
m j on 19 Jan 2020
Commented: Kaashyap Pappu on 22 Jan 2020
Im trying to spline 2 different samplerates to desired samplerate and I get a tiny error.The 2 samplerates are 50kHz,200kHz and desired samplerate is 300kHz.
%first find lcm(least common multiple) of both samplerates along with new desired samplerate of 300kHz
%factor = lcm(allSamplerates,newSamplerate);
factor = lcm([50000,200000],300000);
%factor = 600000
%find ratio needed for spline to raise samplerate
upSamp = 50000/factor; %50kHz/600kHz = 0.08333
upSamp2 = 200000/factor; %200kHz/600kHz = 0.3333
%sample1 = 1 X 256 @ 50kHz (0.00512 milli seconds long) array
sample1 = s1; %s1 = 1:256
%determine spline variables for sample1
x = 1:size(sample1,2);
y = sample1(1,:);
tx = 1:upSamp:size(sample1,2);
%sample2 = 1 X 1024 @ 200kHz (0.00512 milli seconds long) array
sample2 = s2 %s2 = 1:1024
%determine spline variables for sample2
x = 1:size(sample2,2);
y = sample2(1,:);
tx = 1:upSamp2:size(sample2,2);
sNew1 = [];
sNew2 = [];
sNew1 = [spline(x,y,tx); sNew1];
sNew2 = [spline(x2,y2,tx2); sNew2];
sNew1 = 1 X 3061 array , the 50kHz array splined to a 600kHz array
sNew2 = 1 X 3070 array , the 200kHz array splined to a 600kHz array
Both arrays are very close to 0.00512 milli seconds but arnt exact. Am I missing something? Because I was under the impression by using the LCM(least common multiple) of all samplerates. Arrays should both be same size. I know I could just pad the arrays so thery're the same size. The size of the arrays are only off by a very small margin. But just curious if im doing something wrong?Also after I plan on downsampling both arrays to 300kHz but had this minor error.

Answers (1)

Kaashyap Pappu
Kaashyap Pappu on 22 Jan 2020
This could be due to the digital representation of the ‘upSamp’ values. These values are recurring decimals, but due to the digital word length, which are truncated.
For instance, considering the value is 0.33333…, but is digitized to 0.333. If 10000 samples are generated using both values, the original value should produce 3333.3 sample points in an ideal case, but would only produce 33300 samples.
Further information on this can be found here and in the Documentation . The first comment in the first link mentions why this behavior is observed. The documentation elaborates how MATLAB stores these variables.
Hope this helps!
  1 Comment
Kaashyap Pappu
Kaashyap Pappu on 22 Jan 2020
More information can be found in this thread:

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!