I use FFT to analyze signal and IFFT to recover the signal. If I add haning window when FFT, the signal can't recover by IFFT. I am not very good at algorithm, please help.
dsp_fft_bit_reverse_and_forward_real(sample,512,dsp_sine_256,dsp_sine_512);
dsp_complex_t * local = (int32_t *)sample;
dsp_complex_window_hanning_post_fft_half(local,512); //add window
dsp_fft_bit_reverse_and_inverse_real(local,512,dsp_sine_256,dsp_sine_512);
How to recover signal if use window function to do

 Member++
 Posts: 26
 Joined: Tue Jul 02, 2019 8:38 am

 Respected Member
 Posts: 265
 Joined: Wed May 31, 2017 6:55 pm
As I understand it, windowing is usually applied before the forward FFT as it avoids spectral leakage due to discontinuities at the ends of the input sequence. Can you provide a reference for dsp_complex_window_hanning_post_fft_half()? I can't find it on git_hub.

 Member++
 Posts: 26
 Joined: Tue Jul 02, 2019 8:38 am
This function is define in dsp_complex.h in lib_dsp 4.2 versionCousinItt wrote: ↑Mon Jul 29, 2019 11:38 am As I understand it, windowing is usually applied before the forward FFT as it avoids spectral leakage due to discontinuities at the ends of the input sequence. Can you provide a reference for dsp_complex_window_hanning_post_fft_half()? I can't find it on git_hub.
https://github.com/xmos/lib_dsp

 Member++
 Posts: 26
 Joined: Tue Jul 02, 2019 8:38 am
And another question is about the Nyquist real term (in array[0].im) after FFT, what's this part use for?

 Respected Member
 Posts: 265
 Joined: Wed May 31, 2017 6:55 pm
See here:
https://www.researchgate.net/post/How_C ... puting_FFT
The linked article on embedded.com is interesting. I assume the algorithm convolves the window function with the postFFT spectrum. I don't understand why it would be preferable timedomain windowing.
When you say you can't recover the original signal, why would you expect to? It's going to be different after the window function is applied.
https://www.researchgate.net/post/How_C ... puting_FFT
The linked article on embedded.com is interesting. I assume the algorithm convolves the window function with the postFFT spectrum. I don't understand why it would be preferable timedomain windowing.
When you say you can't recover the original signal, why would you expect to? It's going to be different after the window function is applied.

 Respected Member
 Posts: 265
 Joined: Wed May 31, 2017 6:55 pm
The first real term is the d.c. level  this is likely to be very close to zero in a typical audio application, with a.c. coupling in audio circuitry and lowfrequency highpass filters in ADCs. If the input to the FFT is a real signal, the zero frequency complex component should be zero.

 Member++
 Posts: 26
 Joined: Tue Jul 02, 2019 8:38 am
Hi CousinIttCousinItt wrote: ↑Mon Jul 29, 2019 1:16 pm See here:
https://www.researchgate.net/post/How_C ... puting_FFT
The linked article on embedded.com is interesting. I assume the algorithm convolves the window function with the postFFT spectrum. I don't understand why it would be preferable timedomain windowing.
When you say you can't recover the original signal, why would you expect to? It's going to be different after the window function is applied.
Below is the define about dsp_complex_window_hanning_post_fft_half in dsp_complex.h file. I just want to confirm that the signal can be recovered after FFT and IFFT and then I input a sine signal but output signal is not a good sine. If I remove window function, the result is good. What is the affect about the window function?
And when input a real signal (sine signal), the output first real term is a big number after FFT. But what I really want to know is the Nyquist real term (in array[0].im). what about this part is used for?
/** Function that performs a Hanning window post FFT. That is, the FFT is
* performed with a rectangular window (no window), and this function is
* called on the resulting real spectrum.
* The input array shall contain N points, where N is a power of 2 greater than
* or equal to 4. The input array shall contain the FFT spectrum in indices
* 1..N, with element zero containing the DC real term (in array[0].re) and the
* Nyquist real term (in array[0].im).

 Respected Member
 Posts: 265
 Joined: Wed May 31, 2017 6:55 pm
OK, it's just the real part of the component at the Nyquist frequency, i.e. Fs/2, where Fs is the sampling frequency. I guess it will be as useful as any other component; I'm not aware of any particular use for it but maybe I'm just ignorant. It's using a spare location, since the imaginary part of the zero frequency component will be zero for a real signal.
Windowing functions are used because, normally, when you take a sequence of samples of a real signal it won't contain a single cycle or a multiple of cycles of all the components. The output of the DFT will be distorted because of it. Windowing smoothly tapers off the ends of the sequence so that the resulting spectrum is less distorted (using some measure).
The DFT and IDFT are complementary operations, so if you run the forward transform and then the inverse transform on the result, you'll get out moreorless exactly what you put in. Your code is applying the window between the transforms, but the result should be the same as if you've applied the window first. Try plotting the output of your code, and you should see a sine wave sequence with the beginning and end tapering to zero.
Windowing functions are used because, normally, when you take a sequence of samples of a real signal it won't contain a single cycle or a multiple of cycles of all the components. The output of the DFT will be distorted because of it. Windowing smoothly tapers off the ends of the sequence so that the resulting spectrum is less distorted (using some measure).
The DFT and IDFT are complementary operations, so if you run the forward transform and then the inverse transform on the result, you'll get out moreorless exactly what you put in. Your code is applying the window between the transforms, but the result should be the same as if you've applied the window first. Try plotting the output of your code, and you should see a sine wave sequence with the beginning and end tapering to zero.

 Member++
 Posts: 26
 Joined: Tue Jul 02, 2019 8:38 am
Thank you very much. According to you answer, I have below questionsCousinItt wrote: ↑Tue Jul 30, 2019 4:16 pm OK, it's just the real part of the component at the Nyquist frequency, i.e. Fs/2, where Fs is the sampling frequency. I guess it will be as useful as any other component; I'm not aware of any particular use for it but maybe I'm just ignorant. It's using a spare location, since the imaginary part of the zero frequency component will be zero for a real signal.
Windowing functions are used because, normally, when you take a sequence of samples of a real signal it won't contain a single cycle or a multiple of cycles of all the components. The output of the DFT will be distorted because of it. Windowing smoothly tapers off the ends of the sequence so that the resulting spectrum is less distorted (using some measure).
The DFT and IDFT are complementary operations, so if you run the forward transform and then the inverse transform on the result, you'll get out moreorless exactly what you put in. Your code is applying the window between the transforms, but the result should be the same as if you've applied the window first. Try plotting the output of your code, and you should see a sine wave sequence with the beginning and end tapering to zero.
1. If the Nyquist is the Fs/2, it should be the same if the sample frequency don't change. But accord to my result, this component is different every time.
2. According to the comment in dsp_complex.h, the window function is used between the transforms. Actually, I'm using spectral subtraction to eliminate noise and window function is a must .If applying window function to do some operation, and then how to do can I get data to do IDFT to eliminate effect which window function bring up.

 Respected Member
 Posts: 265
 Joined: Wed May 31, 2017 6:55 pm
Ideally the Nyquist component should be small, because if it's not then you're on the verge of aliasing. When you say it's different, is it large? Is your input data appropriately bandlimited?
I understand that the window function is being applied after the forward transform, but the effect would have to give the same result as the usual method. I'm not sure why you're using a window function in this case. Have you tried simply not using it? Take a look at this example https://exnumerus.blogspot.com/2011/12 ... using.html
I understand that the window function is being applied after the forward transform, but the effect would have to give the same result as the usual method. I'm not sure why you're using a window function in this case. Have you tried simply not using it? Take a look at this example https://exnumerus.blogspot.com/2011/12 ... using.html