Finding maximum of a matrix

Status
Not open for further replies.

sheikh

Advanced Member level 4
Joined
Sep 10, 2007
Messages
104
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
2,008
Hi Dear all
How can I calculate the maximum element of a NxN matrix? I know how to find it by matlab or C or even by using "for..loop" and "if" statements in vhdl but I am not sure that, Does this kind of coding synthesisable or not? ( I mean I didn't design a circuit for it before start to write the code). So what is your suggestion? Do I continue coding by "for..loop" and "if" statements or may be there are some designed units for it?
Regards
Mostafa
 

"For loop" is synthesizable but value of "N" must be known i.e. how many times loop will be executed, so if you know the order of matrix (N) then it will work fine. BUT if order is to be entered by user (variable) then it won't be synthesizable.
Hope this will be helpful.
 
Reactions: sheikh

    sheikh

    Points: 2
    Helpful Answer Positive Rating
you could do it like engineer sugested, but it wont synthesis to anything that will run at a decent clock speed for anything larger than about 3x3.

You need to pipeline the solution with a larger adder tree.
 
Reactions: sheikh

    sheikh

    Points: 2
    Helpful Answer Positive Rating
Thanks all.
@Tricky:
Could you please explain more?
 
Last edited:

using a big for loop will simply add them all in parrallel in a single clock cycle. This would be very slow.

You will need to manual create the pipeline.
 

Tricky, The op doesn't want to add the values but compare them for the maximum value.

I'm assuming the desire is to both get the maximum and produce the location of the value in the matrix...

There are two approaches as I see it right now.

1. The parallel approach which would require a comparator tree - compare two values (for all elements paired up) and pass the larger of each compare to the next compare stage. This will result in a very large circuit with relatively small MxN matrices.

2. If you can tolerate latency then a more software like approach would be much more efficient. Build an FSM that cycles through all the entries in the "memory array" (matrix) and compares for the largest entry. Cycle time is entirely dependent on the size of the matrix, but the design won't grow much regardless of the size of the matrix being examined. If the latency is too large break it up with more than one of the FSM's running in parallel.

Regards,
-alan
 
Reactions: sheikh

    sheikh

    Points: 2
    Helpful Answer Positive Rating
its still the same theory, as you have to compare every value to every other value.
 
Reactions: sheikh

    sheikh

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…