08-10-2011 10:50 PM
I need to generate the random sparse matrix but elements of have to be at specific place for example random numbers on diagonal other is 0.How can I store it ? And how I can get the special element of this matrix each time?
Thanks in advance !
09-20-2011 08:50 AM
08-11-2011 12:48 AM
matlab has the "eye" function, giving you amatrix filled with ones on the diagonal:
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1
now you can multiply this with a rqandom matrix of the same size using the ".*" operator for element wise multiplication
0.0648 0 0 0 0 0 0
0 0.5798 0 0 0 0 0
0 0 0.4611 0 0 0 0
0 0 0 0.8744 0 0 0
0 0 0 0 0.2140 0 0
0 0 0 0 0 0.4399 0
0 0 0 0 0 0 0.6072
So much for generating such a matrix.
But for the other questions, please be more specific.
Is this also just matlab related, or is anything with FPGAs involved?
Have a nice simulation
08-11-2011 11:36 PM
If be more specific, I need store this matrix in some element in system generator .I know two store elements which probably can be appropriate for it: ROM and single port RAM.But my problem is how to get specific element of this matrix ?For example I need only element (5,5)?And another question which appears :How can I do matrix multiplication?not just multiplication element by element?
if and then 
and size of matrix can be different.
08-12-2011 12:29 AM
ok, so you want to do matrix math inside an FPGA.
It's not impssible, but kind of inconvenient, if you are used to the high level matlab functions.
Actually you have to redesign the algorithms according to your system specifications all by yourself.
In some cases you may find predifined libraries written in some HDL, but they may not always fit to your requirements one way or the other.
So, how to proceed:
Lets just assume that you somehow managed to store some 2D Matrix into a RAM.
The RAM now holds a 1D representation of your matrix.
RAM address Matrix element
Now you need some controlling device (e.g. some FSM) that performs read operations on this ram and controlls a data path, that is able to do two multiplications and one addition (e.g.: a*e + b*g), the result then can be stored to some other ram position or forwarded to some output, depending on your requirements.
As you can see the adress for some specific element of the marix can be calculated using some simple operations:
If your matrix dimension is a 2^n value, the multiplication herein is a simple shift operation.
There are many things that can be done to optimize the performance of your design in any direction (area vs. speed), but they are very specific to your requirements.
If the size of your matrix shall be different, you need to make your controller flexible, e.g. by using loadable counters for address calculations. basically just the same as you would do in software, just that you have to care fore some more limitations because the arithmetic structure (your datapath) has to be fixed, and can not change at runtime.
Also your memory is kind of limited, if you intend to use just internal RAM ressources.
Hope you got an idea now what lies in front of you.
This is hardware design and the higher grade of freedom has to be paid with work time.
Have a nice synthesis
08-18-2011 05:53 AM - edited 08-18-2011 06:21 AM
Thanks for reply and I am trying to it.But now I faced other problem I need to find a reminder.I am tring to use Divider Generator but it gives result only after 50 time clk. But I need that it gives each time.I try to use black box but it gives me 0 output.
Simple verilog code:
module remaider(counter,matrixsize,remainder,clk); input [15:0] counter; input [15:0] matrixsize; input clk; output signed [14:10] remainder; always @ (posedge clk ) begin assign remainder = counter%matrixsize; end endmodule
I know why it gives 0 because output of model changes to [5:0] but i didn't get why??
09-12-2011 10:55 PM
sorry for answering so late, I had some weeks of vacancy.
The solution is simple, you hopefully already found it by yourself.
In your black box the HDL simulator isn't activated:
So, without a HDL simulator runnig you won't get any outputs from the black box.
You can choose between ISIM or Modelsim. In the later case you also have to add the ModelSim block to your simulink model.
Have a nice simulation
09-20-2011 08:50 AM