ええ、それはそれを行う方法です。
このサンプル C コードはそれを示しています。
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979324
#endif
typedef struct
{
double x, y;
} tComplex;
tComplex complexAdd(const tComplex* a, const tComplex* b)
{
tComplex c;
c.x = a->x + b->x;
c.y = a->y + b->y;
return c;
}
tComplex complexMul(const tComplex* a, const tComplex* b)
{
tComplex c;
c.x = a->x * b->x - a->y * b->y;
c.y = a->x * b->y + a->y * b->x;
return c;
}
void dft(tComplex out[], const tComplex in[], size_t n, int direction)
{
size_t k, i;
for (k = 0; k < n; k++)
{
tComplex r = { 0, 0 }, e;
for (i = 0; i < n; i++)
{
e.x = cos(-2 * direction * M_PI / n * ((double)k - n / 2) * ((double)i - n / 2));
e.y = sin(-2 * direction * M_PI / n * ((double)k - n / 2) * ((double)i - n / 2));
e = complexMul(&e, &in[i]);
r = complexAdd(&r, &e);
}
out[k] = r;
}
}
double maxAbs(const tComplex in[], size_t n)
{
double m = 0;
while (n--)
{
double a = hypot(in->x, in->y);
if (m < a) m = a;
in++;
}
return m;
}
#define SAMPLE_CNT 32
#define SAMPLE_SHIFT 3
int main(void)
{
tComplex signalIn[SAMPLE_CNT];
tComplex signalOut[SAMPLE_CNT];
tComplex tmp[SAMPLE_CNT];
int i;
// signalIn[] = square pulse
for (i = 0; i < SAMPLE_CNT; i++)
{
signalIn[i].x = ((i - SAMPLE_CNT / 2) >= 0) * ((i - SAMPLE_CNT / 2) < SAMPLE_CNT / 4);
signalIn[i].y = 0;
}
// tmp[] = DFT{signalIn[]}
dft(tmp, signalIn, SAMPLE_CNT, 1);
// tmp[] = DFT{signalIn[]} * exp(j * 2 * PI * f * TimeShift)
for (i = 0; i < SAMPLE_CNT; i++)
{
tComplex e;
e.x = cos(2 * M_PI * (i - SAMPLE_CNT / 2) * SAMPLE_SHIFT / SAMPLE_CNT);
e.y = -sin(2 * M_PI * (i - SAMPLE_CNT / 2) * SAMPLE_SHIFT / SAMPLE_CNT);
tmp[i] = complexMul(&tmp[i], &e);
}
// signalOut[] = IDFT{tmp[]}
dft(signalOut, tmp, SAMPLE_CNT, -1);
printf(" Re{In[]} . Im{In[]} |"
" |DFT{In[]}| |"
" Re{Out[]} . Im{Out[]}\n");
for (i = 0; i < SAMPLE_CNT; i++)
{
int j, s;
s = signalIn[i].x / maxAbs(signalIn, SAMPLE_CNT) * 8 + .5;
for (j = -8; j <= 8; j++) printf("%c", " *"[s == j]);
printf(".");
s = signalIn[i].y / maxAbs(signalIn, SAMPLE_CNT) * 8 + .5;
for (j = -8; j <= 8; j++) printf("%c", " *"[s == j]);
printf("|");
s = hypot(tmp[i].x, tmp[i].y) / maxAbs(tmp, SAMPLE_CNT) * 8;
for (j = -8; j <= 8; j++) printf("%c", " *"[s == j]);
printf("|");
s = signalOut[i].x / maxAbs(signalOut, SAMPLE_CNT) * 8 + .5;
for (j = -8; j <= 8; j++) printf("%c", " *"[s == j]);
printf(".");
s = signalOut[i].y / maxAbs(signalOut, SAMPLE_CNT) * 8 + .5;
for (j = -8; j <= 8; j++) printf("%c", " *"[s == j]);
printf("\n");
}
return 0;
}
出力:
Re{In[]} . Im{In[]} | |DFT{In[]}| | Re{Out[]} . Im{Out[]}
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
*. * | *| * . *
*. * | * | * . *
*. * | * | * . *
*. * | * | *. *
*. * | * | *. *
*. * | * | *. *
*. * | * | *. *
*. * | * | *. *
* . * | * | *. *
* . * | * | *. *
* . * | * | *. *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
SAMPLE_SHIFT
出力は、時間的にサンプル (ここでは 3)シフトされた入力のレプリカであることがわかります。
整数以外の値に変更SAMPLE_SHIFT
して、サンプルの分数でシフトを取得することもできます。
SAMPLE_SHIFT
= 2.5の出力:
Re{In[]} . Im{In[]} | |DFT{In[]}| | Re{Out[]} . Im{Out[]}
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
*. * | *| * . *
*. * | * | * . *
*. * | * | * . *
*. * | * | *. *
*. * | * | * . *
*. * | * | * . *
*. * | * | * . *
*. * | * | * . *
* . * | * | * . *
* . * | * | *. *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *
* . * | * | * . *