# Upsampling and zero order hold

Maybe to someone this question may seem quite easy but I have a problem grasping it. Namely, assume that we have two systems A and B with sampling rates $f_A$ and $f_B$ where $f_A>f_B$ and $R=\frac{f_A}{f_B}$. If we upsample system B by $R$ (i.e., $f_B=f_A$) using the zero order hold interpolation what is the relation between the time samples before ($n_{old}$) and after ($n_{new}$) upsampling? More precisely, we defined $\mathcal{N}_{old}=\{1,2,...,n_{old},..N_{old}\}$ and $\mathcal{N}_{new}=\{1,2,...,n_{new},..,R*N_{old}\}$ as sets of time samples before and after upsampling. Based on the definition of ZOH following relation should hold: $$n_{old}=\frac{n_{new}}{R}$$ i.e., every $R^{th}$ sample from $\mathcal{N}_{new}$ corresponds to the one time sample from $\mathcal{N}_{old}$ but if we for example take some $n_{new}$that is not multiple of $R$ we will get that $n_{old}$ is not an integer what doesn't make sense. What am I doing wrong?

• I want to provide an answer despite the fact the it's rather vague what exactly you are asking. But I think I have an opinion at least. Commented May 20, 2016 at 23:21

Assuming a digital (discrete-time) sample rate conversion (upsampling) operation carried on old samples of a signal x[n] to upsample it by an integer factor R by the utilization of a zero-order hold interpolation filter, you would essentially replicate (repeat) every new and empty (R-1) samples with the single old sample that they originate from. I guess the problem you have stems from the fact that you misinterpret the relation: $$n_{old}=\frac{n_{new}}{R}$$

which is correct for continuous variables but not if you consider the fact that both $n_{old}$,$n_{new}$,and $R$ are integers. Therefore it cannot hold true for those samples $n_{new}$ which are not integer multiples of $R$

To remedy your confusion with the ZOH output index calculation, you shall better use the following interpretation as a relation between new and old sample indices: $$n_{old} = \lfloor \frac{n_{new}}{R} \rfloor$$

Where floor, with brackets $\lfloor$, $\rfloor$ is the mathematical operation that returns the largest integer that is less than or equal to its argument.

Or you could, equally, define a ruling to map old and new samples as: index $n_{old}$ is equivalent to the integer $K$, for all those $n_{new}$ that satisfy $K R \leq n_{new} < (K+1)R$

• If I would index newly sampled samples as $\mathcal{N}_{new}=\{1,1,1,2,2,2...,n_{new},n_{new},n_{new},..,R*N_{old},R*N_{old},R*N_{old}\}$ for R=3 for example, would that be correct? In this way all $n_{new}$ fit to the initial formula (without flooring). I am doing some calculations where it is a little bit difficult to include flooring, i.e., I need that every $n_{new}$ can be included into calculations.
– Cali
Commented May 23, 2016 at 10:54
• When creating the new signal from the old signal you don't need that flooring here, all you need is a double-for loop in which outer loop will run trough the range of old indices from n=0 to n=Lold, and inner loop per n, will range through m=0 to m=R-1; and copy the expanded sample into those newly allocated (R-1) empty samples in between two consequitive old samples. (i.e. for(n=0; n<Lold; n++) { for(m=0; m<R; m++){ xnew[R*n + m] = xold[n] ;} } Commented May 23, 2016 at 13:39
• I agree and thx for your reply but this is solution if somebody has to implement this problem in some programming language. My concern is how to express this in analytical ("mathematical") way. I want to map all $n_{old}$ to each $n_{new}$ in a way that a have relation that I can after easily use in some mathematical computations. That is why I have proposed this new indexing but I am not sure does it hold.
– Cali
Commented May 23, 2016 at 14:30
• ok but if your concern is "mathematical" expression then just use floor? but you say it is difficult to compute (I don't know why btw) any way your ""abstract"" indexing is ok. it will give you a map between the two signals xold and xnew. Btw floor is just an integer division in C language. Commented May 23, 2016 at 14:42
• I agree regrading the flooring, it is quite simple operation but let's say I want to have just equality between $n_{new}$ and $n_{old}$ because I am expressing $n_{old}$ through $n_{new}$ and I am working with variables and not fixed numbers so having flooring makes my notation cumbersome. However, thank you very much for your help.
– Cali
Commented May 23, 2016 at 14:54