Simulink中如何获取一个数的最大值?
我正在构建一个模型,需要找到一组 8 个信号中的最大值,并找到最大值的索引。
如何在 Simulink(Xilinx 库)中构建这样的模型?
我猜测比较块后面跟着一个计数器块。但不知何故,我无法将所有事情放在一起。
谢谢
I am building a model which requires me to find the maximum of a set of 8 signals, also find the index of the maximum value.
How can I build such a model in Simulink(Xilinx library) ?
I am guessing Compare block followed by a counter block. But somehow, I am not able to figure all things together.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并行完成这一切的一种方法是:
您需要构建一个比较器和多路复用器的树:
这可以通过管道传输,以便您可以按照自己的意愿快速地通过它倒入数据。但它会使用相当多的资源。你的信号有多宽?每个比较器的每位有 1 个 LUT4,2:1 多路复用器的每位有 1 个 LUT4。
或者,您可以使用计数器依次选择每个值。如果它大于当前最大值,则将该值锁存到“最大”寄存器中,并将计数器锁存到“最大索引”寄存器中。每次计数器重置时,将“最大”寄存器重置为最小值。
这将需要与您有信号一样多的时钟周期(在您的情况下是 8 个)
One way which gets it all done in parallel:
You need to build a tree of comparators and multiplexers:
This can be pipelined so you can pour data through it as fast as you like. But it'll use a fair amount of resource. How wide are your signals? Each comparator is 1 LUT4 per bit and a 2:1 mux is 1 LUT4 per bit.
Alternatively, you use a counter to select each of your values in turn. If it's bigger than the current biggest, latch the value into your "biggest" register and latch the counter into a "biggest index" register. Reset the "biggest" register to the smallest value each time your counter resets.
This will take as many clock cycles as you have signal (8 in your case)