As previously decribed floating point arithmetic is not associative. Which means it is very easy for floating point models not …
read moreOther articles
"Matlab: linear progressions"
"Matlab: functions inputs parsed based on outputs"
It is quite common to detect how many input arguments have been passed to a function, using
read morenargin
(N arguments …"SystemVerilog: RTL Types"
read morereg
andwire
were the original synthesisable types. Wires are constantly assigned and regs are evaluated at particular points, the …"Verilog: define if not defined"
To set a default define option while allowing it to be overridden from the command line.
read more`ifndef mode_sel `define mode_sel …
"Verilog: shm waveforms"
The best practice is to use a tcl file:
shm.tcl
read moredatabase -open waves -shm probe -create your_top_level -depth all …
"Verilog Timeformat"
Time can be displayed during simulation using
%t
.$display("%t", $realtime);
Timeformat is used to control the way (
read more%t
) this …"SystemVerilog: Constrained Random"
A minimal example of constrained random to constraining a 4 bit value to 0 to 11 when randomised.
read moremodule tb …
"Verilog: Thermometer Code"
Efficiently create a thermometer code in verilog:
read morelocalparam M = 32; function [M-1:0] therm_code; input [$clog2(M):0] val; begin …
"Verilog: Calculate primes"
"Submit to SGE as if working locally"
Setting an alias in you .tcshrc
alias qrun 'qrsh -V -noshell -cwd !*'
or bash
read morealias qrun='qrsh -V -noshell -cwd …
"Simulink: Scroll wheel erratic behaviour"
On Mac OS X matlab behaves quite oddly with the track pad zooming in and out very quickly and erratically …
read more"Matlab editor no tabs"
Matlab always use to open text files in tabs in the same editor window. When switching to 2014a documents started …
read more"Simulink: Globally set sample time"
To set each constant in a model to sample time -1:
read moreblks = find_system(dut, 'BlockType', 'Constant'); for i = 1:length …
"Simulink: list programmable block properties"
Select a block ie gain in Simulink then in Matlab type:
get(gcbh)
This shows the list of properties which …
read more"Matlab: Find all gain blocks"
find_system('BlockType', 'Gain')
This will list all gain blocks in currently loaded models. to limit to a particulat model:
read morefind_system …
"Floating Point Arithmetic is not Associative"
"Verilog: Timeout"
To wait for a maximum of
10ns
for positive edge on clk then carry on with simulation.read morefork : wait_or_timeout begin …
"Matlab Remove Elements from Array"
"Matlab: Formatting Strings"
"Matlab: Grid"
To add X and Y grids to plots :
grid on;
To add Y only grid:
read moreset(gca,'XGrid','off','YGrid …
"Matlab: Line Breaks in Strings"
Wrap strings with
sprintf
to allow the\n
to be escaped correctly.read more>> disp('hello\nworld') hello\nworld >> disp(sprintf('hello …
"Matlab: Listing field name values of a struct"
"Matlab toolboxes with absolute path setup"
When a script or function is called with
read morerun(./relative/path/script)
the working directory is changed to the./relative …
"Matlab: Array content check"
Checking if an Array contains a number:
input = [1,2,3,4]; check = 4; any(input==4)
Check if a …
read more"Matlab: Split Odd & Even Array Elements"
Using Matlab to splitting data into odd and even samples.
A for loop approach:
read moredata_odd = []; data_even = []; for i = 1:length …
"Verilog importing envvar"
Based on a Stackoverflow answer, to import environment variables into Verilog you can use:
read moreimport "DPI-C" function string getenv(input …
"Matlab: leading 0's"
For adding leading zeros to a number the following can be used for 4 decimal places with integer input:
read moredat …
"Matlab Wrapper Scripts"
To wrap a function with variable input arguments and pass them all on to the wrapped function. Based on a …
read more"Matlab sort_by"
In ruby we can perform schwartzian transforms easily with the sort_by method. This allows sorting enumerators by any property.
For …
read more"Beyond the LSB"
If we truncate a number, that is to throw away the LSBs (least significant bits) we loose resolution.
A 4 …
read more"Matlab Function Outputs"
Handling functions with extraneous leading outputs. For example:
read morefunction [a,b] = dummy_function a = 10; b = 20; endfunction [a, b] = dummy_function …
"Matlab Shuffle Array"
To shuffle a:
a(randperm(length(a)))
Example:
read morea = [10 2 5 20]; a = a(randperm(length(a))) a = 5 …
"OO Magic Bullet?"
I do not think that there are any magic bullets, best practises can minimise risk but you have to fully …
read more"$display without a line return"
In Verilog to output to stdout without a line return use
$write();
Equivalent statements :
read more$write("\n"); $display("");
"Object-Oriented Matlab"
Mathworks Article on Object-Oriented programming for Matlab.
A quick example of the syntax:
read moreclassdef sads properties Name SampleRate end properties …
"Matlab: legend colours"
When plotting several lines in Matlab, I have become aware of how hard it was to see the colours in …
read more"Matlab benchmarking"
In the following example we test the allocation speed of different types:
read moresamples_to_avg = 10000; for i=1:samples_to_avg tic; t …
"Matlab remove values from array"
"flip-flop"
A flip-flop (D-Type) is essentially 2 latches in series with the enable to one inverted. This stops the flip-flop from …
read more"Matlab repeat a matrix n times"
repmat(matrix, [repeat_y, repeat_x])
Horizontal
read morerepmat([1 2 3],[1,4]) ans = 1 2 3 1 2 3 1 2 …
"Matlab setting Simulink simulation stop time"
Running the Simulink model model.mdl from matlab for a specified time:
sim('model', stoptime)
Where stoptime is a number …
read more"Name Spacing in Matlab"
A typical work flow in Matlab involves a folder filled with scripts and functions. Over time this folder grows until …
read more"Navigate Verilog with VIM"
Using
gf
In your vimrc
read more" gf goto_file, automatically add search for these file extensions :set suffixesadd+=.v :set suffixesadd+=.sv …
"Testing Matlab Arrays for Equality."
Testing a matlab array for equality can be doen a few different was some have surprising side effects if your …
read moreTasks Using Absolute Delays
As previously mentioned SystemVerilog introduced abolute delays in the form of
read more#1s;
,#1ms
,#1us
,#1ns
. Using these as values passed …"Matlab Scripting Axes Properties"
Matlab figure properties which can be set through the properties editor can also be set by scripts. My main stumbling …
read more