Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Spectrum Computation #104

Open
00sapo opened this issue May 30, 2021 · 1 comment
Open

Wrong Spectrum Computation #104

00sapo opened this issue May 30, 2021 · 1 comment

Comments

@00sapo
Copy link

00sapo commented May 30, 2021

LibXtract/src/vector.c

Lines 323 to 373 in 41273dd

default:
/* MAGNITUDE_SPECTRUM */
for(n = 0, m = 0; m < M; ++n, ++m)
{
if(n==0 && !withDC) /* discard DC and keep Nyquist */
{
++n;
}
#ifdef USE_OOURA
/*
if(n==1 && withDC) // discard Nyquist
{
++n;
}
*/
// OOURA discards the always 0 imaginary of DC and Nyquists
if (n == M && !withDC)
{
real = fft[1];
imag = 0.0;
}
else if (n == 0 && withDC) {
real = fft[0];
imag = 0.0;
}
else {
real = fft[n * 2];
imag = fft[n * 2 + 1];
}
#else
if (n == M && !withDC)
{
real = fft->imagp[0];
imag = 0.0;
}
else if (n == 0 && withDC) {
real = fft->realp[0];
imag = 0.0;
}
else {
real = fft->realp[n];
imag = fft->imagp[n];
}
#endif
result[m*2] = real;
result[m*2+1] = imag;
XTRACT_SET_FREQUENCY;
XTRACT_GET_MAX;
}
break;
}

I was trying to implement a higher level API in Julia and I've found these two lines that seem wrong to me. Shouldn't it compute the euclidean distance between imag and real? The following two lines seems copied from the previous clause:

LibXtract/src/vector.c

Lines 367 to 368 in 41273dd

result[m*2] = real;
result[m*2+1] = imag;

If you confirm, I can do a pull request

@00sapo
Copy link
Author

00sapo commented May 31, 2021

I noted that in master branch there is the following line:

*marker = sqrt(XTRACT_SQ(real) + XTRACT_SQ(imag)) / (double)N;

So, I think develop branch is wrong. I cannot compile master branch, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant