How to recover signal if use window function to do

Voice related projects and technical discussions
link0513
Member++
Posts: 25
Joined: Tue Jul 02, 2019 8:38 am

How to recover signal if use window function to do

Postby link0513 » Mon Jul 29, 2019 9:37 am

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);
User avatar
CousinItt
XCore Addict
Posts: 140
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » 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.
link0513
Member++
Posts: 25
Joined: Tue Jul 02, 2019 8:38 am

Postby link0513 » Mon Jul 29, 2019 11:52 am

CousinItt 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.
This function is define in dsp_complex.h in lib_dsp 4.2 version
https://github.com/xmos/lib_dsp
link0513
Member++
Posts: 25
Joined: Tue Jul 02, 2019 8:38 am

Postby link0513 » Mon Jul 29, 2019 1:01 pm

And another question is about the Nyquist real term (in array[0].im) after FFT, what's this part use for?
User avatar
CousinItt
XCore Addict
Posts: 140
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » 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 post-FFT spectrum. I don't understand why it would be preferable time-domain 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.
User avatar
CousinItt
XCore Addict
Posts: 140
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Mon Jul 29, 2019 1:19 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 low-frequency high-pass filters in ADCs. If the input to the FFT is a real signal, the zero frequency complex component should be zero.
link0513
Member++
Posts: 25
Joined: Tue Jul 02, 2019 8:38 am

Postby link0513 » Tue Jul 30, 2019 1:51 am

CousinItt 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 post-FFT spectrum. I don't understand why it would be preferable time-domain 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.
Hi CousinItt
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).
User avatar
CousinItt
XCore Addict
Posts: 140
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » 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 more-or-less 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.
link0513
Member++
Posts: 25
Joined: Tue Jul 02, 2019 8:38 am

Postby link0513 » Wed Jul 31, 2019 2:35 am

CousinItt 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 more-or-less 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.
Thank you very much. According to you answer, I have below questions
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.
User avatar
CousinItt
XCore Addict
Posts: 140
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Wed Jul 31, 2019 4:32 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 band-limited?

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

Who is online

Users browsing this forum: No registered users and 0 guests