# Getting Rank of Elements in an Array using VHDL...

M

#### Md Multan Biswas

##### Guest
Dear VHDL Coders,

I am trying to get the rank of elements from an array of data. For example, I have an array, Voltage = [20 40 10 30] ;

The position of the elements in the voltage array is ranged from 0 to 3.

Using a bubble sorting algorithm, I obtained the position index of the elements in the array as follows:
Index (0)= 2 ; Index (1)= 0 ; Index (2)= 3 ; Index (3)= 1 ;

However, basically I just the rank of the elements in the voltage array. I expect to get:
Rank (0) = 1 ; Rank (1) = 3 ; Rank (2) = 0 ; Rank (3) = 2 ;

I would appreciate any of your help and suggestion to get the desired outcome using the VHDL code. Thanks, a bunch in advance K

#### Kevin

##### Guest
Md Multan Biswas schrieb am Dienstag, 21. Juni 2022 um 08:51:22 UTC-6:
Dear VHDL Coders,

I am trying to get the rank of elements from an array of data. For example, I have an array, Voltage = [20 40 10 30] ;

The position of the elements in the voltage array is ranged from 0 to 3.

Using a bubble sorting algorithm, I obtained the position index of the elements in the array as follows:
Index (0)= 2 ; Index (1)= 0 ; Index (2)= 3 ; Index (3)= 1 ;

However, basically I just the rank of the elements in the voltage array. I expect to get:
Rank (0) = 1 ; Rank (1) = 3 ; Rank (2) = 0 ; Rank (3) = 2 ;

I would appreciate any of your help and suggestion to get the desired outcome using the VHDL code. Thanks, a bunch in advance If you are asking how to sort from largest-to-smallest instead of smallest-to-largest, that is easy to do by a slight changed of the algorithm or by a wire-reversal at the end of the sort.

I recently built a sorter (in Verilog) and I found that the best sort algorithm for hardware, if you are doing a full-parallel sort, is the Batcher Odd-Even Mergesort. I did not find any good HDL examples, though, and had to start from scratch. The Bitonic Sort is OK, but not quite as efficient in hardware. If you have a lot of time, a parallelized bubble sort might work fine.

### Welcome to EDABoard.com 