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.14 vsip_vcmaxmgsqval_p - Find Maximum Magnitude Squared Value in Complex Vector

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

This function finds the maximum 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 largest 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 max_magnitude_sq; 
vsip_scalar_vi max_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 a peak at position 42 
    float magnitude = (i == 42) ? 10.0f : 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 maximum magnitude squared value and its index 
max_magnitude_sq = vsip_vcmaxmgsqval_f(spectrum, &max_index); 
 
printf("Maximum magnitude squared value: %.4f\n", max_magnitude_sq); 
printf("Found at index: %ld\n", max_index); 
printf("Actual magnitude: %.4f\n", sqrt(max_magnitude_sq)); 
 
// Clean up 
vsip_cvalldestroy_f(spectrum);