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

4.6.10 vsip_vmaxmgval_p - Find Maximum Magnitude Value in Vector

vsip_scalar_f vsip_vmaxmgval_f(const vsip_vview_f *a, vsip_scalar_vi *index);
Description

This function finds the maximum magnitude (absolute) value in a vector and returns its value while storing its index in the provided output parameter.

The function scans the input vector a and finds the element with the largest absolute value, returning this value and storing its index in the output parameter.

Parameters
Return Value
Example

vsip_vview_f *signal; 
vsip_scalar_f max_magnitude; 
vsip_scalar_vi max_index; 
vsip_length n = 1024; 
 
// Create vector 
signal = vsip_vcreate_f(n, VSIP_MEM_NONE); 
 
// Initialize signal with some values (e.g., a sine wave with noise) 
for (vsip_length i = 0; i < n; i++) { 
    float val = 10.0f * sin(2 * M_PI * i / n) + 2.0f * ((float)rand()/RAND_MAX - 0.5f); 
    vsip_vput_f(signal, i, val); 
} 
 
// Add a spike at position 42 for demonstration 
vsip_vput_f(signal, 42, 15.0f); 
 
// Find the maximum magnitude value and its index 
max_magnitude = vsip_vmaxmgval_f(signal, &max_index); 
 
printf("Maximum magnitude value: %.4f\n", max_magnitude); 
printf("Found at index: %ld\n", max_index); 
 
// Clean up 
vsip_valldestroy_f(signal);