Adelsbach/VSIPL
Core Programming Reference Guide
DD-00016-015
Core

This manual is preliminary and incomplete.
While our Core implementation implements all functions given in the standard we are still working on completing this documentation.

Please refer to the VSIPL standard for a complete function reference of the Core profile until we have completed work on this documentation.

4.6.15 vsip_vcminmgsqval_p - Find Minimum Magnitude Squared Value in Complex Vector

vsip_scalar_f vsip_vcminmgsqval_f(const vsip_cvview_f *a, vsip_scalar_vi *index);
Description

This function finds the minimum magnitude squared value in a complex vector and returns its value while storing its index in the provided output parameter.

The function scans the input complex vector a and finds the element with the smallest magnitude squared value (real part squared plus imaginary part squared), returning this value and storing its index in the output parameter.

The magnitude squared is calculated as:

|ai| 2= real(ai)2+ imag(ai)2
Parameters
Return Value
Example

vsip_cvview_f *spectrum; 
vsip_scalar_f min_magnitude_sq; 
vsip_scalar_vi min_index; 
vsip_length n = 1024; 
 
// Create complex vector for spectrum data 
spectrum = vsip_cvcreate_f(n, VSIP_MEM_NONE); 
 
// Initialize with some complex spectrum data (e.g., FFT results) 
for (vsip_length i = 0; i < n; i++) { 
    // Simulate a spectrum with mostly small values and one very small value 
    float magnitude = (i == 123) ? 0.001f : 0.1f + 0.9f * (float)rand()/RAND_MAX; 
    float phase = 2 * M_PI * (float)rand()/RAND_MAX; 
    vsip_cscalar_f val = VSIP_CMPLX_F(magnitude * cos(phase), magnitude * sin(phase)); 
    vsip_cvput_f(spectrum, i, val); 
} 
 
// Find the minimum magnitude squared value and its index 
min_magnitude_sq = vsip_vcminmgsqval_f(spectrum, &min_index); 
 
printf("Minimum magnitude squared value: %.6f\n", min_magnitude_sq); 
printf("Found at index: %ld\n", min_index); 
printf("Actual magnitude: %.6f\n", sqrt(min_magnitude_sq)); 
 
// Clean up 
vsip_cvalldestroy_f(spectrum);