vsip_vview_f* vsip_vcreate_hanning_f(vsip_length n, vsip_memory_hint hint);
This function creates and initializes a vector with coefficients of a Hanning window (also known as Hann window) of length
.
The Hanning window is defined by:
![( (2πk ))
w[k]= 0.5 1-cos ---- , 0≤ k< n
n-1](VSIPLCoreRef_PG200x.png)
vsip_length n: Length of the window (number of elements in the vector).
vsip_memory_hint hint: Memory allocation hint:
VSIP_MEM_NONE - No memory hint
VSIP_MEM_RDONLY - The memory is to be used read-only
VSIP_MEM_CONST - The memory will hold constants
VSIP_MEM_SHARED - The memory will be shared
VSIP_MEM_SHARED_RDONLY - The memory will be shared and is read-only
VSIP_MEM_SHARED_CONST - The memory will be shared and will hold constants
On success, returns a pointer to the newly created and initialized vector containing the Hanning window coefficients.
On error (e.g., if memory allocation fails), returns NULL.
vsip_vview_f *hanning_win; vsip_length n = 64; // Create a Hanning window hanning_win = vsip_vcreate_hanning_f(n, VSIP_MEM_NONE); if (hanning_win == NULL) { // Handle error } // Print first 5 coefficients printf("First 5 Hanning window coefficients:\n"); for (int i = 0; i < 5; i++) { printf("%f\n", vsip_vget_f(hanning_win, i)); } // Use the window in a signal processing application // For example, apply it to a signal vector vsip_vview_f *signal = vsip_vcreate_f(n, VSIP_MEM_NONE); vsip_vview_f *windowed_signal = vsip_vcreate_f(n, VSIP_MEM_NONE); // Initialize signal with some values (e.g., a sine wave) // vsip_vramp_f(0.0f, 1.0f, signal); // Apply the window: windowed_signal = signal * hanning_win vsip_vmul_f(signal, hanning_win, windowed_signal); // Clean up vsip_valldestroy_f(hanning_win); vsip_valldestroy_f(signal); vsip_valldestroy_f(windowed_signal);
The Hanning window is symmetric for even-length vectors and nearly symmetric for odd-length vectors.