Matlab 毫無疑問是最常用的 computation 及 DSP 的軟體。大概也是我從大學以來使用程度最高的 programming language. (其次是 perl,甚少用 C 或其它語言) 主要的好處 :
* Easy to use: No malloc of array; matrix and vector operation; dynamic typing
* Complete DSP functions: windowing, fft, etc.
* Very nice graphics
主要的缺陷 :
1. Cost
2. Lack of general purpose programming language capability
3. Hard to integrate with other tools (such as verilog PLI) and do batch job. Always need to open the matlab
I was looking for the right solution. Octave is almost the same as Matlab as far as my work is concerned. It only solved the cost part.
Pylab
Python is another alternative. However, I found it’s difficult to use at beginning even with NumPy, SciPy, and Matplotlib. For example, you need to do a=Vector([1, 2, 3]) instead of a=[1,2,3]. Not mentioned to install the right tools.
The key is to Pylab (similar to Matlab) combines NumPy, SciPy, Matplotlib into an integrated and consistent environment. Pylab is an interactive mode of IPython (#ipython –pylab) similar to Matlab.
The most import thing is:
from pylab import *
Based on KeirMierle’s viewpoint, Pylab still needs to resolve these API consistency and installation issues.
Three Distributions Targeting Scientific Computing
Then I found the following three distributions based on Python
1. Sage: good for linux, maybe not easy for windows (use ?? as console)
2. Pythonxy: good for windows, maybe not good for linux (use Eclipse/IPython/Spyderlib as console)
3. Enthought Python Distribution (EPD): both for linux and windows. The founder is the developer of NumPy (use IPython as console)
I found it’s very easy to use:
Cons:
1. First, the size of each distributin is huge. For example, EPD 7.0 has 250MB. Sage is similar, if not larger.
2. EPD only support the lastest built. EPD7.0 needs to use > glibc2.5. That is, RHEL 5 or above. For RHEL 4 you need to pay to get the old distribution. Similar things may happen in other distribution.
Theerefore, alternative is to build your own environment (as many people have done it before).
The most essential part is: python, numpy, scipy, matplotlib, ipython (pylab), and maybe wxpython.
Installatin Procedure
Step1: Install python 2.6.5 (Matlibplot requires python 2.4-2.7)
* Make sure installed python NOT overwrite /usr/bin/python since RHEL uses old python for lots of system scripts.
Step2: Use python2.6.5 to install easy_install for other python packages installation.
Step3: Use easy_install for NumPy
Step3b: Use easy_install for SciPy. However, it seems to require fortran; encounter problems and skip.
Step4: Use easy_install for Matplotlib
* Matplotlib requires python 2.4-2.7
* NumPy 1.1 or later
* libpng 1.1 or later –> Use: “yum install libpng-devel”
* freetype 1.4 or later
Step5: Use easy_install for ipython
Step6: Add path (../bin before /usr/bin for python)
Run “ipython –pylab” for ipython in pylab mode.
The whole thing is summarized in the following shell script.
--------------------------------------------------------------------
#! /bin/sh
builddir=$(pwd)/pythondist
mkdir -p $builddir/source
cd $builddir/source
# Step1
wget 'http://python.org/ftp/python/2.6.5/Python-2.6.5.tgz'
wget 'http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e'
tar -xvzf Python-2.6.5.tgz
# Build python
cd $builddir/source/Python-2.6.5/
# The --prefix argument is the key!
./configure --prefix=$builddir
# Be sure to speed things up with the -j option if you're
# on a multicore machine (e.g. make -j 4 build for a quadcore)
make build
make install
# Step2
# Now install setuptools
cd $builddir/source
tar -xvzf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11/
# The next key is to call this with the python you just built!
$builddir/bin/python setup.py build
$builddir/bin/python setup.py install
# Step3-5
# Now just install numpy, scipy, ipython, matplotlib, etc through easy_install
$builddir/bin/easy_install numpy
$builddir/bin/easy_install scipy
$builddir/bin/easy_install matplotlib
$builddir/bin/easy_install ipython
---------------------------------------------------------------------------------------------------
Testing Example
from pylab import *
x = linspace(0, 1000, 1024)
y = sin(x)
win = kaiser(x.size, 12)
plot(x, 20*log10(abs(fft(y*win))))
grid(1)
axis([0, 1, 0, 1])
Almost identical to matlab and very easy to use.