Hi everybody, I have implemented Hann windowing function as follows: var N = samples.Length / 2; for (int i = 0; i < samples.Length; i++) { samples[i] *= 0.5 - 0.5 * Math.Cos((2 * Math.PI * i) / (N - 1)); } Samples field consists of varying real and imaginary values. When i apply Hann window my signal mirrors every time at negative frequency, ergo the peak should be at 5kHz only but it also appears at -5kHz after the operation mentioned above. What do I miss? Thanks for your advice! --------------------------------------- Posted through http://www.DSPRelated.com
Hanning window - I/Q signal
Started by ●February 4, 2016
Reply by ●February 5, 20162016-02-05
On Thursday, February 4, 2016 at 7:41:15 PM UTC+1, r.a.m- wrote:> I have implemented Hann windowing function as follows: > > var N = samples.Length / 2; > for (int i = 0; i < samples.Length; i++) { > samples[i] *= 0.5 - 0.5 * Math.Cos((2 * Math.PI * i) / (N - 1)); > } > > Samples field consists of varying real and imaginary values.I'm not sure I understand what samples really is. Is it a double[] with interleaved real and imaginary components or is it a Complex[]? Either way, your code snippet seems wrong. If samples is a Complex[] you would not divide the array length by two, would you? If samples is a double[] with interleaved real and imaginary components the function you want probably looks more like this: var N = samples.Length / 2; for (int i = 0; i < samples.Length; i++) { double w = 0.5 - 0.5 * Math.Cos((2 * Math.PI * i) / (N - 1)); samples[2*i+0] *= w; samples[2*i+1] *= w; } It is important to use the same scaling factor for real and imaginary part. You basically used slightly different factors and applied a short window on only the first half of the array. Inconsistent scale factors between real and imaginary parts can account for some aliasing (5 kHz mirroring to -5 kHz) to some extent. In the extreme case you can multiply the imaginary part by 0 and then the spectrum has to be symmetric around 0 Hz. ;-) Cheers! sg