variable declaration in simulink

3 Ansichten (letzte 30 Tage)
BabuLal
BabuLal am 31 Mär. 2011
% This is a sample code in which I have a variable weight.Initially it has 0.9999 value ofter that it will changes as per the given code.i.e for every sample of input, weight will be compared with input and match = min(input,weight),after this weight will be changing based on some conditions,and again it will be compared with next input sample. How Can I implement the Weight variable in Simulink HdlCoder. That is in hardware point of view weight is a register Please give me some idea?
Here is my sample code:-
[FileName,PathName,FilterIndex] = uigetfile('*.xls');
File = strcat(PathName,FileName);
[status,sheets,format] = xlsfinfo(File);
testvectordata = xlsread(File,sheets{1,1});
for i = 1:16
weight(1,i) = 0.9999;
weight(2,i) = 0.9999;
weight(3,i) = 0.9999;
weight(4,i) = 0.9999;
end
for n=1:size(testvectordata,1)-1
input(n,1) = testvectordata(n,1);
input(n,2) = testvectordata(n,2);
end
Input_a = input(:,1);
Input_b = input(:,2);
Input_a = Input_a';
Input_a_c = 1 - Input_a;
Input_b = Input_b';
Input_b_c = 1 - Input_b;
for i = 1:size(Input_a') % Number of samples
%%input sample to the BLOCK
%===============================================================================
in_data = [Input_a(1,i);Input_a_c(1,i);Input_b(1,i);Input_b_c(1,i)];
for j = 1:16 % 16 parallel nodes and each node has 4 weights
match(:,j) = min(in_data,weight(:,j));
MatchVector_Sum = sum(match(:,j));
Weight_Sum = sum(weight(:,j));
if ((MatchVector_Sum/2) >= vigilance )
Test(j) = MatchVector_Sum/(0.1 + Weight_Sum);
else
Test(j) = 0;
end
end
[TJ,Index] = max(Test);
id = Index(1);
weight(:,id) = match(:,id); % Update weight
Category = [Category;id];
%==============================================================================
end

Antworten (1)

Tim McBrayer
Tim McBrayer am 11 Apr. 2011
Since you are starting with MATLAB code you will probably want to use the MATLAB Function block in Simulink. This will be more straightforward to get working than reimplementing your algorithm using Simulink blocks. The first step will be to separate your testbench code (uigetfile, xlsread, etc.) from your design code and place only the design code in the function block. Then, to make 'weight' a register you will need to make it a persistent variable in the function block.
Additionally: while Simulink HDL Coder supports doubles for code generation, they in general are not synthesizable. You will probably want to convert your code to use fixed-point arithmetic if you want to synthesize your design.
The Simulink HDL Coder demo "An 8-bit RISC Processor using MATLAB Function Blocks" is a good place to start understanding the use of the MATLAB Function block for HDL code generation.

Kategorien

Mehr zu Code Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by