Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

State Machine to MATLAB code

Status
Not open for further replies.

chiu

Newbie level 3
Joined
Feb 19, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
how can i simulate the following state machine in MATLAB?
could you please write the code? im a newbie :p
**broken link removed**
attachment.php
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    71.9 KB · Views: 441
Last edited:

Check if that tutorial helps you :

**broken link removed**

+++
 

this is the block diagram



my code is like this:

function [ y1,y2,D1,D2 ] = Encoder(input)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
length_input = length(input);
y1(1) = input(1);
D1(1) = 0;
D2(1) = 0;
y2(1) = input(1);
for i = 2:length_input
y1(i) = input(i);
y2(i) = xor(input(i),D2(i-1));
D1(i) = xor(y2(i-1),input(i));
D2(i) = xor(D1(i-1),y2(i-1));
end
end

i insert a group of date [1 1 0 1 1 0 0 0]

using the state machine ,the output should be [11 10 01 10 10 01 00 01]

but i run my code and got a set of wrong output which is [11 11 01 10 11 00 00 01]

could you please see if there is any problem in my code?
 

it might be easier to draw the state machine instead of writing it out textually. Stateflow (another product by MathWorks, makers of MATLAB and Simulink) is probably the best tool to represent state machine logic like this. Look at some of the getting started videos on the Stateflow website:
**broken link removed**
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top