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

Inverse Hann not working - or am I missing something? #69

Open
drp0 opened this issue Oct 4, 2021 · 0 comments
Open

Inverse Hann not working - or am I missing something? #69

drp0 opened this issue Oct 4, 2021 · 0 comments

Comments

@drp0
Copy link

drp0 commented Oct 4, 2021

I can :
FFT.Windowing(real, BUF_SIZE, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(real, imag, BUF_SIZE, FFT_FORWARD);
FFT.Compute(real, imag, BUF_SIZE, FFT_REVERSE);
FFT.Windowing(real, BUF_SIZE, FFT_WIN_TYP_HAMMING, FFT_REVERSE);

and get back the original data.
Without windowing I get back the original data.

If I try this with a HANN window some of the 1st and last values are undefined, or inaccurate.
Is this an issue with the inverse HANN windowing?
Or is it down to the nature of a HANN window?

See simple test below.. I have also tried with data ranging -128 to 128, 0 to 1 and -1 to +1.

David

#include  "arduinoFFT.h"
arduinoFFT FFT = arduinoFFT();
#define BUF_SIZE 256

void setup() {
Serial.begin (115200);
int I;
double orig[BUF_SIZE];
double real[BUF_SIZE];
double imag[BUF_SIZE];
float newval = 0;
  for (I = 0; I < BUF_SIZE; I++) {
  real[I] = newval;
  orig[I] = newval;
  newval ++;
  }

Serial.println("\nHann\n");
FFT.Windowing(real, BUF_SIZE, FFT_WIN_TYP_HANN, FFT_FORWARD);
FFT.Compute(real, imag, BUF_SIZE, FFT_FORWARD);
FFT.Compute(real, imag, BUF_SIZE, FFT_REVERSE);
FFT.Windowing(real, BUF_SIZE, FFT_WIN_TYP_HANN, FFT_REVERSE);
  for (I = 0; I< BUF_SIZE; I++){
  Serial.print(I); Serial.print("\t"); Serial.print(orig[I]);
  Serial.print("\t"); Serial.print(real[I], 6);
    if (abs(real[I] - orig[I]) > 0.01) Serial.println(" ak"); else Serial.println(); 
  }

Serial.println("\nHamming\n");
// reset for HAMMING
  for (I = 0; I < BUF_SIZE; I++) {
  real[I] = orig[I];
  imag[I] = 0;
  }
FFT.Windowing(real, BUF_SIZE, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(real, imag, BUF_SIZE, FFT_FORWARD);
FFT.Compute(real, imag, BUF_SIZE, FFT_REVERSE);
FFT.Windowing(real, BUF_SIZE, FFT_WIN_TYP_HAMMING, FFT_REVERSE);

  for (I = 0; I< BUF_SIZE; I++){
  Serial.print(I); Serial.print("\t"); Serial.print(orig[I]);
  Serial.print("\t"); Serial.print(real[I], 6);
    if (abs(real[I] - orig[I]) > 0.01) Serial.println(" ak"); else Serial.println();  
  }
}

void loop() {
}

Hann

0 0.00 inf ak
1 1.00 1.023717 ak
2 2.00 2.048339 ak
3 3.00 3.021425 ak
4 4.00 4.000010
5 5.00 5.004950
6 6.00 6.008430
7 7.00 7.007216
8 8.00 8.004227
9 9.00 9.004525
...
246 246.00 246.007217
247 247.00 247.008926
248 248.00 248.008712
249 249.00 249.013732 ak
250 250.00 250.027526 ak
251 251.00 251.042877 ak
252 252.00 252.051025 ak
253 253.00 253.144409 ak
254 254.00 254.905548 ak
255 255.00 inf ak

Hamming

0 0.00 0.000048
1 1.00 1.000089
2 2.00 2.000482
3 3.00 3.000634
4 4.00 3.999955
5 5.00 5.000478
6 6.00 6.000649
7 7.00 7.000646
8 8.00 8.000188
...
246 246.00 246.000656
247 247.00 247.000656
248 248.00 248.000534
249 249.00 249.000732
250 250.00 250.000823
251 251.00 251.001190
252 252.00 252.000671
253 253.00 253.000747
254 254.00 254.000869
255 255.00 255.001068

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