Simulink 中的模式匹配
我正在尝试构建一个模型来比较特定位模式的输入。
例如,如果我必须检查输入模式 1110,我会构建一个具有 3 个延迟元素的模型,获取输入并将其连接起来,然后使用比较器与 14(十六进制 E)进行比较。
目前,我需要进行 128 位的模式匹配。按照前面的例子,我可以理想地构建使用 127 个延迟元素的类似模型并比较块。
但我想知道是否有一个最佳的和“更好”的方法来做到这一点。
期待在这方面提出一些建议。
如果您有兴趣,这里是我构建的用于提取 8 位的小模型:
I am trying to build a model to compare the input for a particular bit pattern.
For example, if I have to check for input pattern 1110, I build a model with 3 delay elements get the input and Concatenate it and then use a comparator to compare with 14(Hex E).
Currently, I need to do a pattern matching for 128 bits. Going by previous instance, I can ideally build the similar model of using 127 Delay elements and compare Blocks.
But I would like to know if there is a optimal and "better" way to do it.
Looking forward to some suggestion in this regard.
If you are interested, here is the small model I built to extract 8 bits:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所描述的是一种很好的通用方法 - 它对您想要检测的模式没有任何假设。
如果模式是(例如)一长串 1 然后 0,您可能可以做一些不同的事情(创建计数器来计算这些长度,并在计数器达到正确值时标记匹配)
我认为您可以使您的图表成为如果您创建了一个包含 z^-1 和 concat 的块,那么(也许)会容易一些。然后,当您传入输入时,您可以延迟它并将其与前一阶段的输出(也传入)连接起来。
另一方面,这在 VHDL 中被简单地描述为移位寄存器(一行代码)和匹配器(另一行代码)。
您可以在 m 代码块中(在类似的几行中)构建类似的东西,使用寄存器的持久变量,但如果您想实例化该块的多个实例,您可以不幸的是,
持久
存储在它们之间共享!What you have described is a fine generic approach - it assumes nothing about the patterns you want to detect.
You might be able to do something different if the pattern is (for example) a long string of 1s then 0s (create counters to count those lengths and flag a match if the counters reach the right values)
I think you could make your diagram a little easier (maybe) if you created a block with the z^-1 and concat inside. Then when you pass in the input, you can delay it and concat it with the previous stage's output (also passed in).
As another aside, this is trivially described in VHDL as a shift register (one line of code) and a matcher (another line of code).
You could build a similar thing in an m-code block (in a similar couple of lines), using
persistent
variables for registers, but if you want to instantiate more than one instance of the block you're out-of-luck as thepersistent
storage is shared across them!