Interpolation

ZXNet echo conference «code.zx»

From Alexander Ageev To Leonid Mishankov 13 January 2000

Hello Leonid! Wednesday January 12 2000 00:49, Leonid Mishankov wrote to Alexander Ageev: AA>> There are a lot of interpolation options, the choice depends on the required quality AA>> and time spent. The simplest option is linear AA>> interpolation, LM> points between every 2 samples are obtained by drawing a line LM> between these 2 samples? Yes. Moreover, you can take more points, for example 3, and build an equation based on them parabolas ax^2+bx+c - the quality will be better. If you have free time, you can do cubic interpolation using 4 points. But these are all bad methods in terms of quality, but good in terms of speed %) LM> It all started with the fact that I had a sine of 128 points and an amplitude too LM> 128 points. But it looked not like a full-fledged harmonic function, but LM> as a set of points. So I want to get a beautiful nerve sinus. #define PI 3.141592653589793238462643 static float Sinc (float A,float X,float X0) { X-=X0; if (!X) return A; X*=PI; return (A*sin(X)/(X)); } This is sinc. To obtain an interpolated value at some point X call sinc as many times as you have samples, passingas arguments X0 is the sample number, and A is the amplitude of this sample. You sum up the results and you get the answer. For example: sample number amplitude 0 12 1 21 2 35 4 23 You need to get the value exactly between the first and second readings: sinc(12,0.5,0)+sinc(21,0.5,1)+sinc(35,0.5,2) ... And so on for EVERY output sample. LM> But this does not necessarily apply to sine, the implementation is important LM> interpolation in theory, which would be suitable for all cases of life. Life is about compromises, there are no perfect solutions. Stinger.