Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Community Forums
- :
- Forums
- :
- Vivado RTL Development
- :
- Synthesis
- :
- how to find most frequent element in an array in v...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

wyh@521

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-18-2019 02:15 AM

812 Views

Registered:
01-15-2019

I want to get the most frequent element in an array, for example , an array [1,2,1,3,1,4,1,5], the most frequent element is 1. but how to write the code ?

I referred other language to find the most frequent element , if have any error ,please tell me.

wire [21:0] A [0:7];

reg [16:0] curr_count=1;

reg [16:0] max_count=1;

reg [16:0] res= A[0];

integer i;

always @ (posedge CLK )

begin

if (RST_X)

begin

for(i=0; i<7; i=i+1)

begin

curr_count <= 0;

end

end

else if ( A[i]==A[i-1])

begin

curr_count <= curr_count+1;

end

else if ( curr_count> max_count)

begin

max_count <= curr_count;

res <= A[i - 1];

end

end

Im not sure the following syntax.

//else if ( A[i]==A[i-1])

begin

curr_count <= curr_count+1;

end//

I think this syntax just stated to compare with Whether the adjacent numbers are equal.

who can help me to correct this code ?

1 Solution

Accepted Solutions

Highlighted

jmcclusk

Mentor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-18-2019 07:58 AM

758 Views

Registered:
02-24-2014

What you need is called a Histogram function.. After computing the histogram, then it's a matter of finding the histogram index with the highest value.

Here is an example of VHDL that implements a histogram function. you can then add an output stage that finds the peak value of the histogram.

Now of course your target language is verilog, but this some elbow grease, you should be able to convert from VHDL to verilog.

good luck!

John

Don't forget to close a thread when possible by accepting a post as a solution.

1 Reply

Highlighted

jmcclusk

Mentor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-18-2019 07:58 AM

759 Views

Registered:
02-24-2014

What you need is called a Histogram function.. After computing the histogram, then it's a matter of finding the histogram index with the highest value.

Here is an example of VHDL that implements a histogram function. you can then add an output stage that finds the peak value of the histogram.

Now of course your target language is verilog, but this some elbow grease, you should be able to convert from VHDL to verilog.

good luck!

John

Don't forget to close a thread when possible by accepting a post as a solution.