2018/04/12

Matlab: Basic Differentiation and Integration with the syms symbolic variable

To perform basic calculus calculations with Matlab, declare symbolic variables with syms command:

>> syms x;
>> y = 3*x^3+2*x^2-4*x+5;

Hence y = 3x3+2x2-4x+5.

For differentiation, the derivative of y is y' = diff(y):

>> y_prime = diff(y)

y_prime =

9*x^2 + 4*x - 4

Hence y' = dy/dx = 9x2+4x-4.

For integration, the integral of y is ∫ y dy = int(y):

>> y_integral = int(y)

y_integral =

(3*x^4)/4 + (2*x^3)/3 - 2*x^2 + 5*x

Consequently, ∫ y dy = (3x4)/4 + (2x3)/3 - 2x2 + 5x + c.

2018/04/10

Matlab: Simple structure with dot (.)

To create a basic form of structure in Matlab, simply use a dot (.) as below:

>> mystruct.name = "peter";
>> mystruct.age = 15;
>> mystruct.hobby = "swimming";
>> mystruct

mystruct =

  struct with fields:

     name: "peter"
      age: 15
    hobby: "swimming"




2018/03/29

Verilog Development Environment with Mac

To develop Verilog codes with a Mac, the following tools may be used:

Command line editor: Nano

Graphical UI Editor: TextWrangler (Available on App Store for Free)

Compiler: Icarus Verilog (Install with Homebrew with command: brew install icarus-verilog)

Waveform Viewer: GTKWave (Write $dumpfile command to output vcd file

References:

如何在Mac OS X上安裝Verilog環境 (Instructions to Icarus Verilog and GTKWave installation)
is there a good verilog editor for mac?

Verilog vs. VHDL (Study EECC)
Digital Logic Design - Truth Table and K-map (Study EECC)

2018/03/16

Digital Logic Design - Truth Table and K-map

To convert digital logic conditions in a truth table to a digital circuit, use the K-map.

truth table 真值表
Karnaugh map / K-map 卡諾圖
Boolean algebra / logic algebra 布林代數 / 邏輯代數

References

Karnaugh map (Wikipedia)
Truth table (Wikipedia)
Boolean algebra (Wikipedia)
HOW TO: Combinational logic: Truth Table → Karnaugh Map → Minimal Form → Gate Diagram (YouTube)

Verilog Development Environment with Mac (Study EECC)

2018/03/10

Matlab: Run Hello World files written in C/C++ with MEX command

To run C/C++ files from Matlab, use the MEX command.
Create the files in C or C++:

C (hello.c)

#include"mex.h"
#include<stdio.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
    printf("Hello, World!\n");
}


C++ (helloCPP.cpp)

#include"mex.h"
#include <iostream>

using namespace std;

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
    cout << "Hello, World!\n";

}

The mexFunction in either of the C or C++ example above is similar to the main function in pure C or C++ programs. Type your main program here such as printf in C or cout in C++.

Execute the files with the MEX command in Matlab such as below:

C
mex hello.c
hello

C++
mex helloCPP.cpp
helloCPP

Results in the Matlab command window:


References

Matlab 教材:測試 MEX-file
C language with Mac: Hello World with Mac's Terminal
C++ with Mac: Hello World with Mac's Terminal

2018/02/23

Verilog vs. VHDL

Verilog -
1984年推出、1995年成為標準IEEE 1364-1995、較廣泛使用、接近程式語言

VHDL (VHSIC Hardware Description Language) -
1983開始、1987年成為標準IEEE 1076-1995、使用較Verilog少、學習時間較Verilog長、仍有其優點

參考資料
Verilog (Wikipedia)
VHDL (Wikipedia)
SystemVerilog (Wikipedia)
Verilog HDL和VHDL的比較

Verilog Development Environment with Mac (Study EECC)