MyTetra Share
Делитесь знаниями!
Интерполяция 3 степени (оптимизированная)
Время создания: 19.09.2019 16:16
Раздел: Computer - Programming - C

#include <stdio.h>

#include <stdint.h>

#include <math.h>


#define CURR 0

#define PREV 1


int main()

{

float *BufProbe = new float [2048]; //Бфуер входного сгнала

float *BufProbe05 = new float [2048]; //Буфер интерполированыых промежуточных отсчетов


static const float Pi = 3.14159265358979323846;

static const uint16_t N = 256;


//Generating random array

for(int i=0; i<N; ++i)

{

BufProbe[i] = 200.0*sin((Pi*(double)i)/10.0)*sin((Pi*(double)i)/178.0);

}




{

float c[2] = {0.0};

float d, b;

float delta[N+1];

float lambda[N+1];


static const float Hk = 1.0;


delta[1] = - 0.25;

lambda[1] = 1.5 * ((BufProbe[2] - BufProbe[1]) - (BufProbe[1] - BufProbe[0])) / 2.0;


for(uint16_t i=2; i<=N; ++i)

{

delta[i] = -Hk / (4.0 + delta[i-1]);

lambda[i] = (3.0 * ((BufProbe[i+1] - BufProbe[i]) - (BufProbe[i] - BufProbe[i-1])) - lambda[i-1])

/ (4.0 + delta[i-1]);

}


c[CURR] = 0;

for(uint16_t i=N; i>0; --i)

{

if(i == 1)

c[PREV] = 0;

else

c[PREV] = delta[i-1] * c[CURR] + lambda[i-1];

d = (c[CURR] - c[PREV]) / 3.0;

b = (BufProbe[i] - BufProbe[i-1]) + (2.0 * c[CURR] + c[PREV]) / 3.0;

BufProbe05[i] = BufProbe[i] + (b * 0.5) + (c[CURR] * pow(0.5, 2)) + (d * pow(0.5, 3));


c[CURR] = c[PREV];

}


BufProbe05[0] = 0;

}



for(int i=0; i<N; ++i)

{

printf("%i: %f ___ %f\n\r", i, BufProbe[i], BufProbe05[i]);

}



getchar();


return 0;

}

 
MyTetra Share v.0.53
Яндекс индекс цитирования