My task is to design a FSM whose output goes high for a single cycle whenever the pattern 0110 is detected on its input. The patterns may overlap, so an input 0110110 of would cause the output to go high twice- once for the first pattern (0110110), and once for the second pattern (0110110). a is used for the input and f is used for the output.
I am assuming I will need five state bubbles like this.
Is this correct or am I missing some cases based on the pattern going high twice if the pattern overlaps?
-
1$\begingroup$ The idea of output going "high" or "low" is probably not particularly familiar to Computer Scientists. I suspect most people here learned finite automata in terms of acceptor machines, reading in a string then either accepting or rejecting it. Are you using this for circuit/electrical design? $\endgroup$Joey Eremondi– Joey Eremondi2013年07月25日 06:31:41 +00:00Commented Jul 25, 2013 at 6:31
-
$\begingroup$ Possible dup: cs.stackexchange.com/q/11780/755 $\endgroup$D.W.– D.W. ♦2013年07月26日 06:10:04 +00:00Commented Jul 26, 2013 at 6:10
-
1$\begingroup$ @jmite: I know Computer Science is not about computers, but let's be honest: we know that much. At least I do :) $\endgroup$reinierpost– reinierpost2013年08月01日 15:47:50 +00:00Commented Aug 1, 2013 at 15:47
-
1$\begingroup$ It depends highly on the type of CS education, particularly whether a school does it as part of science or engineering. I'm not saying it's off topic, I'm just asking for some background. $\endgroup$Joey Eremondi– Joey Eremondi2013年08月01日 16:12:42 +00:00Commented Aug 1, 2013 at 16:12
-
1$\begingroup$ This is certainly not a duplicate of a question about nondeterministic finite automata: the asker seems to be looking for a circuit design and real electronic circuits are not nondeterministic. I also don't think the question is unclear so I'm voting to leave open. $\endgroup$David Richerby– David Richerby2015年04月01日 07:46:20 +00:00Commented Apr 1, 2015 at 7:46
2 Answers 2
It looks like you're missing the overlap case, if I understand your diagram correctly. This does the trick:
A // goto B if read 0 else stay
B // goto C if read 1 else stay
C // goto D if read 1 else goto B
D // goto E if read 0 else goto A
E // emit rising edge, goto B
assuming that you have a falling edge after every read.
This problem is just an instance of the substring searching problem, for the specific substring 0110ドル$. There are several algorithms that solve it.
Given that the search is to be done in real-time, I guess the best algorithm is the Knuth-Morris-Pratt algorithm. For any string to be searched, the KMP algorithm will compute the table for a DFA that recognizes all occurences of that string in any string given as input.
Note however that the finite state device to be constructed is not really a DFA, but a deterministic finite state transducer (also known as Generalized sequential machines - GSM), as it has an output for each transition, which is either low or high. The words low and high may be taken as symbol of an output alphabet, even if they have physical meaning in the context of the question.
I leave it as an exercise to apply the KMP algorithm to the specific example of the question, since the question is actually asking how to design the finite state transducer, and is not asking to actually do it.
Explore related questions
See similar questions with these tags.