Professional Documents
Culture Documents
() 158
MATLAB
MATLAB
9 MATLAB MATLAB
MATLAB Complier m
Simulink Simulink Real-Time Workshop DSP
MATLAB
MATLAB // MATLAB
Administering Apache
Matlab/Simulink
100084
http://www.tup.tsinghua.edu.cn
7871092 1/16
21
479
2002 10 1 2002 10 1
ISBN 7-900643-63-X
00015000
34.00
: l
Library VB MATLAB
Simulink TI DSPs/Xilinx
FPGA/WindRiver VxWorks
MATLAB
MATLAB
MATLAB
MATLAB MATLAB
MATLAB MATLAB
MATLAB MATLAB MATLAB
1 MATLAB MATLAB
2 MATLAB m
C/Fortran m
3 MATLAB Compiler m
VC++ m VC++/VB MATLAB
Matlab/Simulink
II
z
8 WindRiver VxWorks
Simulink VxWorks/Tornado
9 MATLAB DSP
>>command_name/command_name(arg1,,argN) MATLAB
m >> MATLAB
z
: (
: )
: (
%MATLABROOT% MATLAB
: )
MATLAB
E-mail yongchunchen@hotmail.com MATLAB
http://www.hirain.com
MathWorks http://www.mathworks.com MATLAB
MATLAB
2002 7 30
1
1.1
1.2
1.3
1.4
1.5
MATLAB ...................................................................................1
............................................................................................... 1
MATLAB .......................................................................................... 5
MATLAB ............................................................... 28
MATLAB ....................................................................................................... 29
MATLAB ................................................................................................ 37
2 ..........................................................................................................47
2.1 ................................................................................................. 47
2.2 m ................................................................................................................ 49
2.3 m ................................................................................................................ 50
2.4 Toolboxes .................................................................................................................... 57
2.5 C/Fortran .................................................................................................... 61
2.6 ..................................................................................................... 83
2.7 ............................................................................................................. 84
3
3.1
3.2
3.3
3.4
3.5
3.6
m .............................................................................93
C/C++ compiler .................................................................................................. 94
m C/C++..................................................... 97
m C/C++........................................................... 111
VC++ m ........................................................................................... 118
VC++ MATLAB C Math Library............................................................. 122
VB MATLAB ................................................................................. 138
4 Simulink ...............................................................................143
4.1 ............................................................................................................... 143
4.2 ............................................................................................................... 144
4.3 Blocksets.................................................................................................................... 149
4.4 Simulink .................................................................................................... 150
4.5 ................................................................................................................... 152
4.6 C m .......................................................................... 158
Matlab/Simulink
IV
6
6.1
6.2
6.3
6.4
6.5
TI DSP .........................................................................193
Developers Kit for TI DSP ............................................................................. 193
................................................................................................................... 193
Developers Kit for TI DSP .......................................................................... 195
Matlab TI DSP ............................................................................................. 196
Simulink C6701 EVM ........................................... 225
VxWorks ..............................................................................258
VxWorks/Tornado ..................................................................................................... 258
Simulink VxWorks ....................................................................................... 258
Tornado (VxWorks) Real-Time Target .................................................... 260
Tornado (VxWorks) Real-Time Target ................................................ 263
DSP ..........................................................................281
9.10
9.11
9.12
9.13
9.14
9.15
9.16
9.17
9.18
9.19
9.20
9.21
9.22
9.23
9.24
............................................................................322
1
1.1
MATLAB
MATLAB MathWorks
MATLAB
MATLAB
MATLAB
z
z
z
z
z
z
z
z
z
MATLAB
MATLAB MATLAB
MATLAB
MATLAB http://www.mathworks.com/partners
MATLAB
MATLAB
Matlab/Simulink
2
MATLAB Toolbox
Simulink
Stateflow
Stateflow Coder
Real-Time Workshop
Communications Blockset
Communications Toolbox
DSP Blockset
Database Toolbox
Datafeed Toolbox
Financial Toolbox
Fixed-Point Blockset
GARCH Toolbox
MATLAB Compiler
Mapping Toolbox
Optimization Toolbox
1 MATLAB
Robust Control Toolbox
Spline Toolbox
Statistics Toolbox
Wavelet Toolbox
xPC Target
ver
>> which ver
D:\MATLAB6p1\toolbox\matlab\general\ver.m
ver
>> edit ver
Matlab/Simulink
4
For example,
ver control
1.2
1.1 ver
1.2
helpwin ver
: (
)
1 MATLAB
1.3
MATLAB
1.2
MATLAB
MATLAB 1.4
1.4 MATLAB
Matlab/Simulink
MATLAB Toolbox
1.4 MATLAB MATLAB MATLAB ToolboxMATLAB
Toolbox m MATLAB MATLAB
MATLAB Toolbox MATLAB
1.5 MATLAB
1.5 MATLAB
Toolboxes
Toolboxes ver MATLAB
Communications Toolbox
Database Toolbox
Datafeed Toolbox
Financial Toolbox
GARCH Toolbox
1 MATLAB
LMI Control Toolbox
Mapping Toolbox
02-Feb-2001(nnet)
Optimization Toolbox
18-May-2001(opt)
:
:
: Toolbox
18-May-2001(robust)
Spline Toolbox
13-Mar-2000(splines)
Statistics Toolbox
01-Sep-2000(stats)
18-May-2001(ident)
Wavelet Toolbox
06-Apr-2001(wavelet)
:
:
: (
:
: )
Filter analysis.
abs
- Magnitude.
angle
- Phase angle.
filternorm
freqs
freqspace
freqz
freqzplot
fvtool
grpdelay
- Group delay.
impz
unwrap
- Unwrap phase.
zplane
Filter implementation.
conv
- Convolution.
conv2
- 2-D convolution.
: angle
Matlab/Simulink
8
deconv
- Deconvolution.
fftfilt
filter
- Filter implementation.
filter2
filtfilt
filtic
latcfilt
medfilt1
sgolayfilt
sosfilt
upfirdn
- Convolution matrix.
cremez
fir1
- Window based FIR filter design - low, high, band, stop, multi.
fir2
- FIR arbitrary shape filter design using the frequency sampling method.
fircls
fircls1
firls
firrcos
intfilt
kaiserord
remez
remezord
sgolay
cheby1
cheby2
ellip
maxflat
yulewalk
cheb1ord
cheb2ord
ellipord
1 MATLAB
besselap
buttap
cheb1ap
cheb2ap
ellipap
butter
cheby1
cheby2
ellip
lp2bs
lp2hp
lp2lp
Filter discretization.
bilinear
impinvar
polystab
- Polynomial stabilization.
polyscale
residuez
sos2ss
sos2tf
sos2zp
ss2sos
ss2tf
ss2zp
tf2latc
tf2sos
tf2ss
tf2zp
zp2sos
zp2ss
zp2tf
Matlab/Simulink
10
Windows.
bartlett
- Bartlett window.
barthannwin
blackman
- Blackman window.
blackmanharris
bohmanwin
- Bohman window.
chebwin
- Chebyshev window.
gausswin
- Gaussian window.
hamming
- Hamming window.
hann
- Hann window.
kaiser
- Kaiser window.
nuttallwin
rectwin
- Rectangular window.
triang
- Triangular window.
tukeywin
- Tukey window.
window
Transforms.
bitrevorder
czt
- Chirp-z transform.
dct
dftmtx
fft
fft2
fftshift
goertzel
hilbert
idct
ifft
ifft2
Cepstral analysis.
cceps
- Complex cepstrum.
icceps
rceps
corrcoef
- Correlation coefficients.
corrmtx
- Autocorrelation matrix.
cov
- Covariance matrix.
csd
1 MATLAB
pburg
pcov
peig
periodogram
pmcov
pmtm
pmusic
psdplot
pwelch
pyulear
rooteig
rootmusic
tfe
xcorr
- Cross-correlation function.
xcorr2
- 2-D cross-correlation.
xcov
- Covariance function.
Parametric modeling.
arburg
arcov
armcov
aryule
ident
invfreqs
invfreqz
prony
stmcb
Linear Prediction.
ac2rc
ac2poly
is2rc
lar2rc
levinson
- Levinson-Durbin recursion.
lpc
lsf2poly
poly2ac
poly2lsf
poly2rc
rc2ac
rc2is
rc2lar
11
Matlab/Simulink
12
rc2poly
rlevinson
schurrc
- Schur algorithm.
downsample
interp
interp1
resample
spline
upfirdn
upsample
Waveform generation.
chirp
diric
gauspuls
gmonopuls
pulstran
rectpuls
sawtooth
- Sawtooth function.
sinc
square
tripuls
vco
Specialized operations.
buffer
cell2sos
cplxpair
demod
dpss
dpssclear
dpssdir
dpssload
dpsssave
eqtflength
modulate
seqperiod
sos2cell
specgram
1 MATLAB
stem
strips
- Strip plot.
udecode
uencode
sptool
See also SIGDEMOS, AUDIO, and, in the Filter Design Toolbox, FILTERDESIGN.
>> help images
Image Processing Toolbox.
Version 3.1 (R12.1) 18-May-2001
Release information.
images/Readme - Display information about current and previous versions.
Image display.
colorbar
getimage
image
imagesc
immovie
imshow
- Display image.
montage
movie
subimage
truesize
warp
dicomread
dicom-dict.txt
imfinfo
imread
imwrite
Image arithmetic.
imabsdiff
13
Matlab/Simulink
14
imadd
imcomplement
- Complement image.
imdivide
imlincomb
immultiply
imsubtract
Geometric transformations.
checkerboard
findbounds
fliptform
imcrop
- Crop image.
imresize
- Resize image.
imrotate
- Rotate image.
imtransform
makeresampler
maketform
tformarray
tformfwd
tforminv
Image registration.
cpstruct2pairs
cp2tform
cpcorr
cpselect
normxcorr2
imcontour
imhist
impixel
improfile
mean2
pixval
regionprops
std2
Image analysis.
edge
qtdecomp
1 MATLAB
qtgetblk
qtsetblk
15
Image enhancement.
histeq
imadjust
imnoise
medfilt2
ordfilt2
stretchlim
wiener2
Linear filtering.
convmtx2
fspecial
imfilter
freqz2
fsamp2
ftrans2
fwind1
fwind2
Image deblurring.
deconvblind
deconvlucy
deconvreg
deconvwnr
edgetaper
otf2psf
psf2otf
Image transforms.
dct2
dctmtx
fft2
fftn
fftshift
idct2
ifft2
: -
Matlab/Simulink
16
ifftn
iradon
phantom
radon
: -
blkproc
col2im
colfilt
im2col
nlfilter
- Default connectivity.
imbothat
imclearborder
imclose
- Close image.
imdilate
- Dilate image.
imerode
- Erode image.
imextendedmax
- Extended-maxima transform.
imextendedmin
- Extended-minima transform.
imfill
imhmax
- H-maxima transform.
imhmin
- H-minima transform.
imimposemin
- Impose minima.
imopen
- Open image.
imreconstruct
- Morphological reconstruction.
imregionalmax
- Regional maxima.
imregionalmin
- Regional minima.
imtophat
watershed
- Watershed transform.
bwarea
bwareaopen
bwdist
bweuler
bwhitmiss
bwlabel
bwlabeln
1 MATLAB
bwmorph
bwpack
bwperim
bwselect
bwulterode
- Ultimate erosion.
bwunpack
makelut
getneighbors
getnhood
getsequence
isflat
reflect
strel
translate
- Translate strel.
Region-based processing.
roicolor
roifill
roifilt2
roipoly
Colormap manipulation.
brighten
cmpermute
cmunique
colormap
imapprox
rgbplot
ntsc2rgb
rgb2hsv
rgb2ntsc
rgb2ycbcr
ycbcr2rgb
Array operations.
circshift
17
Matlab/Simulink
18
padarray
- Pad array.
gray2ind
grayslice
graythresh
im2bw
im2double
im2uint8
im2uint16
ind2gray
im2mis
ind2rgb
isbw
isgray
isind
isrgb
label2rgb
mat2gray
rgb2gray
rgb2ind
Toolbox preferences.
iptgetpref
iptsetpref
Demos.
dctdemo
edgedemo
firdemo
imadjdemo
landsatdemo
nrfiltdemo
qtdemo
roidemo
Slide shows.
ipss001
ipss002
- Feature-based logic.
ipss003
: -
1 MATLAB
19
Extended-examples.
ipexindex
ipexsegmicro
ipexsegcell
ipexsegwatershed
- Watershed segmentation.
ipexgranulometry
- Granulometry of stars.
ipexdeconvwnr
- Wiener deblurring.
ipexdeconvreg
- Regularized deblurring.
ipexdeconvlucy
- Lucy-Richardson deblurring.
: aboutsignaltbx
ipexdeconvblind
- Blind deblurring.
: fircls
ipextform
: ac2poly
ipexshear
: fircls1
ipexmri
: ac2rc
ipexconformal
- Conformal mapping.
ipexnormxcorr2
- Normalized cross-correlation.
: firls
ipexrotate
ipexregaerial
: Contents
: fir2
: arburg
: firrcos
: arcov
: freqs
: armcov
M-files in directory D:\MATLAB6p1\toolbox\signal\signal
: freqz
: aryule
Contents
fir2
psdplot
aboutsignaltbx
fircls
pulstran
ac2poly
fircls1
pwelch
ac2rc
firls
pyulear
: gauspuls
arburg
firrcos
rc2ac
: bartlett
arcov
freqs
rc2is
: gausswin
armcov
freqz
rc2lar
: besselap
aryule
freqzplot
rc2poly
: gmonopuls
barthannwin
gauspuls
rceps
: besself
bartlett
gausswin
rectpuls
besselap
gmonopuls
rectwin
besself
goertzel
remez
bilinear
grpdelay
remezord
: grpdelay
bitrevorder
hamming
resample
: bitrevorder
blackman
hann
residuez
: hamming
blackmanharris
hanning
rlevinson
bohmanwin
hilbert
rooteig
: hann
boxcar
icceps
rootmusic
bscost
idct
sawtooth
buffer
impinvar
schurrc
: freqzplot
: barthannwin
: goertzel
: bilinear
: blackmanharris
: hanning
: bohmanwin
Matlab/Simulink
20
buttap
impz
seqperiod
butter
impzlength
sgolay
buttord
interp
sgolayfilt
cceps
intfilt
signalpolyutils
cell2sos
invfreqs
sigprivate
cheb1ap
invfreqz
sinc
cheb1ord
is2rc
sos2cell
cheb2ap
kaiser
sos2ss
cheb2ord
kaiserord
sos2tf
chebwin
kratio
sos2zp
cheby1
lar2rc
sosfilt
cheby2
latc2tf
specgram
chirp
latcfilt
specplot
cohere
levinson
spectrum
convmtx
lp2bp
square
corrmtx
lp2bs
ss2sos
cremez
lp2hp
stmcb
csd
lp2lp
strips
czt
lpc
tf2latc
datawrap
lsf2poly
tf2sos
dct
maxflat
tfe
decimate
medfilt1
triang
demod
modulate
tripuls
dftmtx
nuttallwin
tukeywin
diric
pburg
udecode
downsample
pcov
uencode
dpss
peig
upfirdn
dpssclear
periodogram
upsample
dpssdir
pmcov
vco
dpssload
pmem
vratio
dpsssave
pmtm
window
ellip
pmusic
xcorr
ellipap
poly2ac
xcorr2
ellipord
poly2lsf
xcov
eqtflength
poly2rc
yulewalk
fftfilt
polyscale
zp2sos
filternorm
polystab
zplane
filtfilt
prony
filtic
psd
fir1
psdoptions
1 MATLAB
mtlb
21
vcosig
levinson
latcfilt
seqperiod
upfirdn
imdilate
: Contents
Readme
imdivide
applylut
imerode
bestblk
imextendedmax
blkproc
imextendedmin
bmpread
imfeature
bmpwrite
imfill
bwarea
imfilter
bwareaopen
imhist
bwdist
imhmax
bweuler
imhmin
bwfill
imimposemin
bwhitmiss
imlincomb
bwlabel
immovie
bwlabeln
immultiply
bwmorph
imnoise
bwpack
imopen
bwperim
impixel
bwselect
improfile
bwulterode
imreconstruct
bwunpack
imregionalmax
checkerboard
imregionalmin
circshift
imresize
cmgamdef
imrotate
cmgamma
imshow
cmpermute
imslice
cmunique
imsubtract
col2im
imtophat
colfilt
imtransform
conndef
imzoom
Matlab/Simulink
22
convmtx2
ind2gray
corr2
iptgetpref
cp2tform
iptsetpref
cpcorr
iradon
cpselect
isbw
cpselectswitchyard
isgray
cpstruct2pairs
isind
dct2
isrgb
dctmtx
label2rgb
dctmtx2
makelut
deconvblind
makeresampler
deconvlucy
maketform
deconvreg
mat2gray
deconvwnr
mean2
dicominfo
medfilt2
dicomread
mfilter2
dilate
montage
dither
nlfilter
edge
normxcorr2
edgetaper
ntsc2rgb
erode
ordfilt2
findbounds
otf2psf
fliptform
padarray
freqz2
pcxread
fsamp2
pcxwrite
fspecial
phantom
ftrans2
pixval
fwind1
psf2otf
fwind2
qtdecomp
getimage
qtgetblk
getline
qtsetblk
getpts
radon
getrect
regionprops
gifread
rgb2gray
gifwrite
rgb2ind
gray2ind
rgb2ntsc
grayslice
rgb2ycbcr
graythresh
roicolor
hdfpeek
roifill
hdfwrite
roifilt2
histeq
roipoly
idct2
std2
: convmtx2
: fliptform
1 MATLAB
im2bw
stretchlim
im2col
subimage
im2double
tformarray
im2mis
tformfwd
im2uint16
tforminv
im2uint8
tiffread
imabsdiff
tiffwrite
imadd
truesize
imadjust
warp
imapprox
watershed
imbothat
wiener2
imclearborder
xwdread
imclose
xwdwrite
imcomplement
ycbcr2rgb
23
imcontour
imcrop
MAT-files in directory D:\MATLAB6p1\toolbox\images\images
dicom-dict
MEX-files in directory D:\MATLAB6p1\toolbox\images\images
applylut
imabsdiff
bwpack
imlincomb
bwunpack
imreconstruct
imregionalmax
Compiler
MATLAB Compiler MATLAB m C/C++
Borland C/C++VC++ MathWorks
C/C++ MathWorks C/C++
Matlab m
C/C++ MATCOM
Matlab/Simulink
24
http://www.google.com MATCOM
Simulink
1.4 Simulink Matlab
1.6 Simulink
1.6 Simulink
Simulink
Simulink m C
Simulink Matlab
Simulink Matlab Matlab
Blocksets
Blocksets Simulink
MathWorks
DSP Blockset
FFT/FCT 1.7 1.8
1.9 MathWorks Power System Blockset Communications
1 MATLAB
25
1.7 DSP
1.8
1.9
26
Matlab/Simulink
1.10
Simulink
Real-Time WorkshopRTW
Real-Time WorkshopRTW Simulink RTW
Simulink RTW 1.11
: .
: (
: )
: (
: )
1 MATLAB
27
Real-Time Workshop
Stateflow
Stateflow Simulink
1.12
1.12
Locked Unlocked
1.12
Locked
Unlocked
Unlocked
Locked 1.12 Locked
Stateflow Simulink
Simulink
Stateflow Coder
Stateflow Coder Stateflow C
C
MATLAB Toolbox Simulink
: (
: )
: (
: )
Matlab/Simulink
28
1.3
MATLAB
MATLAB 1.13
1.13
MATLAB
Matlab C
Matlab
Simulink
/DSP
Simulink
:
:
1 MATLAB
29
1.4
MATLAB
:
: (
: )
: (
: )
:
:
:
:
:
: (
: )
:
:
:
30
Matlab/Simulink
1.14
1.15 MATLAB
1.16
1 MATLAB
31
1.18
License Agreement
:
: 8
: 19
:
Matlab/Simulink
32
7. 1.21
MATLAB
Windows Program Files
z
z
z
1 MATLAB
33
MATLAB /
PLP MATLAB
MATLAB MATLAB
MATLAB MATLAB
MATLAB
1.21
MATLAB MATLAB
1.22
Installation Status
: 22
:
: (
: )
: (
: )
34
Matlab/Simulink
8. 1.23 MATLAB
MATLAB 1.24
1.21 Real-Time Windows Target 1.25
Real-Time Windows Target Next 1.25
: (
: )
:
1.23
1 MATLAB
35
9. 1.25 MATLAB
Internet MATLAB
1.25
Installation Complete
MATLAB
license.txt MATLAB
z MATLAB
z
\BIN\WIN32 MATLAB
LICENSE.DAT
License
MATLAB.EXE
MATLAB
*.DLL*.EXE*.BAT
\DEMOS MATLAB
\EXTERN MATLAB
\EXAMPLES MATLAB CFortran
\INCLUDE MATLAB
\LIB
\SRC
MEX C
\FLEXLM FLEXlm
\HELP MATLAB HTML PDF
\JA MATLAB
\JAVA MATLAB Java
\NOTEBOOK MATLAB Notebook
z
Matlab/Simulink
36
\SYS MATLAB
\GHOSTSCRIPT\BIN
GhostScript
PostScript GhostScript
\GHOSTSCRIPT\FONTS
\GHOSTSCRIPT\PS_FILES
PostScript
\PERL\WIN32 ActiveState Perl
\RTW Real-Time Workshop
\Simulink Simulink S-
\STATEFLOW Stateflow
\TOOLBOX MATLAB
\LOCAL Matlab
: Matalb
\MATLAB
\AUDIO
I/O
\DATAFUN
Fourier
\DATATYPES
\DEMOS
\ELFUN
\ELMAT
\FUNFUN
\GENERAL
\GRAPH2D
\GRAPH3D
\GRAPHICS
\IOFUN
I/O
\LANG
m
\MATFUN
\OPS
\POLYFUN
\SPARFUN
\SPECFUN
\SPECGRAPH
\STRFUN
\TIMEFUN
\UITOOLS
\VERCTRL
\WINFUN
Window
\UNINSTALL MATLAB Uninstaller
\WORK
:
:
:
:
1 MATLAB
37
1.5
MATLAB
1.26 MATLAB
: (
: )
Matlab/Simulink
38
MATLAB
z Command Window MATLAB
MATLAB MATLAB m
m
Launch Pad
Launch Pad MATLAB
z Workspace MATLAB
MATLAB MATLAB
1.27 MATLAB
1 MATLAB
39
1.28 MATLAB
1.29
MATLAB 5.3
MATLAB %MATLABROOT%\toolbox\local\
matlabrc.m MATLAB
matlabrc.m
%MATLABROOT%\toolbox\local startup.m matlabrc
startup.m 1.30 1.31
matlabrc.m MATLAB 1.32
Matlab/Simulink
40
1.30 %MATLABROOT%\toolbox\local\matlabrc.m
1.31
%MATLABROOT%\toolbox\local\matlabrc.m
: (
: )
1 MATLAB
1.32
41
MATLAB
%MATLABROOT%\toolbox\local matlabrc.m
startup.m finish.m MATLAB 1.33
1.33
%MATLABROOT%\toolbox\local
PIII600+Windows 2000+1024X768
+32 matlabrc.m
MATLAB
%MATLABRC Master startup M-file.
% MATLABRC is automatically executed by MATLAB during startup.
% It establishes the MATLAB path, sets the default figure size,
% and sets a few uicontrol defaults.
Matlab/Simulink
42
%
%
%
% MATLABRC also invokes a STARTUP command if the file 'startup.m'
% exists on the MATLAB path.
% Copyright 1984-2000 The MathWorks, Inc.
% $Revision: 1.142 $ $Date: 2001/04/27 17:29:20 $
% Set up path.
if exist('pathdef','file')
ptime0 = [];
if exist([matlabroot '/toolbox/local/toolbox_cache.mat'], 'file') &...
strcmpi(system_dependent('getpref','GeneralUseToolboxCache'),...
'BTrue')
disp(' MATLAB Toolbox Path being initialized using Toolbox Path Cache.')
if strcmpi(system_dependent('getpref','GeneralUseToolboxCacheDiag'),...
'BTrue')
ptime0 = clock;
end
end
matlabpath(pathdef);
if ~isempty(ptime0)
disp(sprintf(' MATLAB Path initialized in %.2f seconds.', etime(clock, ptime0)));
end
end
% Display helpful hints.
% If the MATLAB Desktop is not running, then use the old message, since
% the Help menu will be unavailable.
if usejava('Desktop')
disp(' ')
disp(' To get started, select "MATLAB Help" from the Help menu.')
disp(' ')
else
disp(' ')
disp(' To get started, type one of these: helpwin, helpdesk, or demo.')
disp(' For product information, visit www.mathworks.com.')
disp(' ')
end
1 MATLAB
% Set default warning level to WARNING BACKTRACE. See help warning.
warning backtrace
% Enable MEX-file backwards compatibility mode
feature('MEXFileCompat',1);
% The RecursionLimit forces MATLAB to throw an error when the specified
% function call depth is hit. This protects you from blowing your stack
% frame (which can cause MATLAB and/or your computer to crash). Set the
% value to inf if you don't want this protection.
cname = computer;
if strncmp(cname,'GLNX',4)
set(0,'RecursionLimit',100)
elseif strncmp(cname,'ALPHA',5)
set(0,'RecursionLimit',200)
else
set(0,'RecursionLimit',500)
end
% Set the default figure position, in pixels.
% On small screens, make figure smaller, with same aspect ratio.
screen = get(0, 'ScreenSize');
width = screen(3);
height = screen(4);
if screen(3:4) ~= [1 1] % don't change default if screensize == [1 1]
if all(cname(1:2) == 'PC')
if height >= 500
mwwidth = 560; mwheight = 420;
if(get(0,'screenpixelsperinch') == 116) % large fonts
mwwidth = mwwidth * 1.2;
mwheight = mwheight * 1.2;
end
else
mwwidth = 560; mwheight = 375;
end
left = (width - mwwidth)/2;
bottom = height - mwheight -90;
else
if height > 768
mwwidth = 560; mwheight = 420;
left = (width-mwwidth)/2;
bottom = height-mwheight-90;
43
Matlab/Simulink
44
end
:
colordef(0,'white') % Set up for white defaults
% Make uicontrols, uimenus and lines look better on monochrome displays.
if get(0,'ScreenDepth')==1,
set(0,'DefaultUIControlBackgroundColor','white');
set(0,'DefaultAxesLineStyleOrder','-|--|:|-.');
set(0,'DefaultAxesColorOrder',[0 0 0]);
set(0,'DefaultFigureColor',[1 1 1]);
end
%% Uncomment the next line to use Letter paper and inches
%defaultpaper = 'usletter'; defaultunits = 'inches';
%% Uncomment the next line to use A4 paper and centimeters
%defaultpaper = 'A4'; defaultunits = 'centimeters';
%% If neither of the above lines are uncommented then guess
%% which papertype and paperunits to use based on ISO 3166 country code.
if usejava('jvm') & ~exist('defaultpaper','var')
if any(strncmpi(char(java.util.Locale.getDefault.getCountry), ...
{'gb','uk','fr','de','es','ch','nl','it','ru',...
'jp','kr','tw','cn'},2))
defaultpaper = 'A4';
defaultunits = 'centimeters';
end
end
%% Set the default if requested
if exist('defaultpaper','var') & exist('defaultunits','var')
% Handle Graphics defaults
set(0,'DefaultFigurePaperType',defaultpaper);
set(0,'DefaultFigurePaperUnits',defaultunits);
% Simulink defaults
1 MATLAB
set_param(0,'PaperType',defaultpaper);
set_param(0,'PaperUnits',defaultunits);
end
%% For Japan, set default fonts
lang = lower(get(0,'language'));
if strncmp(lang, 'ja', 2)
if strncmp(cname,'PC',2)
set(0,'defaultuicontrolfontname',get(0,'factoryuicontrolfontname'));
set(0,'defaultuicontrolfontsize',get(0,'factoryuicontrolfontsize'));
set(0,'defaultaxesfontname',get(0,'factoryuicontrolfontname'));
set(0,'defaultaxesfontsize',get(0,'factoryuicontrolfontsize'));
set(0,'defaulttextfontname',get(0,'factoryuicontrolfontname'));
set(0,'defaulttextfontsize',get(0,'factoryuicontrolfontsize'));
%% You can control the fixed-width font
%% with the following command
% set(0,'fixedwidthfontname','MS Gothic');
end
end
%% For the 'edit' command, to use an editor defined in the $EDITOR
%% environment variable, the following line should be uncommented
%% (UNIX only)
%system_dependent('builtinEditor','off')
%% CONTROL OVER FIGURE TOOLBARS:
%% The new figure toolbars are visible when appropriate,
%% by default, but that behavior is controllable
%% by users. By default, they're visible in figures
%% whose MenuBar property is 'figure', when there are
%% no uicontrols present in the figure. This behavior
%% is selected by the figure ToolBar property being
%% set to its default value of 'auto'.
%% to have toolbars always on, uncomment this:
%set(0,'defaultfiguretoolbar','figure')
%% to have toolbars always off, uncomment this:
%set(0,'defaultfiguretoolbar','none')
%% init java prefs system if java is present
45
Matlab/Simulink
46
if usejava('mwt')
initprefs
end
%% Text-based preferences
NumericFormat = system_dependent('getpref','GeneralNumFormat');
if ~isempty(NumericFormat)
eval(['format ' NumericFormat(2:end)]);
end
NumericDisplay = system_dependent('getpref','GeneralNumDisplay');
if ~isempty(NumericDisplay)
format(NumericDisplay(2:end));
end
MaxTab = system_dependent('getpref','CommandWindowMaxCompletions');
if ~isempty(MaxTab) & MaxTab(1) == 'I'
EnableTab = system_dependent('getpref','CommandWindowTabCompletion');
TabSetting = strcmpi(EnableTab,'BTrue') * str2num(MaxTab(2:end));
system_dependent('TabCompletion', TabSetting);
end
if (strcmpi(system_dependent('getpref','GeneralEightyColumns'),'BTrue'))
feature('EightyColumns',1);
end
% Clean up workspace.
clear
% Execute startup M-file, if it exists.
if (exist('startup','file') == 2)
startup
end
% Defer echo until startup is complete
if strcmpi(system_dependent('getpref','GeneralEchoOn'),'BTrue')
echo on
end
: %MATLABRC
Master startup M-file.
% MATLABRC is
automatically executed by
MATLAB during startup.
% It establishes the
MATLAB path, sets the
default figure size,
% and sets a few uicontrol
defaults.
%
% On multi-user or
networked systems, the system
manager can put
% any messages, definitions,
etc. that apply to all users here.
%
% MATLABRC also invokes
a STARTUP command if the
file 'startup.m'
% exists on the MATLAB
path.
% Copyright 1984-2000 The
MathWorks, Inc.
% $Revision: 1.142 $ $Date:
2001/04/27 17:29:20 $
% Set up path.
if exist('pathdef','file')
ptime0 = [];
if exist([matlabroot
'/toolbox/local/toolbox_cache.
mat'], 'file') &...
strcmpi(system_dependent('get
pref','GeneralUseToolboxCach
e'),...
'BTrue')
disp(' MATLAB Toolbox
Path being initialized using
Toolbox Path
Cache.')
if
strcmpi(system_dependent('get
pref','GeneralUseToolboxCach
eDiag'),...
'BTrue')
ptime0 = clock;
end
end
matlabpath(pathdef);
if ~isempty(ptime0)
disp(sprintf(' MATLAB
Path initialized in %.2f
seconds.',
etime(clock, ptime0)));... [1]
46:
[1]
fcr
%
% MATLABRC also invokes a STARTUP command if the file 'startup.m'
% exists on the MATLAB path.
% Copyright 1984-2000 The MathWorks, Inc.
% $Revision: 1.142 $ $Date: 2001/04/27 17:29:20 $
% Set up path.
if exist('pathdef','file')
ptime0 = [];
if exist([matlabroot '/toolbox/local/toolbox_cache.mat'], 'file') &...
strcmpi(system_dependent('getpref','GeneralUseToolboxCache'),...
'BTrue')
disp(' MATLAB Toolbox Path being initialized using Toolbox Path
Cache.')
if strcmpi(system_dependent('getpref','GeneralUseToolboxCacheDiag'),...
'BTrue')
ptime0 = clock;
end
end
matlabpath(pathdef);
if ~isempty(ptime0)
disp(sprintf(' MATLAB Path initialized in %.2f seconds.',
etime(clock, ptime0)));
end
end
% Display helpful hints.
% If the MATLAB Desktop is not running, then use the old message, since
% the Help menu will be unavailable.
if usejava('Desktop')
disp(' ')
disp(' To get started, select "MATLAB Help" from the Help menu.')
disp(' ')
else
disp(' ')
disp(' To get started, type one of these: helpwin, helpdesk, or
demo.')
disp(' For product information, visit www.mathworks.com.')
disp(' ')
end
2002-9-16 17:38:00
set(0,'defaulttextfontsize',get(0,'factoryuicontrolfontsize'));
%% You can control the fixed-width font
%% with the following command
% set(0,'fixedwidthfontname','MS Gothic');
end
end
%% For the 'edit' command, to use an editor defined in the $EDITOR
%% environment variable, the following line should be uncommented
%% (UNIX only)
%system_dependent('builtinEditor','off')
%% CONTROL OVER FIGURE TOOLBARS:
%% The new figure toolbars are visible when appropriate,
%% by default, but that behavior is controllable
%% by users. By default, they're visible in figures
%% whose MenuBar property is 'figure', when there are
%% no uicontrols present in the figure. This behavior
%% is selected by the figure ToolBar property being
%% set to its default value of 'auto'.
%% to have toolbars always on, uncomment this:
%set(0,'defaultfiguretoolbar','figure')
%% to have toolbars always off, uncomment this:
%set(0,'defaultfiguretoolbar','none')
%% init java prefs system if java is present
if usejava('mwt')
initprefs
end
%% Text-based preferences
NumericFormat = system_dependent('getpref','GeneralNumFormat');
if ~isempty(NumericFormat)
eval(['format ' NumericFormat(2:end)]);
end
NumericDisplay = system_dependent('getpref','GeneralNumDisplay');
if ~isempty(NumericDisplay)
format(NumericDisplay(2:end));
end
MaxTab = system_dependent('getpref','CommandWindowMaxCompletions');
if ~isempty(MaxTab) & MaxTab(1) == 'I'
EnableTab = system_dependent('getpref','CommandWindowTabCompletion');
TabSetting = strcmpi(EnableTab,'BTrue') * str2num(MaxTab(2:end));
system_dependent('TabCompletion', TabSetting);
end
if (strcmpi(system_dependent('getpref','GeneralEightyColumns'),'BTrue'))
feature('EightyColumns',1);
end
% Clean up workspace.
clear
% Execute startup M-file, if it exists.
if (exist('startup','file') == 2)
startup
end
% Defer echo until startup is complete
if strcmpi(system_dependent('getpref','GeneralEchoOn'),'BTrue')
echo on
end
MathWorks
MathWorks MATLAB
z Matlab
z Simulink
Matlab 4 Simulink
2.1
Matlab MATLAB
MATLAB Compiler
MATLAB C/C++ Math Library MATCOM
Matlab CC++
MATLAB
MATLAB m
Matlab
C
1
1.5 x1 + x 2 + 2 x3 = 2.5
3x1 x 2 + x3 = 5
x1 + 3x 2 + 5 x3 = 8
Matlab MATLAB :
>> A=[-1.5 1 2;3 -1 1;-1 3 5];
>> b=[2.5;5;8];
>> x=A\b
x=
:
:
M atlab/Sim ulink
0.7500
-0.6250
2.1250
: (
: )
:
//solver.c
//used to solve A*X=b,
//where A=[-1.5 1 2;3 -1 1;-1 3 5], b=[2.5;5;8].
#include "stdio.h"
void main()
{
double A[3][3]={{-1.5,1,2},{3,-1,1},{-1,3,5}};
double b[3]={2.5,5,8};
double invA[3][3],X[3];
int i;
// the determinant of A
double deltaA=A[0][0]*A[1][1]*A[2][2]+A[1][0]*A[2][1]*A[0][2]+
A[2][0]*A[1][2]*A[0][1]-(A[0][2]*A[1][1]*A[2][0]+
A[0][0]*A[2][1]*A[1][2]+A[0][1]*A[1][0]*A[2][2]);
//the inversion of A
invA[0][0]=1/deltaA*(A[1][1]*A[2][2]-A[1][2]*A[2][1]);
invA[1][0]=-1/deltaA*(A[1][0]*A[2][2]-A[1][2]*A[2][0]);
invA[2][0]=1/deltaA*(A[1][0]*A[2][1]-A[1][1]*A[2][0]);
invA[0][1]=-1/deltaA*(A[0][1]*A[2][2]-A[2][1]*A[0][2]);
invA[1][1]=1/deltaA*(A[0][0]*A[2][2]-A[2][0]*A[0][2]);
invA[2][1]=-1/deltaA*(A[0][0]*A[2][1]-A[0][1]*A[2][0]);
invA[0][2]=1/deltaA*(A[0][1]*A[1][2]-A[0][2]*A[1][1]);
invA[1][2]=-1/deltaA*(A[0][0]*A[1][2]-A[0][2]*A[1][0]);
invA[2][2]=1/deltaA*(A[0][0]*A[1][1]-A[0][1]*A[1][0]);
printf("The solution X is\n");
for(i=0;i<3;i++)
{
X[i]=invA[i][0]*b[0]+invA[i][1]*b[1]+invA[i][2]*b[2];
printf("%f\n",X[i]);
}
49
Matlab C Matlab
A mn b mp X
n p C
m m m
m
2.2
m m MATLAB
m MATLAB 1 m
%solver.m
%used to solve A*X=b
%where A=[-1.5 1 2;3 -1 1;-1 3 5], b=[2.5;5;8].
A=[-1.5 1 2;3 -1 1;-1 3 5];
b=[2.5;5;8];
X=A\b
% m m solver.m
MATLAB solver
>> solver
X=
0.7500
-0.6250
2.1250
m MATLAB solver
MATLAB whos MATLAB
Ab X
>> whos
:
:
:
Matlab/Simulink
50
Name
Size
Bytes Class
33
72 double array
31
24 double array
31
24 double array
2.3
2.1 MATLAB
:
:
51
m
m MATLAB
m
31
31
m
m m
: (
: )
:
[] m m
help helpwin
m m
2.1 m
help helpwin
>> help mymean
MYMEAN Average or mean value.
For vectors, MYMEAN(X) is the mean value.
For matrices, MYMEAN(X) is a row vector
containing the mean value of each column.
>> helpwin mymean
2.2
mymean.m 2.3 help helpwin
: []
Matlab/Simulink
52
2.4
:
:
:
: mymean.m
2.3
help helpwin
2.3
2.4
:
:
53
: >> help mymean
H1 help line
H1 help line lookfor
Lookfor H1 help line
>> lookfor 'average or mean'
m
m 2.5
2.4 mymean.m
helpwin mymean
: ,
2.5
2 m 2.6 m
z varargin
z nargin length(varargin
z {}
2.6 x,y
z 1 N
:
:
:
: )
: (
: )
:
: (
: )
Matlab/Simulink
54
function myvarin(p1,p2,,pN,varargin)
z
z
2~4
6~11 1 1
13~17 x y
:
:
:
:
2.6 m
z
z
z
19~20 x 0 y 0
22
23
2.7
>> myvarin([0 1],[2 3],[3 10],[-1 -16])
2.8
>> myvarin([0 1])
Usage:myvarin([x1,y1],[x2,y2],...,[xN,yN]),where N>=2
Input more than one points,Please!
>> myvarin
Usage:myvarin([x1,y1],[x2,y2],...,[xN,yN]),where N>=2
Input more than one points,Please!
:
:
:
55
:
:
:
:
:
: >> myvarin([0
1],[2 3],[3 10],[-1 -16])
2.8
:
:
:
:
3 m 2.9
z varargout
z nargout length(varargout
z {}
Matlab/Simulink
56
2.9 x,y
z 1 N
function [p1,p2,,pN,varargout]=myvarout
z
z
2~4
6~11 0 0
: (
: )
: (
: )
:
:
2.9 m
z
13~17 [0 9]x,y
>> p1=myvarout
p1 =
6
p2 =
9
:
:
:
: (
: )
57
:
p3 =
4
>> myvarout
Usage:[p1,p2,...pN]=myvarout,where N>=1
Input output points more than zero,Please!
2.4
Toolboxes
MATLAB Toolboxes
MATLAB
MATLAB Toolbox
MATLAB
MATLAB MATLAB
z MATLAB
: (
: )
MATLAB Compiler
MATLAB C/C++ Math Library
z MATLAB C/C++ Graphics Library
MATLAB 1
help
helpwin doc Data Acquisition Toolbox
z
z
:
: 1.6
: (
: )
(R12.1) 06-April-2001
daq/analogoutput
daq/digitalio
Matlab/Simulink
58
daqdevice/set
setverify
Execution.
daqdevice/start
stop
trigger
waittilstop
addmuxchannel
flushdata
getdata
getsample
muxchanidx
peekdata
putdata
putsample
getvalue
putvalue
General.
binvec2dec
daq/private/clear
daqcallback
daqfind
daqmem
daqread
daqregister
daqreset
daqdevice/delete
dec2binvec
:
:
ischannel
isdioline
isvalid
59
length
daq/private/load
:
:
makenames
obj2mfile
daq/private/save
showdaqevents
size
daqhwinfo
daqpropedit
daqsupport
propinfo
demodaq_callback
demodaq_intro
demodaq_save
daqtimerplot
demoai_channel
demoai_fft
demoai_intro
demoai_logging
demoai_trig
daqscope
:
: -
daqplay
daqsong
demoao_channel
demoao_intro
demoao_trig
daqfcngen
Matlab/Simulink
60
Digital I/O demos.
demodio_intro
demodio_line
diopanel
2.10
:
:
2.11
:
:
:
2.11 doc daq
:
:
2.5
61
C/Fortran
:
:
2.12 %MATLABROOT%\extern\examples\mex\yprime.m
2.12
y = 2 * y + y s * ( y + ) ( y + )2 + ( y )2 3 * ( y s ) ( y s )2 + ( y )2 3
3
3
y ( 4 ) = 2 * y + y s * y ( y + )2 + ( y )2 * y ( y s )2 + ( y )2
= 1 82.54
s = 1
m t [t 0 ,t1 ] [t 0 t1 L t N ]
y t 0 [ y, y , y , y ] [y , y , y , y ( ) ]
4
m yp 1= y yp2
= y yp 3 = y yp 4 = y
(4 )
: (
: )
: (
: )
: (
: )
: (
: )
y 1 = y y 2 = y y 3 = y y 4
: (
: )
: (
: )
: (
: )
: (
: )
: (
: )
t=
: (
: )
Matlab/Simulink
62
0
0.0112
0.0224
0.0336
0.0448
0.1008
0.1568
0.2129
0.2689
0.4124
0.5559
0.6995
0.8430
0.9933
1.1435
1.2938
1.4441
1.6004
1.7567
1.9130
2.0694
2.2485
2.4276
2.6068
2.7859
2.9653
3.1446
3.3239
3.5032
3.6956
3.8880
4.0804
4.2729
4.4644
4.6559
4.8474
5.0389
5.2380
5.4371
5.6362
5.8353
6.0365
2
6.2378
6.4391
6.6403
6.8428
7.0452
7.2477
7.4501
7.6605
7.8710
8.0814
8.2918
8.4960
8.7001
8.9043
9.1085
9.3314
9.5543
9.7771
10.0000
y=
1.0000 2.0000 3.0000 4.0000
1.0230 2.1005 3.0447 3.9869
1.0471 2.2009 3.0893 3.9720
1.0723 2.3012 3.1337 3.9555
1.0986 2.4015 3.1779 3.9372
1.2471 2.9005 3.3954 3.8200
1.4234 3.3931 3.6051 3.6597
1.6271 3.8761 3.8046 3.4568
1.8575 4.3463 3.9916 3.2117
2.5633 5.4706 4.3978 2.3975
3.4198 6.4371 4.6686 1.3328
4.4011 7.1970 4.7696 0.0468
5.4744 7.7088 4.6725 -1.4214
6.6545 7.9415 4.3348 -3.1032
7.8440 7.8325 3.7366 -4.8735
8.9900 7.3614 2.8689 -6.6666
10.0378
10.9650
11.6660
63
Matlab/Simulink
64
12.0850
4.1771
8.6785
4.5031
65
2.13 plot(t,y(:,1))
>> t=0:0.1:10;
>> [t y]=ode45(@yprime,t,[1 2 3 4])
0
0.2000
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
1.1000
1.2000
1.3000
1.4000
1.5000
1.6000
1.7000
: (
2.13
0.1000
: (
: )
>> plot(t,y(:,1))
t=
: )
:
:
Matlab/Simulink
66
1.8000
1.9000
2.0000
2.1000
2.2000
2.3000
2.4000
2.5000
2.6000
2.7000
2.8000
2.9000
3.0000
3.1000
3.2000
3.3000
3.4000
3.5000
3.6000
3.7000
3.8000
3.9000
4.0000
4.1000
4.2000
4.3000
4.4000
4.5000
4.6000
4.7000
4.8000
4.9000
5.0000
5.1000
5.2000
5.3000
5.4000
5.5000
5.6000
5.7000
5.8000
5.9000
2
6.0000
6.1000
6.2000
6.3000
6.4000
6.5000
6.6000
6.7000
6.8000
6.9000
7.0000
7.1000
7.2000
7.3000
7.4000
7.5000
7.6000
7.7000
7.8000
7.9000
8.0000
8.1000
8.2000
8.3000
8.4000
8.5000
8.6000
8.7000
8.8000
8.9000
9.0000
9.1000
9.2000
9.3000
9.4000
9.5000
9.6000
9.7000
9.8000
9.9000
10.0000
67
Matlab/Simulink
68
y=
1.0000 2.0000 3.0000 4.0000
1.2447 2.8931 3.3922 3.8220
1.5780 3.7662 3.7598 3.5071
1.9967 4.6008 4.0892 3.0576
2.4961 5.3790 4.3675 2.4781
3.0696 6.0825 4.5815 1.7759
3.7092 6.6944 4.7191 0.9599
4.4050 7.1994 4.7696 0.0417
5.1455 7.5837 4.7238 -0.9652
5.9177 7.8354 4.5740 -2.0450
6.7081 7.9441 4.3136 -3.1812
7.5016 7.9006 3.9374 -4.3554
8.2827 7.6985 3.4422 -5.5484
9.0356 7.3340 2.8272 -6.7402
9.7440 6.8062 2.0939 -7.9103
10.3917
10.9629
11.4415
11.8124
12.0620
12.1781
2.0000
4.2779
6.6070
2
-13.2408 -20.8957 -18.2238
8.9603
9.7081
6.3687
43.1806
69
Matlab/Simulink
70
43.5397
0.4483
5.7133
: (
: )
/*=================================================================
* YPRIME.C
: (
: (t, y
: )
: [yp] = yprime
Sample .MEX file corresponding to YPRIME.M
: )
: *
:
: <#>
... [1]
: (
: (MAX
: )
2
71
: )
: #define MAX
[ yp] = yprime(t, y)
: (A
: )
10
*=================================================================*/
: (
11
: (A, B
12
#include <math.h>
: )
13
#include "mex.h"
: )
14
15
: (
/* Input Arguments */
16
: (
: (
17
#define
T_IN prhs[0]
: ) >
18
#define
Y_IN prhs[1]
: (
19
: (B
20
21
: )
/* Output Arguments */
22
23
: ) ?
: (
#define
YP_OUT plhs[0]
24
: (A
: )
25
#if !defined(MAX)
: ) :
26
#define
: (
27
#endif
: (B
28
: )
29
#if !defined(MIN)
: )
30
#define
: )
31
#endif
: )
... [2]
: #if !defined
32
33
#define PI 3.14159265
34
: (
: (MIN
35
static double
mu = 1/82.45;
36
static double
mus = 1 - 1/82.45;
37
: )
: )
: (
38
: (A, B
39
40
double
yp[],
41
double
*t,
42
double
y[]
43
44
: )
: )
: (
: (
: (
: (A
: )
: ) <
: (
: (B
: )
: ) ?
: (
... [3]
: r1 = sqrt
: (
: (
: (
:
: (y[0]+mu
Matlab/Simulink
72
: )
: )*
45
double
r1,r2;
46
: (
: (y[0]+mu
47
r1 = sqrt((y[0]+mu)*(y[0]+mu) + y[2]*y[2]);
: )
48
r2 = sqrt((y[0]-mus)*(y[0]-mus) + y[2]*y[2]);
: ) + y[2]*y[2]
49
: )
50
: );
51
: (
52
mexWarnMsgTxt("Division by zero!\n");
: (y[0]-mus
53
: (
54
... [5]
: (
55
yp[0] = y[1];
: )
56
yp[1] = 2*y[3]+y[0]-mus*(y[0]+mu)/(r1*r1*r1)-mu*(y[0]-mus)/(r2*r2*r2);
: )*
57
yp[2] = y[3];
: (
58
: (y[0]-mus
59
return;
: )
60
: ) + y[2]*y[2]
61
: )
62
63
64
: );
... [6]
:
: if
65
: (
66
double *yp;
67
double *t,*y;
: (r1 == 0.0
|| r2[7]
...
68
69
70
71
: )
: ){
: mexWarnMsgTx
... [8]
:
: (
72
if (nrhs != 2) {
: ("Division
by[9]
...
73
: )
74
: );
75
76
77
78
79
: (
80
m = mxGetM(Y_IN);
: (y[0]+mu
81
n = mxGetN(Y_IN);
: )
82
if (!mxIsDouble(Y_IN) || mxIsComplex(Y_IN) ||
: )/
: (
: (r1*r1*r1
: )
: )-mu*
: (
: (y[0]-mus
: )
: )/
:
... [11]
73
83
84
: YP_OUT =
mxCreateDoubleMatrix
85
: (
: (4, 1, mxREAL
86
87
: )
88
:
: );
89
90
91
yp = mxGetPr(YP_OUT);
92
93
t = mxGetPr(T_IN);
94
y = mxGetPr(Y_IN);
95
96
97
yprime(yp,t,y);
98
return;
:
: yp = mxGetPr
:
: (
: (YP_OUT
: )
: );
:
99
: t = mxGetPr
100 }
:
: (
z 12~36
z 39~60 C yprime
z 62~100 Matlab C mexFunction
MATLAB HTML MATLAB\Using MATLAB\External Interfaces/
API\Calling C and Fortran Programs from MATLAB
MATLAB mex
: (T_IN
: )
: );
y = mxGetPr
: (
: (Y_IN
: )
: );
:
: yprime
Please choose your compiler for building external interface (MEX) files:
: (
: (yp,t,y
: )
: );
:
[3] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio
:
:
[0] None
Matlab/Simulink
74
Compiler: 3
Please verify your choices:
Compiler: Microsoft Visual C/C++ 6.0
Location: C:\Program Files\Microsoft Visual Studio
Are these correct?([y]/n): y
The default options file:
"C:\Documents and Settings\Michael\Application Data\MathWorks\MATLAB\R12\mexopts.bat"
from D:\MATLAB6P1\BIN\WIN32\MATLABWizard.awx
Updated C:\Program Files\Microsoft Visual Studio\common\msdev98\template\MATLABWizard.hlp
from D:\MATLAB6P1\BIN\WIN32\MATLABWizard.hlp
Updated C:\Program Files\Microsoft Visual Studio\common\msdev98\addins\MATLABAddin.dll
from D:\MATLAB6P1\BIN\WIN32\MATLABAddin.dll
Merged D:\MATLAB6P1\BIN\WIN32\usertype.dat
with C:\Program Files\Microsoft Visual Studio\common\msdev98\bin\usertype.dat
Note: If you want to use the MATLAB Visual Studio add-in with the MATLAB C/C++
:
:
Compiler, you must start MATLAB and run the following commands:
:
cd(prefdir);
mccsavepath;
(You only have to do this configuration step once.)
>> mex yprime.c
dir yprime.dll
>> dir yprime.dll
yprime.dll
yprime.c 2.12 m
C yprime
2
>> [t y]=ode45(@yprime,[0 10],[1 2 3 4])
t=
0
0.0112
0.0224
0.0336
0.0448
0.1008
0.1568
0.2129
0.2689
0.4124
0.5559
0.6995
0.8430
0.9933
1.1435
1.2938
1.4441
1.6004
1.7567
1.9130
2.0694
2.2485
2.4276
2.6068
2.7859
2.9653
3.1446
3.3239
3.5032
3.6956
3.8880
4.0804
4.2729
4.4644
4.6559
4.8474
5.0389
5.2380
75
:
Matlab/Simulink
76
5.4371
5.6362
5.8353
6.0365
6.2378
6.4391
6.6403
6.8428
7.0452
7.2477
7.4501
7.6605
7.8710
8.0814
8.2918
8.4960
8.7001
8.9043
9.1085
9.3314
9.5543
9.7771
10.0000
y=
1.0000 2.0000 3.0000 4.0000
1.0230 2.1005 3.0447 3.9869
1.0471 2.2009 3.0893 3.9720
1.0723 2.3012 3.1337 3.9555
1.0986 2.4015 3.1779 3.9372
1.2471 2.9005 3.3954 3.8200
1.4234 3.3931 3.6051 3.6597
1.6271 3.8761 3.8046 3.4568
1.8575 4.3463 3.9916 3.2117
2.5633 5.4706 4.3978 2.3975
3.4198 6.4371 4.6686 1.3328
4.4011 7.1970 4.7696 0.0468
5.4744 7.7088 4.6725 -1.4214
6.6545 7.9415 4.3348 -3.1032
7.8440 7.8325 3.7366 -4.8735
2
8.9900 7.3614 2.8689 -6.6666
10.0378
10.9650
11.6660
12.0850
4.1771
8.6785
77
Matlab/Simulink
78
4.5031
2
3.3000
3.4000
3.5000
3.6000
3.7000
3.8000
3.9000
4.0000
4.1000
4.2000
4.3000
4.4000
4.5000
4.6000
4.7000
4.8000
4.9000
5.0000
5.1000
5.2000
5.3000
5.4000
5.5000
5.6000
5.7000
5.8000
5.9000
6.0000
6.1000
6.2000
6.3000
6.4000
6.5000
6.6000
6.7000
6.8000
6.9000
7.0000
7.1000
7.2000
7.3000
7.4000
79
Matlab/Simulink
80
7.5000
7.6000
7.7000
7.8000
7.9000
8.0000
8.1000
8.2000
8.3000
8.4000
8.5000
8.6000
8.7000
8.8000
8.9000
9.0000
9.1000
9.2000
9.3000
9.4000
9.5000
9.6000
9.7000
9.8000
9.9000
10.0000
y=
1.0000 2.0000 3.0000 4.0000
1.2447 2.8931 3.3922 3.8220
1.5780 3.7662 3.7598 3.5071
1.9967 4.6008 4.0892 3.0576
2.4961 5.3790 4.3675 2.4781
3.0696 6.0825 4.5815 1.7759
3.7092 6.6944 4.7191 0.9599
4.4050 7.1994 4.7696 0.0417
5.1455 7.5837 4.7238 -0.9652
5.9177 7.8354 4.5740 -2.0450
6.7081 7.9441 4.3136 -3.1812
7.5016 7.9006 3.9374 -4.3554
2
8.2827 7.6985 3.4422 -5.5484
9.0356 7.3340 2.8272 -6.7402
9.7440 6.8062 2.0939 -7.9103
10.3917
10.9629
11.4415
11.8124
12.0620
12.1781
2.0000
4.2779
6.6070
8.9603
81
Matlab/Simulink
82
9.7081
6.3687
43.1806
43.5397
83
0.4483
5.7133
-1.0947
2.6
MATLAB MATLAB
m
2.5 C Fortran mex MATLAB
m
e:\material\mytoolbox e:\material\mytoolbox MATLAB
2.14 Matlab
2.14 MATLAB
: (
: )
:
:
:
Matlab/Simulink
84
:
:
:
2.7
:
:
:
Matlab m C/Fortran
MATLAB
4 1010 0123
0.50.10.150.25 Communications Toolbox m
randsrc
: (
: )
: the
%
% ALPHABET can be either a row vector or a two-row matrix:
% Row
: of
: of
uniform.
: is
%
% OUT = RANDSRC(M,N,ALPHABET,STATE) resets the state of RAND to STATE.
: The
85
%
% Examples:
%
out = randsrc(2,3)
% out =
out =
-1
-1
-1
-1
%
%
% out =
out =
%
% See also RAND, RANDINT, RANDERR.
% Copyright 1996-2001 The MathWorks, Inc.
% $Revision: 1.6 $ $Date: 2001/04/23 15:32:46 $
% Basic function setup.
error(nargchk(0,4,nargin));
% --- Placeholder for the signature string.
sigStr = '';
m = [];
n = [];
alpha = [];
state = [];
% --- Identify string and numeric arguments
for i=1:nargin
if(i>1)
sigStr(size(sigStr,2)+1) = '/';
end;
% --- Assign the string and numeric flags
if(isnumeric(varargin{i}))
sigStr(size(sigStr,2)+1) = 'n';
else
error('Only numeric arguments are accepted.');
end;
end;
% --- Identify parameter signitures and assign values to variables
switch sigStr
Matlab/Simulink
86
% --- randsrc
case ''
% --- randsrc(m)
case 'n'
m
= varargin{1};
% --- randsrc(m, n)
case 'n/n'
= varargin{1};
= varargin{2};
% --- randsrc(m, n, alpha)
case 'n/n/n'
= varargin{1};
= varargin{2};
alpha = varargin{3};
% --- randsrc(m, n, alpha, state)
case 'n/n/n/n'
m
= varargin{1};
= varargin{2};
alpha = varargin{3};
state = varargin{4};
% --- If the parameter list does not match one of these signatures.
otherwise
error('Syntax error.');
end;
if isempty(m)
m = 1;
end
if isempty(n)
n = m;
end
if isempty(alpha)
alpha = [-1, 1];
end
% Typical error-checking.
if (~isfinite(m)) | (~isfinite(n))
87
is [0.3 0.4 0.3] then 'prob' would be set to [0.3 0.7 1.0].
prob = cumsum(aprob);
else
% Define the 'prob' vector if the probabilities are not given in the function call.
Matlab/Simulink
88
rand('state', state);
end
% Generate the random matrix.
r = rand(m,n);
will contain integers from one to four after this loop has run.
for i = 1:ac
idx = idx + (r >= prob(i));
end
alphabet = alpha(1,:);
% Assign alphabet elements to the output matrix as specified by 'idx'.
out = alphabet(idx);
% A special case, if the m and n parameters specify a column vector.
if n == 1
out = out(:);
end
% [EOF] randsrc.m
>> randsrc(10,10,[0 1 2 3;0.5 0.1 0.15 0.25])
ans =
3
5 H (z ) =
89
1 + 2 z 1
m
1 + 2 z 1 + 3z 2
plotpz.m
%plotpz.m - plot the zero and pole plane from
%transfer function
%
%
-1
-2
b(1)+b(2)*z +b(3)*z
%H(z)=------------------------%
%
-1
-2
a(1)+a(2)*z +a(3)*z
b=[1 2 0];
a=[1 2 3];
[z,p,k]=tf2zp(b,a);
zplane(z,p);
>> plotpz
2.15
2.15 plotpz
6 Sobel Canny
m edge_detect.m
function [BW1 BW2]=edge_detect(filename)
%EDGE_DETECT Detect the edge of input image
%This function takes an intensity image I as its input,
%and plots and return two binary images BW of the same
%size as I,with 1's where the function finds edges in
%I and 0's elsewhere with Sobel and Canny method.
:
:
: :
Matlab/Simulink
90
I = imread(filename);
2.16 2.17
>> which rice.tif
D:\MATLAB6p1\toolbox\images\imdemos\rice.tif
>> [sobel canny]=edge_detect('rice.tif');
91
2.18 2.19
:
2.16
edge_detect('blood1.tif')1
2.17
edge_detect('blood1.tif')2
:
:
Matlab/Simulink
92
2.18
:
edge_detect('rice.tif')1
:
: 3
2.19
:
edge_detect('rice.tif')2
>> whos
:
: 4
Name
Size
Bytes Class
canny
256x256
sobel
256x256
71:
[1]
xiao
2002-10-4 12:06:00
#if !defined
71:
[2]
xiao
2002-10-4 12:06:00
71:
[2]
xiao
2002-10-4 12:09:00
xiao
2002-10-4 12:08:00
xiao
2002-10-4 12:10:00
xiao
2002-10-4 12:13:00
[6]
xiao
2002-10-4 12:13:00
[7]
xiao
2002-10-4 12:14:00
xiao
2002-10-4 12:14:00
xiao
2002-10-4 12:14:00
xiao
2002-10-4 12:16:00
xiao
2002-10-4 12:17:00
#endif
71:
[3]
)
#define
71:
MIN
[4]
#define PI 3.14159265
72:
[5]
);
r2 = sqrt
72:
);
72:
72:
[8]
mexWarnMsgTxt
72:
[9]
("Division by zero!\n"
72:
[10]
yp[1] = 2*y[3]+y[0]-mus*
72:
[11]
MATLAB Compiler m
MATLAB
MATLAB Compiler
z MATLAB C/C++ Math Library
m
m
()
MATLAB Compiler
mC/C++
C/C++
3.1
Matlab/Simulink
94
C/C++
C/C++ MATLAB C/C++ MATLAB
C/C++ Math Library MathWorks C/C++ MATLAB
C/C++ C/C++ MATLAB fft
MATLAB C/C++ Math Library mlfFft FFT
MATLAB
m C/C++ C/C++
3.1
: (
: )
: 1
C/C++ compiler
[0] None
Compiler: 3
Please verify your choices:
Compiler: Microsoft Visual C/C++ 6.0
Location: C:\Program Files\Microsoft Visual Studio
Are these correct?([y]/n): y
The default options file:
"C:\Documents and Settings\Yongchun\Application Data\MathWorks\MATLAB\R12\mexopts.bat"
is being updated from D:\MATLAB6P1\BIN\WIN32\mexopts\msvc60opts.bat...
95
from D:\MATLAB6P1\BIN\WIN32\MATLABWizard.awx
Updated C:\Program Files\Microsoft Visual Studio\common\msdev98\template\MATLABWizard.hlp
from D:\MATLAB6P1\BIN\WIN32\MATLABWizard.hlp
Updated C:\Program Files\Microsoft Visual Studio\common\msdev98\addins\MATLABAddin.dll
from D:\MATLAB6P1\BIN\WIN32\MATLABAddin.dll
Merged D:\MATLAB6P1\BIN\WIN32\usertype.dat
with C:\Program Files\Microsoft Visual Studio\common\msdev98\bin\usertype.dat
Note: If you want to use the MATLAB Visual Studio add-in with the MATLAB
C/C++Compiler, you must start MATLAB and run the following commands:
:
:
cd(prefdir);
mccsavepath;
(You only have to do this configuration step once.)
>> cd(prefdir)
>> mccsavepath
: (
: )
: (
: )
: (
: )
: (
: )
: (
: )
:
Matlab/Simulink
96
:
:
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C/C++ 6.0
Location: C:\Program Files\Microsoft Visual Studio
Are these correct?([y]/n): y
The default options file:
"C:\Documents and Settings\Yongchun\Application Data\MathWorks\MATLAB\R12\compopts.bat"
from D:\MATLAB6P1\BIN\WIN32\MATLABWizard.awx
Updated C:\Program Files\Microsoft Visual Studio\common\msdev98\template\MATLABWizard.hlp
from D:\MATLAB6P1\BIN\WIN32\MATLABWizard.hlp
Updated C:\Program Files\Microsoft Visual Studio\common\msdev98\addins\MATLABAddin.dll
from D:\MATLAB6P1\BIN\WIN32\MATLABAddin.dll
Merged D:\MATLAB6P1\BIN\WIN32\usertype.dat
with C:\Program Files\Microsoft Visual Studio\common\msdev98\bin\usertype.dat
mbuild setup
<UserProfile>\Application Data\MathWorks\MATLAB\R12 Windows
$HOME/.matlab/R12 UNIX mbuild/mcc m
:
: (
: )
: (
: )
97
3.2 m
C/C++
7 16 Butterworth Fs=16kHz 1.5kHz
5kHz m C/C++
:
: kHz
:
:
function designbutworth
: kHz
%designbutworth.m
: kHz
: KHz
Fs=16;
: KHz
[b,a]=butter(8,[1.5/(Fs/2) 5/(Fs/2)],'bandpass')
: K
freqz(b,a,512,16000)
>> designbutworth
: KHz
b=
Columns 1 through 6
0.0040
0 -0.0320
0 0.1120
Matlab/Simulink
98
Columns 7 through 12
-0.2241
0 0.2801
0 -0.2241
Columns 13 through 17
0.1120
0 -0.0320
0 0.0040
a=
Columns 1 through 6
1.0000 -3.3774 6.1293 -8.2873 9.8335 -10.1137
Columns 7 through 12
8.8294 -6.6792 4.5314 -2.7004 1.3838 -0.6100
Columns 13 through 17
0.2342 -0.0737 0.0181 -0.0032 0.0004
3.3
:
3.3
>> mcc -B sgl designbutworth.m
99
mcc B sgl m C
bin
bilinear.c
freqz.c
buffer_mex_interface.c
freqzplot.c
buttap.c
signal_private_dividenowarn.c
butter.c
signal_private_db.c
datawrap.c
psdoptions.c
designbutworth.c
lp2lp.c
designbutworth_mainhg.c
signal_private_iirchk.c
subplot.c
lp2hp.c
lp2bs.c
lp2bp.c
designbutworth.exe
designbutworth.h
lp2bs.h
lp2bp.h
datawrap.h
lp2hp.h
butter.h
lp2lp.h
buttap.h
psdoptions.h
buffer_mex_interface.h
signal_private_db.h
bilinear.h
signal_private_dividenowarn.h
freqz.h
signal_private_iirchk.h
freqzplot.h
Matlab/Simulink
100
subplot.h
>> !designbutworth
b=
Columns 1 through 7
0.0040
0 -0.0320
0 0.1120
0 -0.2241
Columns 8 through 14
0 0.2801
0 -0.2241
0 0.1120
Columns 15 through 17
-0.0320
0 0.0040
a=
Columns 1 through 7
1.0000 -3.3774 6.1293 -8.2873 9.8335 -10.1137 8.8294
Columns 8 through 14
-6.6792 4.5314 -2.7004
Columns 15 through 17
0.0181 -0.0032 0.0004
3.4
3.4
>> !del bin
E:\material\book\example7\bin\*, (Y/N) ? y
y
>> !designbutworth
b=
Columns 1 through 7
0.0040
0 -0.0320
0 0.1120
0 -0.2241
Columns 8 through 14
0 0.2801
0 -0.2241
0 0.1120
Columns 15 through 17
-0.0320
0 0.0040
a=
Columns 1 through 7
1.0000 -3.3774 6.1293 -8.2873 9.8335 -10.1137 8.8294
Columns 8 through 14
101
Matlab/Simulink
102
Columns 15 through 17
0.0181 -0.0032 0.0004
Warning: Unable to find FigureToolBar.fig on path - not adding built-in toolbar.
3.5
3.5
bin
bilinear.cpp
freqz.cpp
buffer_mex_interface.cpp
freqzplot.cpp
buttap.cpp
signal_private_dividenowarn.cpp
butter.cpp
signal_private_db.cpp
103
datawrap.cpp
psdoptions.cpp
designbutworth.cpp
lp2lp.cpp
designbutworth_mainhg.cpp
signal_private_iirchk.cpp
subplot.cpp
lp2hp.cpp
lp2bs.cpp
lp2bp.cpp
designbutworth.exe
designbutworth.hpp
lp2bs.hpp
lp2bp.hpp
datawrap.hpp
lp2hp.hpp
butter.hpp
lp2lp.hpp
buttap.hpp
psdoptions.hpp
buffer_mex_interface.hpp
signal_private_db.hpp
bilinear.hpp
signal_private_dividenowarn.hpp
freqz.hpp
signal_private_iirchk.hpp
freqzplot.hpp
subplot.hpp
>> which mcc
D:\MATLAB6p1\toolbox\compiler\mcc.dll
>> help mcc
MCC MATLAB to C/C++ Compiler (Version 2.2).
MCC [-options] fun [fun2 ...] [mexfile1 ...] [mlibfile1 ...]
Translate fun.m to fun.c or fun.cpp, and optionally create any Supported
binary file. Write any resulting files into the current directory, by default.
Matlab/Simulink
104
OPTIONS:
A <option> Specify annotation. The following table shows valid
<option>strings and their effects:
annotation:all (*) - All lines from source M-file appears as
comments in generated output file.
annotation:comments - Comments from source M-file appear as
comments in generated output file.
annotation:none
line:off (*)
debugline:on
105
:
sglcpp
applications
pcode
Matlab/Simulink
106
If you wish to have some optimizations on, you may specify them
after the debug switch.
h Compile helper functions. All M-functions called will be
compiled into the resulting MEX-file or stand-alone application.
I <path> Include path. Add <path> to the list of paths to search
for M-files. The MATLAB path is automatically included when
running from MATLAB, but NOT when running from DOS or the Unix
shell. See "help mccsavepath".
L <option> Language. Specifies target language. <option> can be
"C"for C,"Cpp" for C++, or "P" for MATLAB P-code.
l Line. Generates code that reports file name and line numbers on
run-time errors. (Equivalent to -A debugline:on)
m Macro that generates a C stand-alone application. This is
equivalent to the options "-t -W main -L C -h -T link:exe
libmmfile.mlib", which can be found in the file <MATLAB>/toolbox/compiler/bundles/
macro_option_m.
Note: the "-h" means that helper functions will be included.
M "<string>" Pass <string> to the MBUILD or MEX script used to
build an executable. If -M is used multiple times, the rightmost
occurrence is used.
o <outputfilename> Output name. Set the name of the final
executable output (MEX or stand-alone application) to
<outputfilename>. A suitable,possibly platform-dependent,
extension is added to <outputfilename> (e.g., ".exe" for PC
stand-alone applications, ".mexsol" for Solaris MEX-files).
O <optimization> Optimization. There are three possibilities:
<optimization class>:[on|off] - Turns the class on or off
For example: -O fold_scalar_mxarrays:on
list - Lists the available optimization classes.
<optimization level> - Uses a bundle file called
opt_bundle_<level> to determine which optimizations are on or off.
107
macro_option_p.
Note: the "-h" means that helper functions will be included.
S Macro that generates Simulink C-MEX S-Function. This is
equivalent to the options "-t -W simulink -L C -T link:mex
libmatlbmx.mlib", which can be found in the file <MATLAB>/toolbox/compiler/bundles/
macro_option_S.
Note: the absence of "-h" means that helper functions will not
be included.
t Translate M code to target language. Translate any M-functions
specified on the command line to C or C++ functions. This option
is included in all macro options. Omitting it allows the
generation of wrapper C/C++files without generating the C/C++ files corresponding to M-files.
T <option> Specify target phase and type. The following table shows
valid <option> strings and their effects:
codegen
compile:mex
compile:lib
link:mex
Matlab/Simulink
108
link:lib
109
Matlab/Simulink
110
% yields myfun1.c
mcc -t -L C myfun2
% yields myfun2.c
% yields myfun1.o
% yields myfun2.o
% yields myfun1_main.o
111
Note: on PCs, filenames ending with .o above would actually end with .obj.
3.3
m C/C++
8 Butterworth 16
Fs=16kHz1.5kHz~5kHz m
C
: (
: )
:
: A
: kHz
:
:
function dsgnbutworth_varorder(order)
: kHz
%dsgnbutworth_varorder.m
: kHz
: KHz
: KHz
: KHz
return;
: ~
end
Fs=16;
[b,a]=butter(order/2,[1.5/(Fs/2) 5/(Fs/2)],'bandpass')
freqz(b,a,512,16000)
>> dsgnbutworth_varorder(14)
The order should be an even integer,not less than 16!
>> dsgnbutworth_varorder(15)
The order should be an even integer,not less than 16!
>> dsgnbutworth_varorder(16)
b=
Matlab/Simulink
112
Columns 1 through 7
0.0040
0 -0.0320
0 0.1120
0 -0.2241
Columns 8 through 14
0 0.2801
0 -0.2241
0 0.1120
Columns 15 through 17
-0.0320
0 0.0040
a=
Columns 1 through 7
1.0000 -3.3774 6.1293 -8.2873 9.8335 -10.1137 8.8294
Columns 8 through 14
-6.6792 4.5314 -2.7004
Columns 15 through 17
0.0181 -0.0032 0.0004
3.6
>> mcc -B sgl dsgnbutworth_varorder.m
>> !dir /w /b dsgnbutworth_varorder.exe
dsgnbutworth_varorder.exe
>> !dsgnbutworth_varorder 14
Warning: COLON arguments must be real scalars.
ERROR: Matrix dimensions must agree.
EXITING
>> !dsgnbutworth_varorder 15
The order should be an even integer,not less than 16!
>> !dsgnbutworth_varorder 16
Warning: COLON arguments must be real scalars.
:
3.6
113
3.6
: KHz
: KHz
%rate 16kHz.
: KHz
if ischar(order)
disp('The input argument is always taken as a string when converting');
disp('m function to console Application!');
order=str2num(order);
end
:
:
return;
end
if order<16|(mod(order,2)~=0)
disp('The order should be an even integer,not less than 16!');
Matlab/Simulink
114
Fs=16;
[b,a]=butter(order/2,[1.5/(Fs/2) 5/(Fs/2)],'bandpass')
freqz(b,a,512,16000)
>> mcc -B sgl dsgnbutworth_varorder.m
>> !dsgnbutworth_varorder 14
The input argument is always taken as a string when converting
m function to console Application!
The order should be an even integer,not less than 16!
>> !dsgnbutworth_varorder 15
The input argument is always taken as a string when converting
m function to console Application!
The order should be an even integer,not less than 16!
>> !dsgnbutworth_varorder 16
The input argument is always taken as a string when converting
m function to console Application!
b=
Columns 1 through 7
0.0040
0 -0.0320
0 0.1120
0 -0.2241
Columns 8 through 14
0 0.2801
0 -0.2241
0 0.1120
Columns 15 through 17
-0.0320
0 0.0040
a=
Columns 1 through 7
1.0000 -3.3774 6.1293 -8.2873 9.8335 -10.1137 8.8294
Columns 8 through 14
-6.6792 4.5314 -2.7004
115
Columns 15 through 17
0.0181 -0.0032 0.0004
3.7
:
3.7
z MATLAB
7 II
function designbutworthand2df2
%designbutworthand2df2.m
%used to design 16-order Butterworth filter,which has a 1.5kHz-5kHz passband
: KHz
: KHz
Fs=16;
[b,a]=butter(8,[1.5/(Fs/2) 5/(Fs/2)],'bandpass');
: KHz
h=df2(b,a)
Matlab/Simulink
116
>> !designbutworthand2df2
function testinputandeval
R = input('Input MATLAB expression: ','s');
R
eval(R);
MATLAB
>> mcc -B sgl testinputandeval
>> a='sin(10)'
a=
sin(10)
>> !testinputandeval
Input MATLAB expression: a
R=
a
ERROR: Reference to unknown function or variable 'a' while evaluating
expression.
EXITING
>> !testinputandeval
Input MATLAB expression: sin(10)
R=
sin(10)
117
ans =
-0.5440
z
load save
function testls
%testls.m
y= 'a';
load('testls.mat',y);
a MATLAB testls.mat
function testls
%testls.m
load('testls.mat','a');
a
23
7 14 16
6 13
15
20 22
Matlab/Simulink
118
10 12 19 21
11 18 25
MATLAB Compiler
MATCOM MATCOM m m m
C/C++
3.4 VC++ m
VC++ m mex setupcdprefdir
mccsavepath mbuild setup Microsoft Visual C++ MSVCversions 5.0 & 6.0
Microsoft Visual C++
MSVC versions 6.0 Microsoft Visual C++ MSVC
versions 5.0
1. Microsoft Visual C++ IDE File|New... MATLAB
Project Wizard 3.8 OK 3.9
: (
: )
:
: (
: )
: (
: )
:
: (
: (
: )
: )
4. 3.11 m
3.12
: (
: )
119
:
3.11
120
Matlab/Simulink
3.12
mcc-log.txt
5. 4 plotfreq.m 3.13
VC++ 3.14
:
:
3.13 plotfreq.m
: (
: )
:
3.15 plotfreqprj.exe
121
Matlab/Simulink
122
3.17
bin plotfreqprj.exe
: (
: )
123
3.18
3.19
124
Matlab/Simulink
3.21
consoleprj
3.22
125
mysvd.cpp
: (
: )
#include "stdafx.h"
#include "matlab.h"
static double data[] = { 21, 3, 15, 57, 12, 83, 6, 90 };
int mysvd()
{
/* Initialize pointers to array arguments */
mxArray *X = NULL;
mxArray *U = NULL, *S = NULL, *V = NULL;
mlfEnterNewContext(0, 0);
mlfAssign(&X, mlfDoubleMatrix(4, 2, data, NULL));
/* Compute the singular value decomposition and print it */
mlfAssign(&S, mlfSvd(NULL, NULL, X, NULL));
mlfPrintf("One input, one output:\n");
mlfPrintf("S = \n"); mlfPrintMatrix(S);
/* Multiple output arguments */
mlfAssign(&U, mlfSvd(&S, &V, X, NULL));
mlfPrintf("One input, three outputs:\n");
mlfPrintf("U = \n"); mlfPrintMatrix(U);
Matlab/Simulink
126
3.23
mysvd.cpp
6. 3.24
MATLAB C Math Library
3.24
127
consoleprj.cpp
: (
: )
: (
: )
Matlab/Simulink
128
3.25 %MATLABROOT%\extern\inlcude
:
:
3.26
%MATLABROOT%\extern\lib\win32\Microsoft\msvc60
3.27
: 9.
3.27 Microsoft
Visual C++ IDE
Project|Settings
%MATLABROOT%\extern\lib
\win32\Microsoft\msvc60
libmmfile.lib
libmwarpack.liblibeng.lib
libmwlapack.liblibmat.lib
libmwsglm.liblibmatlb.lib
libmx.liblibmatlbmx.lib
sgl.lib libmex.lib
Link Object/library
modules
( Microsoft Visual
C++ 5.0
%MATLABROOT%\extern\lib
\win32 \Microsoft\msvc50
)
10.
3.28
3.28
129
consoleprj.exe
: (
: )
:
130
Matlab/Simulink
3.30
Single document
:
: 3.
mfcprjView.h
int mysvd
: (
: CDC *pDC
: )
: ;
3.31
mfcprj
131
#if !defined(AFX_MFCPRJVIEW_H__8A4E40B9_A69C_4760_AE4C_06D3FB7B69CC__INCLUDED_)
#define AFX_MFCPRJVIEW_H__8A4E40B9_A69C_4760_AE4C_06D3FB7B69CC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
: #if !defined(AF
X_MFCPRJVIEW_H__8A4E
40B9_A69C_4760_AE4C_06
D3FB7B69CC__INC
#LUDED_)define
AFX_MFCPRJVIEW_H__8A
4E40B9_A69C_4760_AE4C_
06D3FB7B69CC__
#INCLUDED_
:
:
:
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
Matlab/Simulink
132
protected:
//{{AFX_MSG(CMfcprjView)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
:
:
4.
matlab.h
z
z mysvdCDC *pDC
z OnDrawCDC* pDC mysvdCDC *pDC
z
: (
: )
: (
: )
#include "stdafx.h"
#include "mfcprj.h"
: )
#include "mfcprjDoc.h"
#include "mfcprjView.h"
#include "matlab.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static double data[] = { 21, 3, 15, 57, 12, 83, 6, 90 };
: (
////////////////////////////////////////////////////////////////////////
// CMfcprjView
IMPLEMENT_DYNCREATE(CMfcprjView, CView)
BEGIN_MESSAGE_MAP(CMfcprjView, CView)
//{{AFX_MSG_MAP(CMfcprjView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////
// CMfcprjView construction/destruction
CMfcprjView::CMfcprjView()
{
// TODO: add construction code here
}
CMfcprjView::~CMfcprjView()
{
}
BOOL CMfcprjView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
////////////////////////////////////////////////////////////////////////
// CMfcprjView drawing
void CMfcprjView::OnDraw(CDC* pDC)
{
CMfcprjDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
133
Matlab/Simulink
134
: pDC>TextOut(0,nHeight,"This is a
demo of calling SVD function
directly");
135
:
:
:
:
Matlab/Simulink
136
137
6. mfcprj 3.32
:
:
3.32
mfcprj.exe
138
Matlab/Simulink
3.6 VB MATLAB
VB MATLAB
MATLAB MatrixVB MatrixVB MATLAB
MathWorks http://www.mathworks.com MatrixVB4.51
3.33
139
4. 3.35 3.36
Next 3.37
3.36
5. MatrixVB license
3.38 license license OK
:
: (
:
: )
140
Matlab/Simulink
3.37
Installing
3.39 MatrixVB
: L
: r
141
3.41
>> plot(invhilb(5))
3.42
: L
Matlab/Simulink
142
3.42
plot(invhilb(5))
131:
[1]
fcr
2002-9-17 9:16:00
};
#ifndef _DEBUG // debug version in mfcprjView.cpp
inline CMfcprjDoc* CMfcprjView::GetDocument()
{ return (CMfcprjDoc*)m_pDocument; }
#endif
////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous //line.
#endif // !defined(AFX_MFCPRJVIEW_H__8A4E40B9_A69C_4760_AE4C_
06D3FB7B69CC__ INCLUDED_)
Simulink
Simulink MATLAB
Simulink Real-Time Workshop
C
4.1
Simulink
Simulink Simulink
Simulink Simulink
Stateflow
Simulink Simulink
z
z
z
z
z
z
z
Simulink Simulink
MATLAB Simulink
Simulink
z DSP Blockset
z Communications Blockset
MATLAB
z
: (
: )
:
Matlab/Simulink
144
4.2
Simulink 4.1
4.1 Simulink
z Simulink/Continuous 4.2
: (
: )
4.2
z
Simulink/Discrete 4.3
: (
: )
Simulink
145
4.3
z
4.4 S-
z
z
z
Simulink/Math 4.5
Simulink/Nonlinear 4.6
Simulink/Signals & Systems 4.7
: (
: )
: (
: )
: (
: )
: (
: )
146
Matlab/Simulink
4.5
4.6
Simulink
147
4.7
z
Simulink/Sinks 4.8
: (
: )
: ,
4.8
Matlab/Simulink
148
z
Simulink/Sources 4.9
: (
: )
4.9
z
Simulink/Subsystems 4.10
: (
: )
4.10
Simulink
4.3
149
Blocksets
Blocksets MathWorks
Simulink
DSP Blockset
4.11
4.11
DSP Blockset
Matlab/Simulink
150
4.12
4.4
Simulink
Simulink
MATLAB
:
:
:
Simulink
151
Simulink Simulink
4.13
SIMULINK
<#>
<#>
4.13
4.13
4.14
Matlab/Simulink
152
()
4.14 Simulink
4.5
4.13
z 0 0
z
Simulink
Simulink
: (
: )
:
: (
: )
Simulink
153
Simulink 4.15
4.15 Simulink
Abs
Saturation
Signals&Systems HitCrossing
z
z
z
9 4.16 Fcn Abs
Fcn Abs
4.17
4.18 Advanced
Opimimations/Zero crossing detection Off
4.16 4.19
<#>
Matlab/Simulink
154
4.16
4.17
zerocrossing_detect.mdl
zerocrossing_detect.mdl
4.18
Simulink
155
4.19 zerocrossing_detect.mdl
Direct feedthrough
Gain
Unit Delay Simulink
Simulink
4.20
Simulink
1-x-x=xx=0.3333
4.20
algebra_loop.mdl
Simulink 4.20
Simulink/Math Algebraic Constraint Algebraic
156
Matlab/Simulink
Constraint
Simulink/Signals & Systems/IC
IC
Simulink Newton
4.21 x x 2 = 0
2
4.22 x x 2 = 0
2
: (
: )
:
:
:
Simulink
157
4.21 4.22
x 2 x 2 = 0 Algebraic Constraint
4.23
Configuration options/Algebraic loop Warning
MATLAB 4.23
4.21 algebraic_constraint.mdl
algebraic_constraint MATLAB
:
:
:
:
?
: Warning: Block
diagram 'algebraic_constraint'
contains 2 algebraic
: loop(s).
Found algebraic loop
containing block(s):
'algebraic_constraint/Algebraic
Constraint Initial Guess: 5/Initial
:
: Guess'
'algebraic_constraint/Sum'
'algebraic_constraint/Sum1'
'algebraic_constraint/Product'
'algebraic_constraint/Product1'
'algebraic_constraint/Algebraic Constraint Initial Guess: 5/Sum' (algebraic variable)
'algebraic_constraint/Algebraic
Constraint Initial Guess: 5/Sum'
:
: (algebraic
variable)
Found algebraic loop
containing block(s):
'algebraic_constraint/Algebraic
Constraint Initial Guess:
5/Initial ]
:
: Guess'
'algebraic_constraint/Sum2'
'algebraic_constraint/Sum3'
'algebraic_constraint/Product1'
4.23
'algebraic_constraint/Algebraic
Constraint Initial Guess:
5/Sum'
:
: (algebraic
variable)
Matlab/Simulink
158
4.6
C m
Simulink C m Simulink
C m C m
S- S- Simulink
m C
z C S- Simulink Real-Time
Workshop m S- Simulink
z C S- m
C S-
z Simulink
S-
S- S- MATLAB
Document PDF sfunctions.pdf C m
10 Simulink y = 10 * x C
1. S-
/*
* File : times10_c.c
* An example C-file S-function for multiplying an input by 10,
*
y = 10*u
*/
: (
: )
Simulink
i;
159
Matlab/Simulink
160
*y
int_T
width = ssGetOutputPortWidth(S,0);
= ssGetOutputPortRealSignal(S,0);
*/
static void mdlTerminate(SimStruct *S)
{
}
#endif
: (
: )
:
Simulink
161
4.24 S-Function
4.25
sintx10.mdl
5. 4.28
4.29 C 10
: (
: )
162
Matlab/Simulink
4.27 S-Function
4.28 sintx10.mdl
Simulink
4.29
163
sintx10.mdl
11 Simulink y = 10 * x m
1. m S-
function [sys,x0,str,ts] = times10_m(t,x,u,flag)
%TIMES10_m S-function whose output is ten times its input.
% This M-file illustrates how to construct an M-file S-function that
% computes an output value based upon its input. The output of this
% S-function is ten times the input value:
%
%
y = 10 * u;
%
% Dispatch the flag. The switch function controls the calls to
% S-function routines at each simulation stage of the S-function.
%
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
% Initialize the states, sample times, and state ordering strings.
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
% Return the outputs of the S-function block.
case 3
sys=mdlOutputs(t,x,u);
Matlab/Simulink
164
%%%%%%%%%%%%%%%%%%%
% Unhandled flags %
%%%%%%%%%%%%%%%%%%%
% There are no termination tasks (flag=9) to be handled.
% Also, there are no continuous or discrete states,
% so flags 1,2, and 4 are not used, so return an emptyu
% matrix
case { 1, 2, 4, 9 }
sys=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Unexpected flags (error handling)%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Return an error message for unhandled flag values.
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end timestwo
%
%=======================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=======================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes()
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs
sizes.NumInputs
Simulink
165
% end mdlInitializeSizes
%
%=======================================================================
% mdlOutputs
% Return the output vector for the S-function
%=======================================================================
%
function sys = mdlOutputs(t,x,u)
sys = u * 10;
% end mdlOutputs
2. m S- 10
sintx10.mdl S-Function 4.30 times10_m.m
MATLAB 10
MATLAB
: 22
4.30 S-Function
: (
: )
: 22
4.7
Blockset
:
12 10 11 Blockset
1. times10_c Windows times10_c.dlltimes10_c.c
: [ 10]
: [ 11]
: (
: )
166
Matlab/Simulink
times10_m.m e:/material/book/myblksetdemo
2. e:\material\book\myblksetdemo Simulink
Library Browser|File|New|Library
3. Simulink\Functions & Tables\S-Function 4.31
4.32 4.33
4.31
: (
: )
: (
: )
m S-Function C S-Function
4.32
m S-
4.33 C S-
Simulink
167
4.35
4.34
4.35
4.36
168
Matlab/Simulink
:
4.37
4.38
Simulink
4.40
169
4.41 times10.mdl
9. 4.40 Simulink\Math\Gain 10
4.42
4.42
Gain times10.mdl
1.
2.
3.
4.
Matlab/Simulink
170
5.
6.
blkStruct.Name
7.
blkStruct.OpenFcn = 'times10';
8.
blkStruct.MaskInitialization = '';
9.
10.
11.
12.
% Return the name of the library model and the name for it
13.
14.
Browser(1).Library = 'times10';
15.
16.
17.
blkStruct.Browser = Browser;
18.
19.
% End of slblocks.m
7 mdl
z 14 mdl
z 15 Simulink Library Browser
Simulink Library Browser MATLAB
slblocks.m Simulink Library Browser
11. e:\material\book\myblksetdemo MATLAB 4.43
4.43 MATLAB
: (
: )
: (
: )
Simulink
171
Matlab/Simulink
172
4.8
Simulink
Simulink
Simulink Matlab Matlab
Simulink
Simulink MATLAB
Document PDF sl_using.pdf MathWorks
http://www.mathworks.com Simulink
4.46 %MATLABROOT%\toolbox\simulink\simdemos\aerospace\f14.mdl
14 4.48
15 4.49 IS-95A
4.50
Simulink
4.47 f14.mdl
4.48 bluetooth_voice.mdl
173
174
Matlab/Simulink
4.49
tpc95.mdl
4.50 tpc95.mdl
Simulink
175
4.51 gsm_edge.mdl
:
4.52 GSM
176
Matlab/Simulink
4.53 GSM/EDGE
:
4.54 EDGE
Simulink
177
4.55 EDGE
17 4.56 IS-95A
Stateflow
178
Matlab/Simulink
4.56
IS-95A
Simulink
179
18 4.57
4.57 softdec.mdl
Real-Time Workshop
m MATLAB Compiler
C/C++MATLAB Compiler C/C++
PC UNIX
DSP FPGA VxWorks
MATLAB DSPFPGA VxWorks
Simulink Real-Time
WorkshopRTW Xilinx System GeneratorAltera DSP Builder
678
: )
: (
: )
5.1
5.1
5.1
RTW 5.2
Real-Time Workshop
181
Simulink RTW
5.2 RTW
5.2
Real-Time Workshop 5.3 Real-Time Workshop
RTW Matlab Matlab
RTW RTW Simulink
:
5.3 RTW
: (
: )
: (
: )
: (
: )
: (
: )
: (
: )
: (
: )
: (
: )
Matlab/Simulink
182
model.c
5.3 RTW
z
model.exe.exe Microsoft
exe
5.3
: (
: )
: (
: )
RTW
:
: (
: )
: (
: )
: (
: )
: (
: )
:
5.4
Real-Time Workshop
183
Real-Time Workshop
: (
: )
Matlab/Simulink
184
sf_car.a2l
*
* Real-Time Workshop code generation for Simulink model "sf_car.mdl".
*
* Model Version
: 1.132
*
* Relevant TLC Options:
* InlineParameters
=1
* RollThreshold
=5
* CodeFormat
= RealTime
*
* Simulink model settings:
* Solver
: FixedStep
* StartTime : 0.0 s
* StopTime : 30.0 s
* FixedStep : 0.04 s
*
* (add additional file header information here)
*
***************************************************************************/
ASAP2_VERSION 1 30
/begin PROJECT unspecified ""
/begin HEADER ""
/* (add HEADER definition here) */
/end HEADER
/begin MODULE unspecified ""
/begin A2ML
: on
Real-Time Workshop
185
Matlab/Simulink
186
2 UBYTE
AXIS_PTS_X
: X
FNC_VALUES
: VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup1D_BYTE
NO_AXIS_PTS_X 1 UBYTE
RESERVED
2 UBYTE
AXIS_PTS_X
FNC_VALUES
: RESERVED
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup1D_UWORD
NO_AXIS_PTS_X 1 UBYTE
RESERVED
2 UBYTE
AXIS_PTS_X
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup1D_WORD
NO_AXIS_PTS_X 1 UBYTE
RESERVED
2 UBYTE
AXIS_PTS_X
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup1D_ULONG
NO_AXIS_PTS_X 1 UBYTE
RESERVED
2 UBYTE
AXIS_PTS_X
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup1D_LONG
NO_AXIS_PTS_X 1 UBYTE
RESERVED
2 UBYTE
AXIS_PTS_X
FNC_VALUES
/end RECORD_LAYOUT
: VALUES
Real-Time Workshop
187
2 UBYTE
AXIS_PTS_X
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup1D_FLOAT64_IEEE
NO_AXIS_PTS_X 1 UBYTE
RESERVED
2 UBYTE
AXIS_PTS_X
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_UBYTE
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_BYTE
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_UWORD
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_WORD
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
/end RECORD_LAYOUT
: RESERVED
Matlab/Simulink
188
3 UBYTE
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_LONG
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_FLOAT32_IEEE
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
: RESERVED
/end RECORD_LAYOUT
/begin RECORD_LAYOUT Lookup2D_FLOAT64_IEEE
NO_AXIS_PTS_X 1 UBYTE
NO_AXIS_PTS_Y 2 UBYTE
RESERVED
3 UBYTE
FNC_VALUES
: RESERVED
/end RECORD_LAYOUT
/end MODULE
: (
: )
/end PROJECT
/* (add any file trailer comments here) */
/* EOF sf_car.a2l */
DOS4GWReal-Time Target
:
: (
: )
:
: (
: )
:
: (
: )
:
:
Real-Time Workshop
189
z HTML
RTW Embedded Coder inlinedS-
RTW Embedded Coder 5.6
MATLAB R12.1 RTW Embedded Coder 2.0
:
: (
: )
: (
: )
Visual C/C++ Project Makefile only for the RTW Embedded Coder
RTW Embedded Coder Visual C/C++
190
Matlab/Simulink
: ,
: (
: )
:
Real-Time Workshop
191
S-function Target
S-function target S- Simulink Sfunction Target Simulink C MEX S- API S-function Target
z Simulink
z
z
z
S-function Target noninlinedS- RTW Embedded
Coder RTW Embedded Coder inlinedS-
: target
: :
: target
: (
: )
: (
: )
: (
: )
TornadoVxWorksReal-Time Target
TornadoVxWorksReal-Time Target Simulink VxWorks/Tornado
: (
: )
:
xPC Target
xPC Target MathWorks PC
- xPC Target Simulink
xPC
Simulink
192
Matlab/Simulink
5.4
RTW
RTW Simulink
C6701 EVM
RTW
z
z
z
z
z
Real-Time Workshop
:
:
Real-Time
Workshop
6
6.1
TI DSP
Developers Kit for TI DSP
: (
: )
:
: (
: )
:
: (
: )
:
:
: (
: )
6.2
Matlab/Simulink
194
z DSP
z
z Simulink CCS IDE
z DSP
:
:
:
:
DSP
:
DSP
6.1
z m
z TI C5000/6000 DSP
: (
: )
TI DSP
195
z
z DSP
z TI C5000/6000 DSP
6.3
:
:
DSP
TI C5000/6000
DSP
Matlab/Simulink
196
)
MATLAB
Simulink
Developers Kit for TI DSP %MATLABROOT%\toolbox
6.2 Developers Kit for TI DSP
: ide
: (
:
: )
:
:
:
TI DSP
197
linkforccsidedemo.m
: s
% linkforccsidedemo.m
: (linkforccsdemo.
m )
% the 'Link for Code Composer Studio IDE'. A simple target DSP
% Global Commands:
visible,disp,info,isrunning,address,halt,run,restart,read, write
10
regread,regwrite,visible.
11
12
13
echo off
14
15
% ==================================================================
Matlab/Simulink
198
16
% Intro
17
disp(sprintf(['=================================================\n'
18
' The ''Link for Code Composer(tm) Studio IDE'' provides a direct\n'
19
20
21
... [1]
: ... [2]
:
:
:
... [3]
... [4]
23
24
25
26
' Before discussing the methods available with the link object,\n'
27
... [5]
28
... [6]
29
... [7]
30
... [8]
31
32
'===========================================================\n\n']));
33
34
pause;
22
35
36
% =================================================================
37
... [9]
: ... [10]
: ... [11]
:
... [12]
... [13]
... [14]
... [15]
... [16]
38
39
disp(sprintf(['=================================================\n'
40
' The ''Link for Code Composer(tm) Studio'' provides two tools for\n'
41
42
... [17]
:
... [18]
:
... [19]
43
44
45
46
'==========================================================\n\n']));
47
48
pause;
49
echo on
... [21]
:
... [22]
: ... [23]
50
ccsboardinfo
51
echo off;
53
52
% ==================================================================
54
... [20]
... [24]
... [25]
:
:
... [26]
55
56
disp(sprintf(['================================================\n'
... [27]
... [28]
:
:
... [29]
:
... [30]
:
:
... [31]
:
6
TI DSP
57
58
' Please Note the CPU that is selected in the GUI will be used\n'
59
' for the rest of this tutorial. For single processor installations,\n'
60
61
'=========================================================\n\n']));
:
:
disp('--- Press any key to continue, then select a DSP from the GUI: boardprocsel ---');
64
... [32]
:
:
... [33]
:
... [34]
:
:
62
63
199
... [35]
:
:
65
pause;
66
echo on
67
[boardNum,procNum] = boardprocsel
68
echo off
69
70
if isempty(boardNum) | isempty(procNum),
71
... [36]
:
:
... [37]
:
:
... [38]
72
' Please restart the tutorial and select a valid board and processor\n']));
73
74
else
75
76
77
' target DSP. These values are then applied during the link creation.\n\n'
78
' You selected board number = %d, and processor number = %d\n\n'],boardNum,procNum);
79
end
80
%==================================================================
81
82
disp(sprintf(['================================================\n'
83
' Next, the actual connection between the MATLAB command line and Code \n'
... [39]
... [40]
... [41]
:
:
... [42]
:
:
... [43]
84
85
' object, which for this session will be saved in variable ''cc''. The\n'
86
' link object is created with the ''ccsdsp'' command, which accepts the\n'
87
88
' properties can also be defined during the object creation; refer to\n'
89
90
' The generated ''cc'' object will be used to direct actions to the \n'
91
' designated DSP chip. Therefore, it will appear in all commands that\n'
92
:
... [46]
:
... [47]
93
94
' NOTE Before proceeding, your DSP hardware should be reset and \n'
95
:
... [48]
:
... [49]
96
'==========================================================\n\n']));
97
... [44]
... [45]
:
:
... [50]
:
:
:
... [51]
:
:
... [52]
:
... [53]
:
... [54]
... [55]
... [56]
Matlab/Simulink
200
98
99
100 pause;
101 echo on
102 cc=ccsdsp('boardnum',boardNum, 'procnum',procNum)
103 echo off
104 %==================================================================
105 % Visibility of Code Composer
106 disp(sprintf([=================================================\n'
107 ' You may have noticed Code Composer appear briefly when ''ccsdsp''\n'
108 ' was called. If Code Composer was not running before the link\n'
109 ' is established, it is started and then placed in the background.\n'
110 ' In most cases, the user will need to interact with Code Composer,\n'
111 ' so the first method that will be introduced (called ''visible'')\n'
112 ' controls the state of Code Composer on the desktop. This accepts\n
113 ' a Boolean input that makes Code Composer visible (1) or \n
114 ' invisible (0) on the desktop. For the rest of this tutorial, \n
115 ' we will need to interact with Code Composer, so we''ll use \n'
116 ' ''visible'' to bring it up to the desktop.\n'
117 '===========================================================\n\n']));
118
119 disp('--- Press any key to continue: visible ---');
:
... [60]
:
:
:
:
... [61]
: ... [62]
:
:
:
:
:
:
:
:
:
... [63]
:
120
121 pause;
122 echo on
... [59]
... [64]
... [65]
: ... [66]
:
... [67]
:
... [68]
... [69]
... [70]
... [71]
... [72]
133 ' ''isrunning'' returns the state (running or halted) of the CPU.\n'
... [73]
:
... [74]
:
... [75]
135 '===========================================================\n\n']));
:
... [76]
... [77]
137 pause;
138 echo on
... [78]
... [79]
132 ' ''disp'' prints a list of information about the target CPU.\n'
:
... [80]
:
... [81]
:
:
:
:
... [82]
6
TI DSP
139 disp(cc)
140 linkinfo = info(cc)
141 cpurunstatus = isrunning(cc)
142 echo off
201
:
... [84]
:
... [85]
:
143
144 %===================================================================
145
158 'Please note In some cases, the values reported by Code Composer\n'
160 linkinfo.family,dec2hex(linkinfo.subfamily),linkinfo.revfamily));
... [88]
... [89]
... [90]
156 ' returned by the ''info'' method, it was determined that you selected\n'
163
... [87]
161
... [86]
162 %==================================================================
... [83]
... [91]
... [92]
:
:
... [93]
:
:
:
168 ' Now that a connection has been established, the target CPU needs\n'
... [94]
:
... [95]
:
169 ' something to do! Therefore, the next step is to create executable \n'
170 ' code for the target CPU with Code Composer. For this tutorial, a\n'
171 ' Code Composer project file was written and included with MATLAB. \n'
172 ' The following set of commands will locate the tutorial project\n'
166 disp(sprintf([================================================\n
167
173 ' file and load it into Code Composer. This will use the ''open''\n'
174 ' method, which can direct Code Composer to load a project files \n'
175 ' or workspace file. (Note Code Composer has its own workspace\n'
176 ' files, which are quite different from MATLAB workspace files).\n'
177 ' Before proceeding, load a valid GEL file to configure the EMIF\n',
... [96]
... [97]
:
:
:
... [98]
178 ' registers of your DSP and perform any required initialization.\n',
179 ' The default GEL files are located in the TI directory space:\n',
... [99]
:
:
:
... [100]
:
: ... [101]
Matlab/Simulink
202
180 ' (TI)\\cc\\gel. Use menu option File->Load_GEL in Code Composer. \n',
181 ' With executable code running on the DSP, we can get down to the\n'
182 ' ultimate goal: exchanging data blocks with the target!\n'
183 '==========================================================\n\n']));
184 disp('--- Load a GEL File(if necessary), then press any key to continue: open ---');
185 pause;
186 if c5xfamily,
187 echo on
188 projfile = fullfile(matlabroot, 'toolbox', 'tiddk', 'tidemos', 'ccstutorial', 'ccstut_54xx.mak')
189 projpath = fileparts(projfile)
... [102]
... [103]
: ... [104]
: ... [105]
:
:
... [106]
190 open(cc,projfile)
191 cd(cc,projpath)
:
... [107]
:
... [108]
:
... [109]
194 echo on
198 cd(cc,projpath)
... [110]
:
... [111]
:
... [112]
:
... [113]
:
... [114]
:
... [115]
:
... [116]
:
... [117]
201 echo on
204 open(cc,projfile)
205 cd(cc,projpath)
... [118]
: ... [119]
: ... [120]
:
... [121]
: ... [122]
: ... [123]
:
: ... [124]
:
213 213 ' You should notice the tutorial''s project file in Code Composer.\n'
214 ' At this point, build the tutorial project from Code Composer.\n'
216 ' The ''Link for Code Composer'' includes methods for reading\n'
217 ' the target''s symbol table to give direct access to data in \n'
218 ' the DSP memory. Note The symbol table is only available after \n'
219 ' the program file is loaded into the DSP (and after build!).\n'
: ... [126]
:
... [127]
220 ' The next step will load the generated program file ''a.out''\n'
... [125]
TI DSP
203
221 ' using the ''load'' method. Notice the results of checking\n'
:
... [128]
222 ' the symbol table for the variable ''ddat'' before and after\n'
:
... [129]
: ... [130]
:
225 disp('--- Build the program file, then press any key to continue: load,address,dec2hex ---');
226 pause;
227 try
228 echo on
: ... [131]
:
230 address(cc, 'ddat') % Note This may (correctly) issue a warning before the executable file is loaded.
231 warning(warnState); % Reinstate warning state
232 load(cc, 'a.out',30) % Load the target execution file
233 ddatA = address(cc, 'ddat') % Now it should find the address of global value: ddat
234 dec2hex(ddatA)
: ... [132]
:
240 240 disp(sprintf(['!!!!! The load of ''a.out'' failed. Please attempt to rebuild it\n'
241 'and then manually load it from Code Composer before proceeding. \n'
242 'Then press return to attempt the load operation again\n']));
: ... [133]
: ... [134]
:
... [135]
:
... [136]
... [137]
243 pause;
244 echo on
: ... [139]
: ... [140]
: ... [141]
247 dec2hex(ddatA)
... [138]
: ... [142]
: ... [143]
: ... [144]
255 ' With the target code loaded, it is now possible to examine\n'
: ... [145]
: ... [146]
:
... [147]
256 ' and modify data values in the DSP target from MATLAB.\n'
257 ' If you look at the source file listing in the Code Composer \n'
:
... [149]
259 ' ''ccstut.c'', which was shipped with this tutorial and included\n'
:
... [150]
:
... [151]
260 ' in the project. It has two global data arrays: ''ddat'' and \n'
261 ' ''idat''. They are declared and initialized in lines 10 and 11.\n'
... [148]
Matlab/Simulink
204
263 ' MATLAB command line using the ''read'' and ''write'' methods.\n'
: ... [152]
:
... [153]
264 ' To control target execution use the ''run'', ''halt'' and\n'
262 ' These DSP memory arrays can be accessed directly from\n'
... [154]
269 disp('--- Insert Breakpoint then press any key to continue: halt,restart,read ---');
:
... [155]
270 pause;
: ... [156]
:
... [157]
271 try
272 if c5xfamily,
: ... [158]
:
273 echo on
274 halt(cc)
275 restart(cc)
277
278 ddatV = read(cc,address(cc, 'ddat'), 'single',4) % Should equal initialized value from C-Code
:
:
: ... [159]
:
279
280 idatV = read(cc,address(cc, 'idat'), 'int16',4)
:
... [160]
281
:
... [161]
: ... [162]
:
285
286 run(cc, 'runtohalt',20);
287
288 ddatV = read(cc,address(cc, 'ddat'), 'single',4)
289
: ... [163]
: ... [164]
:
:
... [165]
292 restart(cc);
:
... [166]
297 restart(cc)
299
300 ddatV = read(cc,address(cc, 'ddat'), 'double',4) % Should equal initialized value from C-Code
301
: ... [167]
:
:
... [168]
:
TI DSP
309
310 ddatV = read(cc,address(cc, 'ddat'), 'double',4)
311
205
:
... [169]
: ... [170]
:
... [171]
: ... [172]
: ... [173]
:
... [174]
:
... [175]
:
... [176]
:
:
... [177]
313
314 restart(cc);
315
316 echo off
: ... [179]
:
317 end
318 catch
... [178]
... [180]
:
:
... [181]
:
:
325 'In some cases, resetting the board before running the tutorial may be\n'
: ... [183]
: ... [184]
:
... [182]
: ... [185]
: ... [186]
:
:
... [187]
336 ' For Assembly language programmers, there are also methods\n'
:
... [188]
:
... [189]
337 ' to directly access CPU registers. For the c5xxx family, most\n'.
338 ' registers are memory-mapped and consequently are available using \n'
339 ' standard memory read/write methods. However, the ''PC'' register\n'
340 ' is not memory-mapped and therefore requires a special pair of \n'
:
... [191]
335 disp(sprintf([================================================\n'
342 '==========================================================\n\n']));
... [190]
: ... [192]
Matlab/Simulink
206
: ... [193]
344 pause;
345 echo on
346 cc.regread('PC', 'binary')
:
... [194]
:
... [195]
: ... [196]
: ... [197]
:
... [198]
: ... [199]
: ... [200]
356 echo on
357 tReg = cc.regread('A0', '2scomp') % 2's complement version of A0
:
... [201]
:
... [202]
% Unsigned version of B2
:
... [203]
: ... [204]
: ... [205]
:
... [206]
: ... [207]
: ... [208]
: ... [209]
: ... [210]
:
... [211]
: ... [212]
: ... [213]
:
378 pause;
: ... [214]
379 echo on
380 clear cc
: echo off
:
6
z
z
z
TI DSP
207
13 MATLAB
49 MATLAB
50 Code Composer Setup
>> ccsboardinfo
Board Board
Proc Processor
Num Name
Num Name
Processor
Type
--- ------ --- ---------------------------- -------------1 C64xx Simulator (Texas Instrum ... 0 CPU
TMS320C6400
TMS320C6200
CPU_1
67
6.4
boardNum =
1
procNum =
0
6.4
6.4
z
z
70~79
102 MATLAB CCSDSP cc MATLAB
Code Composer StudioLink for CCS
IDE CCSDSP
:
:
:
Matlab/Simulink
208
>> cc=ccsdsp('boardnum',boardNum,'procnum',procNum)
CCSDSP Object:
API version
: 1.0
: No
:1
Processor number : 0
Default timeout
: 10.00 secs
>> cc.visible(1)
6.5
6.5
z
cc.visible(1)
139
>> disp(cc)
CCSDSP Object:
6
API version
: 1.0
Processor type
: TMS320C64127
Processor name
: CPU
Running?
: No
Board number
:1
TI DSP
209
Processor number : 0
Default timeout
: 10.00 secs
140
:
timeout: 10
6.1
animate
ccsboardinfo
CCS IDE
ccsdsp
CCS IDE
cd
CCS IDE
clear
CCS IDE
CCS IDE
dir
disp
CCS IDE
display
CCS IDE
get
CCS IDE
halt
info
isreadable
CCS IDE PC
isvisible
MATLAB
(*.out*.obj)
load
open
MATLAB
isrunning
iswritable
CCS IDE
6.5 cc.visible(1)
: linkinfo =
info(cc)
Matlab/Simulink
210
read
TI DSP
211
regread
regwrite
reset
restart
run
set
CCS IDE
symbol
CCS IDE
visible
CCS IDE
write
141 0 1
cpurunstatus = isrunning(cc)
cpurunstatus =
0
z
z
:
:
:
:
linkinfo.family,dec2hex(linkinfo.subfamily),linkinfo.revfamily));
From the 'subfamily' and 'revfamily' members of the structure
returned by the 'info' method, it was determined that you selected
a TMS320C64127 DSP processor.
Please note - In some cases, the values reported by Code Composer
do not match the physical device numbering scheme.
z
:
:
:
Matlab/Simulink
212
>>dec2hex(ddatA)
ans =
80000010
00000000
6.6
z
ccstut_6x11.mak
271~329 6.6 3
ddat 4 MATLAB ddatV idat 4
MATLAB idatV ddat 4
double([pi 12.3 exp(-1) sin(pi/4)] idat 4 int32([1:4])
:
:
:
: (
: )
TI DSP
213
ddat 4
MATLAB ddatV idat 4
MATLAB idatV DSP
>> halt(cc)
restart(cc)
run(cc,'runtohalt',20);
ddatV = read(cc,address(cc,'ddat'),'double',4)
idatV = read(cc,address(cc,'idat'),'int32',4)
write(cc,address(cc,'ddat'),double([pi 12.3 exp(-1) sin(pi/4)]))
write(cc,address(cc,'idat'),int32([1:4]))
run(cc,'runtohalt',20);
ddatV = read(cc,address(cc,'ddat'),'double',4)
idatV = read(cc,address(cc,'idat'),'int32',4)
restart(cc);
ddatV =
16.3000 -2.1300 5.1000 11.8000
idatV =
1
508
647
7000
ddatV =
3.1416 12.3000 0.3679 0.7071
idatV =
1
z
333~361
tReg = cc.regread('A0','2scomp') A0
Matlab/Simulink
214
cc.regread('B2','binary') B2
>>cc.regread('B2','binary')
ans =
1
z
z
cc.regwrite('A2',tReg,'2scomp') A2 tReg
cc.regread('PC','binary')
cc.regwrite('PC',hex2dec('100'),'binary') 256
:
: (
:
: )
:
: (
: linkforrtdxde
mo.m
:
:
: )
:
:
:
:
%linkforrtdxdemo.m
% LINKFORRTDXDEMO is an example script intended to get the user started with the
% Link for RTDX. A simple target DSP application is loaded and run on the
% target DSP, and data messages are transfered via RTDX between the host
% application (MATLAB) and the target DSP. The tutorial writes integers 1:10
% to the target DSP. The target DSP takes the array of integers and
% increments it by 1 and writes the resultant array to the host. This action
% previous array result by one. The 20 messages are read by the script using
10
11
:
:
:
:
:
:
TI DSP
215
12
13
14
disp(sprintf(['You will need to select a board and processor using the '...
15
16
pause;
:
:
17
18
[boardNum,procNum] = boardprocsel;
19
echo on
20
cc=ccsdsp('boardnum',boardNum,'procnum',procNum)
21
echo off
22
23
24
% =================================================================
25
count = 0;
26
notReady = 1;
27
28
29
30
if cc.isrtdxcapable,
if (cc.info.subfamily >= hex2dec('50')) & ...
(cc.info.subfamily <= hex2dec('5f')),
31
c5x = logical(1);
32
target_subdir = 'c5x';
33
outFile = 'rtdxtutorial_5x.out';
34
notReady = 0;
35
% GEL reset
36
37
pause
38
uiwait(msgbox({'For the C54xx, you may need to manually load c5000.gel ';...
39
40
41
42
c5x = logical(0);
44
46
47
48
49
50
51
43
45
target_subdir = 'c6x';
outFile = 'rtdxtutorial_6x1x.out';
else
target_subdir = 'c6x';
outFile = 'rtdxtutorial_6x0x.out';
end
notReady = 0;
52
53
Matlab/Simulink
216
:
54
55
'Selection Error','modal'));
56
count = count+1;
57
if count<2,
58
clear cc;
59
[boardNum,procNum] = boardprocsel;
60
pause(0.1);
61
echo on;
62
cc=ccsdsp('boardnum',boardNum,'procnum',procNum);
63
echo off;
64
end
65
66
end
else % Selected processor is a Simulator
67
68
69
'Selection Error','modal'));
70
count = count+1;
71
if count<2,
72
clear cc;
73
[boardNum,procNum] = boardprocsel;
74
pause(0.1);
75
echo on;
76
cc=ccsdsp('boardnum',boardNum,'procnum',procNum);
77
echo off;
78
79
:
uiwait(msgbox({'RTDX is not
supported for the
selected board, ';
end
end
80
end
81
if ~exist('outFile'),
82
clear cc;
83
error('RTDX is not supported for the selected board. Exiting tutorial ...');
84
end
85
%===================================================================
86
87
88
echo on;
: =
89
90
91
92
93
94
% Go to target directory
6
95
TI DSP
cc.cd(target_dir);
96
97
98
cc.dir;
99
100 % make Code Composer IDE visible
101 cc.visible(1);
102
103 % LOAD .out file to target
104 cc.load(outFile);
105
106 %===================================================================
107 echo off
108 disp('Hit any key to continue...');
109 pause
110 echo on
111
112 % CONFIGURE channel buffers, 4 buffers of 1024 bytes each
113 cc.rtdx.configure(1024,4);
114
115 % OPEN write channel
116 cc.rtdx.open('ichan','w');
117
118 % OPEN read channel
119 cc.rtdx.open('ochan','r');
120
121 % ENABLE RTDX, and verify, for C54x
122 cc.rtdx.enable;
123 cc.rtdx.isenabled
124
125 %===================================================================
126 echo off
127 disp('Hit any key to continue...');
128 pause
129 echo on
130
131 % SET global timeout value, and verify
132 timeout = cc.rtdx.get('timeout')
133 cc.rtdx.set('timeout', 15)
217
Matlab/Simulink
218
disp('writing to target...')
159
indata=1:10
10 1:10
160
cc.rtdx.writemsg('ichan', int16(indata))
161 end
162
163 %==================================================================
164 echo off
165 disp('Hit any key to continue...');
166 pause
167 echo on
168
169 % Check enable status of read channel
170 cc.rtdx.isenabled('ochan')
171
172 % Query for number of available messages -- should be 0
173 num_of_msgs = cc.rtdx.msgcount('ochan')
174
175 % ENABLE read channel, and verify
176 cc.rtdx.enable('ochan');
TI DSP
177 cc.rtdx.isenabled('ochan')
178
179 % give time for target DSP to process data,
180 % and write results to channel buffer
181 pause(4);
182
183 %===================================================================
184 echo off
185 disp('Hit any key to continue...');
186 pause
187 echo on
188
189 % Query for number of available messages -- should be 20
190 num_of_msgs = cc.rtdx.msgcount('ochan')
191
192 % Read one message:
193 outdata = cc.rtdx.readmsg('ochan', 'int16')
194
195 % Read three messages into a cell array of three 1x10 vectors:
196 outdata = cc.rtdx.readmsg('ochan', 'int16', 3)
197 % Look at second matrix--de-reference cell array:
198 outdata{1,2}
199
200 %===================================================================
201 echo off
202 disp('Hit any key to continue...');
203 pause
204 echo on
205
206 % Read two messages into two 2x5 matrices:
207 outdata = cc.rtdx.readmsg('ochan', 'int16', [2 5], 2)
208
209 % Look at both matrices by de-referencing cell array:
210 outdata{1,:}
211
212 % Read one message into one 10x1 column vector:
213 outdata = cc.rtdx.readmsg('ochan', 'int16', [10 1])
214
215 %===================================================================
216 echo off
217 disp('Hit any key to continue...');
218 pause
219
Matlab/Simulink
220
219 echo on
220
221 % READMAT
: % Query for
remaining number of available
messages in read channel
queue...
TI DSP
221
278 cc.halt;
279 end
280
281 % DISABLE RTDX
282 cc.rtdx.disable;
283
284 % CLOSE channels
285 cc.rtdx.close('ichan');
286 cc.rtdx.close('ochan');
287 % or use: cc.rtdx.close('all');
288
289 if cc.isvisible,
290 cc.visible(0);
291 end
292
293 clear cc; % Call destructors
294 echo off;
295
296 % ======================= END OF DEMONSTRATION=====================
297
298 % [EOF] linkforrtdxdemo.m
z 18
C6701 EVM
Matlab/Simulink
222
z
z
z
z
z
z
z
z
z
z
172~173 0
175~177
6.2 Link for RTDX
address
clear
:
: ( 1
: )
: (
: 1 )
:
:
: (
:
%MATLABROOT%\toolbox\t
iddk\tidemos\rtdxtutorial\c6x\
rtdxtutorial_
:
: 6x0x.out)
:
: (
:
Matlab
Link for RTDX
Matlab TI
DSP Matlab
TI DSP
)
: (
: C54X)
:
close
RTDX
configure
RTDX
:
:
:
:
TI DSP
223
disable
disp
RTDX
display
RTDX
RTDX RTDX RTDX
enable
RTDX
flush
get
RTDX
info
RTDX
isreadable
MATLAB RTDX
iswritable
MATLAB RTDX
RTDX RTDX
isenabled
msgcout
RTDX
open
RTDX
readmat
RTDX
RTDX
readmsg
set
writemsg
RTDX
/* RTDX tutorial target application: read from host and echo back */
#include <rtdx.h>
/* RTDX_Data_Read*/
#include <stdio.h>
/* printf
#include <target.h>
/*TARGET_INITIALIZE*/
*/
#define MAX 10
short recvd[MAX];
RTDX_CreateInputChannel(ichan);
RTDX_CreateOutputChannel(ochan);
while ( !RTDX_isInputEnabled(&ichan) )
{/* wait for channel enable from MATLAB */}
RTDX_read( &ichan, recvd, sizeof(recvd) );
10 1:10
:
:
Matlab/Simulink
224
20
while (1) {}
}
z
z
189~190 20
192~193
:
:
9 10 11
195~198 3
:
:
>>outdata{1,2}
ans =
4
z
9 10 11 12 13
206~210
[25 int16]
TI DSP
212~213
225
222~223 52
:
: (
: )
outdata =
9
14
10
15
11
16
12
17
13
18
z
z
225~226 12
228~229 45
:
:
: (
: )
outdata =
10
14
18
13
17
11
15
19
14
18
12
16
11
15
19
13
17
12
16
20
:
z
z
231~233 10
241~242 105
:
: (
: )
Matlab/Simulink
226
:
>>outdata = cc.rtdx.readmat('ochan', 'int16',[4 5] )
outdata =
12
13
14
15
16
13
14
15
16
17
14
15
16
17
18
15
16
17
18
19
16
17
18
19
20
17
18
19
20
21
18
19
20
21
22
19
20
21
22
23
20
21
22
23
24
21
22
23
24
25
z
z
z
z
z
z
z
z
z
z
z
244~246 5
254~255
257~259 4
261~262
264~266 0
274~275 RTDX
277~279
281~282 RTDX
284~287 RTDX
289~291 CCS IDE
293 CCSDSP CCS IDE CCS IDE
CCSDSP
:
:
:
:
:
:
:
:
:
:
TI DSP
6.7
227
C6701 EVM
:
: (
: )
: (
: )
: (
: )
: 0.2sin(2
... [215]
: *
228
Matlab/Simulink
:
: pi
:
: 500
: *
: *
: t)
... [216]
: 0.2sin(2
: *
:
6.8 C6701 EVM
: pi
:
: *
: 1000
: *
: t)
6.9
lfilterwithsimulink.mdl
:
:
... [217]
... [218]
... [219]
: 0.2sin(2
: *
:
: pi
:
: *
: 500
: *
6.10
y1=0.2sin(2*pi*500*t)
: t)
TI DSP
229
:
6.11
: *pi
y2=0.2sin(2*pi*500*t)
: 0.2sin(2
:
: *
: 1000
: *
: t)
230
Matlab/Simulink
6.13
: (
: )
6.14 lfilterwithsimulink.mdl
:
: (
: )
: (
: )
:
:
: (
: )
TI DSP
6.15 lfilterwithc6701.mdl
231
232
Matlab/Simulink
lfilterwithc6701.mdl
1. 6.18 Solver Real-Time Workshop
:
: )
: (
:
6.18
:
: (
: )
: 6.29
TI DSP
233
6.21
TLC debugging
Matlab/Simulink
234
:
: (
:
: cont.
: )
:
6.23
: 6.23
:
:
:
TI DSP
6.25
6.26
235
TI C6701 compiler
TI C6701 linker
: (
: )
:
:
:
236
Matlab/Simulink
: (
: )
:
:
: (
: )
: (
: )
:
6.27
TI DSP
237
: *
: *
: sin(2
:
:
: pi
: 500
6.29
: *
: t)
: 6.29
: (
>> daqfcngen
: )
: (
: 2
: *
:
: pi
6.30
y=sin(2*pi*500*t)
daqfcngen %MATLABROOT%\
toolbox\daq\daqdemos\daqfcngen.m daqfcngen Line Out
6.31 Start Start
Stop y1=0.2sin(2*pi*500*t)
:
: *
: 500
: *
: t)
: 0.2sin(2
: *
:
: pi
:
Matlab/Simulink
238
... [220]
: *
: 500
: *
: t)
: 6.30
:
: () ... [221]
: 0.2sin(2
: *
6.31
y1=0.2sin(2*pi*500*t)
:
: pi
:
: *
: 1000
: *
: t)
... [222]
... [223]
: 0.2sin(2
: *
:
: pi
6.32
y2=0.2sin(2*pi*1000*t)
daqscope %MATLABROOT%\toolbox\daq\
daqdemos\daqscope.m daqscope Line In 6.33
6.34
500Hzf=7.344100/644.714=499.34 1000Hz
:
: *
: 1000
: *
: t)
... [224]
: sin(2
: *
:
: pi
:
: *
: 500
: *
: t)
: sin(2
: *
:
: pi
:
: *
... [225]
... [226]
TI DSP
6.33
239
6.34 500Hz
Matlab/Simulink
240
>> which daqfcngen
D:\MATLAB6p1\toolbox\daq\daqdemos\daqfcngen.m
>> help daqfcngen
DAQFCNGEN Example function generator for the Data Acquisition Toolbox.
DAQFCNGEN creates a function generator window which can be used with
the Data Acquisition Toolbox's analog output objects.
The function generator window is divided into three sections.
The top section contains a popup menu which displays the analog output
:
:
:
:
values are not entered, the default values displayed are used.
The right section consists of three buttons which start/stop the
selected analog output object, reset the function generator window
to its original state and close the function generator window.
The selected waveform can be sent to multiple channels of the same
analog output object. Channels of the same object cannot be connected
to different waveforms.
Information on DAQFCNGEN and the Data Acquisition Toolbox are
available through the Help menu.
The daqfcngen window can be closed either by selecting the File menu
:
:
:
TI DSP
241
:
:
:
:
:
device identification number and the selected channels. When the button
with the triangle image is selected, the created analog input object is
started with the start command and the selected channels' signal will
be displayed in the daqscope axes. While the analog input object is
The time range or x-axis range can be modified while the object is
running by moving the X-Axis range slider. The volts per division (or
channel signals plotted by selecting the View menu and then selecting
the Legend menu.
:
:
Matlab/Simulink
242
The daqscope window can be closed either by selecting the File menu
and then selecting the Close Oscilloscope menu or by selecting the
"x" close button. When the daqscope window is closed, the analog
input object will be stopped, if it is running, and deleted.
See also DAQFCNGEN.
Xilinx FPGA
:
: w
: <#>
<#>
:
MathWorks Xilinx
Simulink FPGA System Generator for Simulink
Simulink MatlabMathWorks FGPA
z
Simulink DSP
z
System Generator for Simulink Simulink Xilinx FPGA
VHDL
z
Xilinx IP
: <#>
: <#>
: <#>
<#>
<#> System Generator for
Simulink Simulink
Xilinx FPGA
VHDL
: <#>
: <#>
7.1
FPGA
:
:
7.1
FPGA
Xilinx FPGA
243
:
: System
Generator for Simulink
:
7.2
Xilinx Blockset
:
:
:
:
Matlab/Simulink
244
: (
: )
Xilinx Blockset
z
Basic Elements 7.4
:
: (
: )
:
:
Word
7.4 Basic Elements
z
: (
: )
Xilinx FPGA
245
Math 7.6
: (
: )
7.6 Math
z
z
Memory 7.7
Matlab IO 7.8
: (
: )
: (
: )
246
Matlab/Simulink
7.7 Memory
:
: ()
7.8 Matlab IO
... [1]
:
Word
: ()
... [2]
Xilinx FPGA
247
7.3
: (
: )
: (
: )
:
: (
: )
VHDL
:
7.10 firandmac.mdl(
)
: Xilinx Blockset
FIR
:
:
Xilinx Blockset
FIR
:
:
:
:
:
248
Matlab/Simulink
7.10 firandmac.mdl
7.11
Din Gateway In
: (
: )
Xilinx FPGA
7.12
249
FIR
:
: (
: )
: (
: )
250
Matlab/Simulink
7.16 Controller
:
7.17 MAC
Xilinx FPGA
251
7.18 firandmac.mdl
7.19 firandmac.mdl
: ,
Matlab/Simulink
252
7.20
Virtex
Spartan-II
Target Directory
Create Testbench
VHDL
: /
: /
: /
: /
Xilinx FPGA
253
FPGA
FPGA
Everywhere in Subsystem
Simulink FPGA
Nowhere in Subsystem
Simulink FPGA
Generate Cores
VHDL Xilinx LogiCOREs
According to Block Masks
Xilinx LogiCOREs
Everywhere Available
Xilinx LogiCOREs
Nowhere
Xilinx LogiCOREs
7.21
: (
: )
: (
: )
:
: (
: )
:
:
Matlab/Simulink
254
7.21
Xilinx FPGA
255
xlfir.vhd
xlfir_core1.vhd
const_pkg.vhd
clock_driver.vhd
xlmult.vhd
xlcounter_core1.vhd
xlspram_core1.vhd
xlmult_core1.vhd
xlsprom_core1.vhd
xlrelational.vhd
xlspram.vhd
xlsprom.vhd
xlfir_core1.vho
xlspram_core1.vho
xlcounter_core1.vho
xlmult_core1.vho
xlsprom_core1.vho
xlfir_core1.xco
sysgen.xco
xlmult_core1.xco
xlcounter_core1.xco
xlsprom_core1.xco
xlspram_core1.xco
vhdlFiles
const_pkg.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/conv_pkg.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/synth_reg.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/synth_reg_w_init.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/synth_valid_pipe.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/synth_mult.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlshutter.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xldelay.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlfromfile.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlregister.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlclockdriver.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xldsamp.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlconstant.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xltofile.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlusamp.vhd
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xladdsub.vhd
: 7.17
Matlab/Simulink
256
C:/matlabR12/toolbox/xilinx/sysgen/vhdl/xlclk.vhd
clock_driver.vhd
xlspram_core1.vhd
xlcounter_core1.vhd
xlmult_core1.vhd
xlfir_core1.vhd
xlsprom_core1.vhd
xlcounter.vhd
xlspram.vhd
xlfir.vhd
xlsprom.vhd
xlrelational.vhd
xlmult.vhd
firandmac_MAC_Based_FIR_MAC.vhd
firandmac_MAC_Based_FIR_Controller.vhd
firandmac_MAC_Based_FIR.vhd
firandmac.vhd
firandmac_testbench.vhd
7.4
: 7.10
:
: (
: )
: (
: )
:
:
7.5
MathWorks Xilinx
C MathWorks Simulink
Xilinx FPGA
257
:
: (
: )
: (
: )
:
VxWorks
8.1
VxWorks/Tornado
UNIX Windows
Tornado WindRiver
VxWorks Tornado
VxWorks 1800 API
VxWorks RTOS Wind
I/O C++
VxWorks WindRiver Tornado 300
MathWorks Simulink VxWorks
Tornado VxWorks Real-Time TargetTornado VxWorks
VxWorks/Tornado WindRiver
http://www.windriver.com
8.2
: (
: )
: (
: )
:
Simulink VxWorks
: (
: )
:
: (
: )
VxWorks
259
8.1 VxWorks
z
z
z
z
z
Matrix MS-AD12
Matrix MS-DA12
VME Microsystems VMIVM-3115-1
Xycom XVME-500/590
Xycom XVME-505/595
260
Matlab/Simulink
8.3
8.3
IO Devices
VxWorks 8.4
MatlabSimulink Real-Time Workshop UNIX/PC VxWorks
Ethernet A/DD/A IO
:
Visio
: (
8.4 VxWorks
: )
:
: (
: )
:
: (
: )
:
: (
: )
:
VxWorks
261
: (
: )
:
:
:
: (
: )
8.5
z Simulink
Simulink Simulink
MEX- Windows ext_com.dll VxWorks
z StethoScope
VxWorks StethoScope
: (
: )
: (
: )
VxWorks
: (
: )
262
Matlab/Simulink
Solver 8.6
8.6
%MATLABROOT%\rtw\c\tornado\rt_main.c
TornadoVxWorksReal-Time Target rt_main.c
z
tSingleRate
tSingleRate
tSingleRate VxWorks semTake
semGive semTake
tSingleRate semTake
tSingleRate 30
8.5
tBaseRate
30
tRaten ()
tRate1tRate2tRaten
tRate1 tRaten
tRate1 tBaseRate
:
: (
: )
:
:
: (
: )
: (
: )
: (
: )
:
: (
: )
: (
: )
:
:
: (
: )
VxWorks
263
TornadoVxWorksReal-Time Target
StethoScope 8.5
tExtern -
Simulink tExtern Simulink
tExtern tExtern
tRaten()
tExtern %MATLABROOT%\rtw\c\src\ext_svr.c
tScopeDaemon and tScopeLink StethoScop VxWorks
tSingleRate
tBaseRate
StethoScope
: (
: )
:
: (
: )
:
:
:
: (
: )
8.4
Tornado(VxWorks)Real-Time Target
1 Simulink
2 Simulink
3 makefile tornado.tmf
4 Simulink VxWorks Ethernet Simulink
VxWorks Ethernet Simulink
: (
: )
: (
: )
:
Simulink
Simulink Simulink
:
Matlab/Simulink
264
VxWorks IO
IO
Simulink C S-
Real-Time Workshop C
TLC S-
C S-
IO MATLAB Document PDF
rtw_ug.pdf Targeting Real-Time Systems
8.7 VxWorks
makefile
VxWorks makefile tornado.tmf Real-Time Workshop
VxWorks tornado.tmf
VxWorks
265
VxWorks
CPU
CPU CPU VxWorks
CPU VxWorks
CPU tornado.tmf
z
Tornado Target
Server
z
Matlab/Simulink
266
TGTSVR_HOST = hostname
Tornado
makefile tornado.tmf 3
z
Simulink
makefile
z
Solver 8.9 Real-Time
Workshop 8.10
: (
: )
: (
: )
8.9
Solver
Solver Fixed-step
discrete no continuous status
: (
: )
VxWorks
267
8.10
Real-Time Workshop
: (
: )
Matlab/Simulink
268
TornadoVxWorksReal-Time Target
Real-Time Workshop Tornado code generation options
8.12
8.12
: (
: )
:
Real-Time Workshop
TornadoVxWorksReal-Time Target
MAT-file logging
model.mat
Workspace I/O Real-Time Workshop
MAT-file variable name modifier
VxWorks
VxWorks
Make command OPTS
"-DSAVEFILE=filename"
make_rtw OPTS="-DSAVEFILE=filename"
External mode Simulink
Make command OPTS="-DVERBOSE"
verbose VxWorks
: (
: )
:
: :
: :
VxWorks
269
perl %MATLABROOT%\rtw\c\
tornado\downld.pl
StethoScope(StethoScope) StethoScope
libxdr.solibutilstssip.so libscope.so VxWorks
StethoScope
: (
: )
: (
: )
:
: (
: )
:
: (
:
: )
TornadoVxWorksReal-Time Target
Tornado
z VxWorks
VxWorks
Target Server VxWorks Target Agent
Tornado DOS DOS
: (
: )
:
: (
: )
: (
: )
: (
tgtsvr target_network_name
VxWorks
Tornado DOS Tornado WindSh
WindSh
z
ld <model.lo
StethoScope
StethoScope libxdr.solibutilstssip.so libscope.so
z
VxWorks rt_main
Simulink StethoScope
StethoScope rt_main rt_main.c
%MATLABROOT%\rtw\c\tornado
/* Function: rt_main ===========================================================
* Abstract:
: )
: /* Function:
rt_main
======================
======================
=======
* Abstract:
* Initialize the Simulink
model pointed to by
"model_name" and start
* model execution.
*
* This routine spawns a task
to execute the passed model. It
will
* optionally initialize
StethoScope (via
ScopeInitServer), if it
* hasn't already been done. It
also optionally sets up external
mode
* communications channels
to Simulink.
*
* Parameters:
... [1]
Matlab/Simulink
270
*
*
for example, "-tf 20 -w" instructs the target program to use a stop time
before starting the "simulation". Note that -tf inf sets the stop time to
infinity.
*
* "scopeInstallString" determines which signals will be installed to
* StethoScope. If scopeInstallString is NULL (the default) no signals
* are installed. If it is "*", then all signals are installed. If it
* is "[A-Z]*", signals coming from blocks whose names start with capital
* letters will be installed. If it is any other string, then signals
* starting with that string are installed.
*
* "scopeFullNames" parameter determines how signals are named: if
* 0, the block names are used, if 1, then the full hierarchical
* name is used.
*
* "priority" is the priority at which the model's highest priority task
* will run. Other model tasks will run at successively lower priorities
* (i.e., high priority numbers).
*
* Example:
* To run the equalizer example from windsh, with printing of external mode
* information, use:
*
*
*
VxWorks
* Returns:
* EXIT_SUCCESS on success.
* EXIT_FAILURE on failure.
*/
int_T rt_main(
SimStruct * (*model_name)(void),
char_T
*optStr,
char_T
*scopeInstallString,
int_T
scopeFullNames,
int_T
priority,
int_T
port)
{
const char *status;
int_T
int
VxWorksTIDs[NUMST];
optStrLen
SEM_ID
int_T
parseError
double
int
= strlen(optStr);
rtClockSem
finaltime
argc
char_T
= NULL;
= FALSE;
= -2.0;
= 0;
**argv
= NULL;
#ifdef MULTITASKING
SEM_ID
int_T
rtTaskSemaphoreList[NUMST];
i;
#endif
#ifdef EXT_MODE
int_T
extern_msg_tid;
int_T
extern_upload_tid;
#endif
/*
* Do error checking on input args and parse the options string.
*/
if (model_name == NULL) {
parseError = TRUE;
goto PARSE_EXIT;
}
/*
* Parse option string.
*/
271
Matlab/Simulink
272
count;
char_T *thisStr;
char_T *nextStr;
/*
* Convert to lower case.
*/
for (i=0; i<optStrLen; i++) {
optStr[i] = tolower(optStr[i]);
}
/*
* Convert error string to standard argc and argv format.
*/
/* count strings and allocate an argv */
argc = CountStrs(optStr) + 1;
argv = (char **)calloc(argc,sizeof(char *));
if (argv == NULL) {
(void)fprintf(stderr,
"Memory allocation error while parsing options string.");
exit(EXIT_FAILURE);
}
/* populate argv & terminate the individual substrings */
argv[0] = "dummyProgramName";
i=1;
nextStr = optStr;
while ((nextStr != NULL) && (thisStr = GetNextStr(nextStr, &nextStr)) != NULL && ( i < argc )) {
argv[i] = thisStr;
i++;
}
/*
* Parse the standard RTW parameters. Let all unrecognized parameters
* pass through to external mode for parsing. NULL out all args handled
* so that the external mode parsing can ignore them.
*/
count = 1;
VxWorks
tmpstr[2];
char_T
str2[200];
double
tmpDouble;
273
Matlab/Simulink
274
printf("\t%s",extParseErrorMsg);
parseError = TRUE;
goto PARSE_EXIT;
}
}
#endif
/*
* Check for unprocessed ("unhandled") args.
*/
{
int i;
for (i=1; i<argc; i++) {
if (argv[i] != NULL) {
if (strcmp(argv[i], "-w") == 0) {
printf("Ignoring command line argument: '-w'\n'-w' only applies to external mode.\n");
continue;
} else {
printf("Unexpected command line argument: %s\n Exiting\n",argv[i]);
parseError = TRUE;
goto PARSE_EXIT;
}
}
}
}
PARSE_EXIT:
free(argv);
argv = NULL;
if (parseError) {
exit(EXIT_FAILURE);
}
}
if (priority <= 0 || priority > 255-(NUMST)+1) {
priority = BASE_PRIORITY;
}
/************************
* Initialize the model *
************************/
VxWorks
rt_InitInfAndNaN(sizeof(real_T));
S = model_name();
if (S == NULL) {
(void)fprintf(stderr,"Memory allocation error during model "
"registration");
exit(EXIT_FAILURE);
}
if (ssGetErrorStatus(S) != NULL) {
(void)fprintf(stderr,"Error during model registration: %s\n",
ssGetErrorStatus(S));
TERMINATE(S);
exit(EXIT_FAILURE);
}
if (finaltime >= 0.0 || finaltime == RUN_FOREVER) {
ssSetTFinal(S, (real_T)finaltime);
}
INITIALIZE_SIZES(S);
INITIALIZE_SAMPLE_TIMES(S);
if ((status=rt_InitTimingEngine(S)) != NULL) {
fprintf(stderr,
"Failed to initialize sample time engine: %s\n", status);
exit(EXIT_FAILURE);
}
rt_CreateIntegrationData(S);
#if defined(RT_MALLOC) && NCSTATES > 0
if(ssGetErrorStatus(S) != NULL) {
fprintf(stderr, "Error creating integration data.\n");
rt_DestroyIntegrationData(S);
TERMINATE(S);
exit(EXIT_FAILURE);
}
#endif
#ifdef MAT_FILE
if (rt_StartDataLogging(S) != NULL) {
fprintf(stderr,"Error starting data logging.\n");
return(EXIT_FAILURE);
}
#endif
275
Matlab/Simulink
276
VxWorks
277
Matlab/Simulink
278
semTake(startStopSem, WAIT_FOREVER);
/********************
* Cleanup and exit *
********************/
printf("\nSimulation Finished\n");
sysAuxClkDisable();
taskDelete(VxWorksTIDs[0]);
semDelete(rtClockSem);
semDelete(startStopSem);
#ifdef EXT_MODE
taskDelete(extern_msg_tid);
taskDelete(extern_upload_tid);
rt_ExtModeShutdown();
semDelete(uploadSem);
#endif
#ifdef STETHOSCOPE
rtInstallRemoveSignals(S, scopeInstallString,scopeFullNames,0);
#endif
#ifdef MULTITASKING
for (i = FIRST_TID + 1; i < NUMST; i++) {
taskDelete(VxWorksTIDs[i]);
semDelete(rtTaskSemaphoreList[i]);
}
#endif
TERMINATE:
#ifdef MAT_FILE
rt_StopDataLogging(MATFILE,S);
#endif
#if defined(RT_MALLOC) && NCSTATES > 0
rt_DestroyIntegrationData(S);
#endif
TERMINATE(S);
VxWorks
279
return(EXIT_SUCCESS);
} /* end rt_main */
rt_main6
: in */
int_T rt_main(
SimStruct * (*model_name)(void),
char_T
char_T
int_T
*optStr,
*scopeInstallString,
scopeFullNames,
int_T
priority,
int_T
port)
model_name
Simulink
SimStruct
z
optStr
-tf
Simulink -w-tf 20 -w 20
Simulink
z
scopeInstallString
StethoScope
NULL
*
[A-Z]*
scopeFullName
StethoScope
1
0
S-
: (
: )
: (
: )
:
:
:
:
priority
tBaseRate
:
:
port
TCP 256~65535 17725
tornado.tmf PROGRAM_OPTS-w -tf rt_main
: (
: )
:
:
Matlab/Simulink
280
WindShrt_main
model
20
StethoScope
30 tBaseRate
TCP 17725
: (
: )
269:
[1]
fcr
2002-9-17 15:32:00
*
*
*
* "scopeInstallString" determines which signals will be installed to
* StethoScope. If scopeInstallString is NULL (the default) no signals
* are installed. If it is "*", then all signals are installed. If it
* is "[A-Z]*", signals coming from blocks whose names start with
* capital letters will be installed. If it is any other string, then
* signals starting with that string are installed.
*
* "scopeFullNames" parameter determines how signals are named: if
* 0, the block names are used, if 1, then the full hierarchical
* name is used.
*
* "priority" is the priority at which the model's highest priority
* task will run. Other model tasks will run at successively lower
* priorities (i.e., high priority numbers).
*
* Example:
* To run the equalizer example from windsh, with printing of external
* mode information, use:
*
*
*
* Returns:
* EXIT_SUCCESS on success.
* EXIT_FAILURE on failure.
*/
int_T rt_main(
SimStruct * (*model_name)(void),
char_T
*optStr,
char_T
*scopeInstallString,
int_T
scopeFullNames,
int_T
priority,
int_T
port)
{
const char *status;
int_T
int
VxWorksTIDs[NUMST];
optStrLen
SEM_ID
int_T
rtClockSem
parseError
double
int
= strlen(optStr);
finaltime
argc
char_T
= NULL;
= FALSE;
= -2.0;
= 0;
**argv
= NULL;
#ifdef MULTITASKING
SEM_ID
int_T
rtTaskSemaphoreList[NUMST];
i;
#endif
#ifdef EXT_MODE
int_T
extern_msg_tid;
int_T
extern_upload_tid;
#endif
/*
* Do error checking on input args and parse the options string.
*/
if (model_name == NULL) {
parseError = TRUE;
goto PARSE_EXIT;
}
/*
* Parse option string.
*/
if ((optStr != NULL) && (optStrLen > 0)) {
int i;
int
count;
char_T *thisStr;
char_T *nextStr;
/*
* Convert to lower case.
*/
for (i=0; i<optStrLen; i++) {
optStr[i] = tolower(optStr[i]);
}
/*
* Convert error string to standard argc and argv format.
*/
/* count strings and allocate an argv */
argc = CountStrs(optStr) + 1;
argv = (char **)calloc(argc,sizeof(char *));
if (argv == NULL) {
(void)fprintf(stderr,
"Memory allocation error while parsing options string.");
exit(EXIT_FAILURE);
}
/* populate argv & terminate the individual substrings */
argv[0] = "dummyProgramName";
i=1;
nextStr = optStr;
while ((nextStr != NULL) && (thisStr = GetNextStr(nextStr,
&nextStr)) != NULL && ( i < argc )) {argv[i] = thisStr;
i++;
}
/*
* Parse the standard RTW parameters. Let all unrecognized
* parameters pass through to external mode for parsing. NULL
* out all args handled so that the external mode parsing can
* ignore them.
*/
count = 1;
while(count < argc) {
const char_T *option = argv[count++];
/* final time */
if ((strcmp(option, "-tf") == 0) && (count != argc)) {
char_T
tmpstr[2];
char_T
str2[200];
double
tmpDouble;
parseError = TRUE;
goto PARSE_EXIT;
}
}
}
}
PARSE_EXIT:
free(argv);
argv = NULL;
if (parseError) {
exit(EXIT_FAILURE);
}
}
if (priority <= 0 || priority > 255-(NUMST)+1) {
priority = BASE_PRIORITY;
}
/************************
* Initialize the model *
************************/
rt_InitInfAndNaN(sizeof(real_T));
S = model_name();
if (S == NULL) {
(void)fprintf(stderr,"Memory allocation error during model "
"registration");
exit(EXIT_FAILURE);
}
if (ssGetErrorStatus(S) != NULL) {
(void)fprintf(stderr,"Error during model registration: %s\n",
ssGetErrorStatus(S));
TERMINATE(S);
exit(EXIT_FAILURE);
}
if (finaltime >= 0.0 || finaltime == RUN_FOREVER) {
ssSetTFinal(S, (real_T)finaltime);
}
INITIALIZE_SIZES(S);
INITIALIZE_SAMPLE_TIMES(S);
if ((status=rt_InitTimingEngine(S)) != NULL) {
fprintf(stderr,
"Failed to initialize sample time engine: %s\n", status);
exit(EXIT_FAILURE);
}
rt_CreateIntegrationData(S);
#if defined(RT_MALLOC) && NCSTATES > 0
if(ssGetErrorStatus(S) != NULL) {
fprintf(stderr, "Error creating integration data.\n");
rt_DestroyIntegrationData(S);
TERMINATE(S);
exit(EXIT_FAILURE);
}
#endif
#ifdef MAT_FILE
if (rt_StartDataLogging(S) != NULL) {
fprintf(stderr,"Error starting data logging.\n");
return(EXIT_FAILURE);
}
#endif
rtClockSem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY);
startStopSem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY);
#ifdef EXT_MODE
uploadSem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY);
rt_ExtModeInit();
extern_msg_tid = taskSpawn("tExternMsg",
priority+(NUMST), VX_FP_TASK, STACK_SIZE, (FUNCPTR)rt_MsgServer,
(int_T) S,0, 0, 0, 0, 0, 0, 0, 0, 0);
if (extern_msg_tid == ERROR) {
printf("handle taskpawn error"); /* xxx */
}
extern_upload_tid = taskSpawn("tExternUpload",
priority+(NUMST)+1,VX_FP_TASK,STACK_SIZE,(FUNCPTR)rt_UploadServer,
(int_T) S,0, 0, 0, 0, 0, 0, 0, 0, 0);
if (extern_upload_tid == ERROR) {
printf("handle taskpawn error"); /* xxx */
}
/*
* Pause until receive model start message - if external mode.
* Make sure the external mode tasks are running so that
* we are listening for commands from the host.
*/
if (ExtWaitForStartMsg()) {
printf("\nWaiting for start message from host.\n");
semTake(startStopSem, WAIT_FOREVER);
}
modelStatus = TARGET_STATUS_RUNNING;
#endif
START(S);
if (ssGetErrorStatus(S) != NULL) {
/* Need to execute MdlTerminate() before we can exit */
goto TERMINATE;
}
#ifdef STETHOSCOPE
/* Make sure that Stethoscope has been properly initialized. */
ScopeInitServer(4*32*1024, 4*2*1024, 0, 0);
rtInstallRemoveSignals(S, scopeInstallString,scopeFullNames,1);
#endif
sysAuxClkDisable();
rtSetSampleRate(1.0 / ssGetStepSize(S));
#ifdef MULTITASKING
for (i = FIRST_TID + 1; i < NUMST; i++) {
static char taskName[20];
sprintf(taskName, "tRate%d", i);
rtTaskSemaphoreList[i] = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY);
VxWorksTIDs[i] = taskSpawn(taskName,
priority + i, VX_FP_TASK, STACK_SIZE, tSubRate, (int_T) S,
(int_T) rtTaskSemaphoreList[i], i,
0, 0, 0, 0, 0, 0, 0);
}
VxWorksTIDs[0] = taskSpawn("tBaseRate",
priority, VX_FP_TASK, STACK_SIZE, tBaseRate, (int_T) S, (int_T)
rtClockSem, (int_T) startStopSem, (int_T) rtTaskSemaphoreList,
0, 0, 0, 0, 0, 0);
#else /*SingleTasking*/
VxWorksTIDs[0] = taskSpawn("tSingleRate",
priority, VX_FP_TASK, STACK_SIZE, tSingleRate, (int_T) S,
(int_T) rtClockSem, (int_T) startStopSem,
0, 0, 0, 0, 0, 0, 0);
#endif
if (sysAuxClkConnect((FUNCPTR) semGive, (int_T) rtClockSem) == OK) {
rebootHookAdd((FUNCPTR) sysAuxClkDisable);
printf("\nSimulation Starting\n");
sysAuxClkEnable();
}
semTake(startStopSem, WAIT_FOREVER);
/********************
* Cleanup and exit *
********************/
printf("\nSimulation Finished\n");
sysAuxClkDisable();
taskDelete(VxWorksTIDs[0]);
semDelete(rtClockSem);
semDelete(startStopSem);
#ifdef EXT_MODE
taskDelete(extern_msg_tid);
taskDelete(extern_upload_tid);
rt_ExtModeShutdown();
semDelete(uploadSem);
#endif
#ifdef STETHOSCOPE
rtInstallRemoveSignals(S, scopeInstallString,scopeFullNames,0);
#endif
#ifdef MULTITASKING
for (i = FIRST_TID + 1; i < NUMST; i++) {
taskDelete(VxWorksTIDs[i]);
semDelete(rtTaskSemaphoreList[i]);
}
#endif
TERMINATE:
#ifdef MAT_FILE
rt_StopDataLogging(MATFILE,S);
#endif
#if defined(RT_MALLOC) && NCSTATES > 0
rt_DestroyIntegrationData(S);
#endif
TERMINATE(S);
return(EXIT_SUCCESS);
} /* end rt_ma
9
9.1
DSP
: (
: )
: X
: X
:
:
:
>> ver
: (
MATLAB
12.1
18-May-2001
06-Apr-2001
21-May-2001
Stateflow Coder
21-May-2001
Real-Time Workshop
18-May-2001
02-Feb-2001
18-May-2001
18-May-2001
Communications Toolbox
18-May-2001
Communications Blockset
18-May-2001
MATLAB Compiler
30-Mar-2001
18-May-2001
06-Apr-2001
Database Toolbox
04-Jan-2001
Datafeed Toolbox
03-Jan-2001
02-Feb-2001
DSP Blockset
18-May-2001
:
: )
282
Matlab/Simulink
Real-Time Workshop Embedded Coder Version 2.0 (R12.1) 01-Mar-2001
Filter Design Toolbox
Version 2.1 (R12.1) 01-Feb-2001
Financial Toolbox
Version 2.1.3 (R12.1) 12-Mar-2001
Financial Derivatives Toolbox
Version 1.0 (R12.1) 14-Aug-2000
Fixed-Point Blockset
Version 3.1 (R12.1) 18-May-2001
Financial Time Series Toolbox
Version 1.1 (R12.1) 01-Dec-2000
Fuzzy Logic Toolbox
Version 2.1.1 (R12.1) 18-May-2001
GARCH Toolbox
Version 1.0 (R12.1) 01-Jun-1999
System Identification Toolbox
Version 5.0.1 (R12.1) 18-May-2001
Image Processing Toolbox
Version 3.1 (R12.1) 18-May-2001
Instrument Control Toolbox
Version 1.1 (R12.1) 18-May-2001
LMI Control Toolbox
Version 1.0.7 (R12.1) 18-May-2001
Mapping Toolbox
Version 1.2 (R12.1) 22-May-2000
Motorola DSP Developer's Kit
Version 1.1 (R12.1) 01-Sep-2000
Model Predictive Control Toolbox
Version 1.0.6 (R12.1) 18-May-2001
Mu-Analysis and Synthesis Toolbox Version 3.0.6 (R12.1) 18-May-2001
Nonlinear Control Design Blockset
Version 1.1.5 (R12.1) 18-May-2001
Neural Network Toolbox
Version 4.0.1 (R12.1) 02-Feb-2001
Optimization Toolbox
Version 2.1.1 (R12.1) 18-May-2001
Partial Differential Equation Toolbox
Version 1.0.4 (R12.1) 06-Apr-2001
Simulink Performance Tools
Version 1.1 (R12.1) 18-May-2001
Power System Blockset
Version 2.2 (R12.1) 06-Apr-2001
Requirements Management Interface
Version 1.0.2 (R12.1) 30-Nov-2000
Robust Control Toolbox
Version 2.0.8 (R12.1) 18-May-2001
MATLAB Report Generator
Version 1.2 (R12.1) 01-Apr-2001
Simulink Report Generator
Version 1.2 (R12.1) 01-Apr-2001
MATLAB Runtime Server Development Kit Version 6.1 (R12.1) 18-May-2001
SB2SL (converts SystemBuild to Simu...
Signal Processing Toolbox
Version 5.1 (R12.1)
Spline Toolbox
Version 3.0 (R12.1)
Statistics Toolbox
Version 3.0 (R12.1)
Symbolic Math Toolbox
Version 2.1.2 (R12.1)
Developer's Kit for TI(tm) DSP
Version 1.1 (R12.1)
Virtual Reality Toolbox
Version 2.0 (R12.1)
Wavelet Toolbox
Version 2.1 (R12.1)
MATLAB Web Server
Version 1.2.1 (R12.1)
xPC Target
Version 1.2 (R12.1)
xPC Target Embedded Option
Version 1.2 (R12.1)
:
10-Apr-2001
:
1
9.2
DSP
283
MATLAB R12.1
DSP
DSP/
MATLAB
z
MATLAB
Communications Toolbox
Filter Design Toolbox
Image Processing Toolbox
MATLAB C/C++ Math Library
MATLAB C/C++ Graphics Library
Signal Processing Toolbox
Wavelet Toolbox
Simulink
Stateflow
CDMA Reference Blockset
Communications Blockset
DSP Blockset
Motorola DSP Developers Kit
Xilinx Blockset
Altera DSP Builder
Real-Time Workshop
Developers kit for TI DSP
Real-time Windows Target
RTW Embedded Coder
Stateflow Coder
Tornado (VxWorks) Real-Time Target
Xilinxs System Generator for Simulink
Altera SignalCompiler for Simulink
xPC Target
:
:
: /
Matlab/Simulink
284
9.3
MATLAB
MATLAB MATLAB
m
m
MATLAB m
>> A=magic(3)
A=
8
>> invA=inv(A)
invA =
0.1472 -0.1444 0.0639
-0.0611 0.0222 0.1056
-0.0194 0.1889 -0.1028
>> [v,d]=eig(A)
v=
-0.5774 -0.8131 -0.3416
-0.5774 0.4714 -0.4714
-0.5774 0.3416 0.8131
d=
15.0000
0
4.8990
:
:
9
0
DSP
285
0 -4.8990
>> rankofA=rank(A)
rankofA =
3
m Welch %MATLABROOT%\toolbox\
signal\signal\pwelch.m
function varargout = pwelch(x,win,noverlap,varargin)
%PWELCH Power Spectral Density estimate via Welch's method.
% Pxx = PWELCH(X) returns the Power Spectral Density (PSD) estimate,
% Pxx, of a discrete-time signal vector X using Welch's averaged,
% modified periodogram method. By default, X is divided into eight
% sections with 50% overlap, each section is windowed with a Hamming
% window and eight modified periodograms are computed and averaged.
%
% If the length of X is such that it cannot be divided exactly into
% eight sections with 50% overlap, X will be truncated accordingly.
%
% Pxx is the distribution of power per unit frequency. For real signals,
% PWELCH returns the one-sided PSD by default; for complex signals, it
% returns the two-sided PSD. Note that a one-sided PSD contains the
% total power of the input signal.
%
% Pxx = PWELCH(X,WINDOW), when WINDOW is a vector, divides X into
% overlapping sections of length equal to the length of WINDOW, and then
% windows each section with the vector specified in WINDOW. If WINDOW is
% an integer, X is divided into sections of length equal to that integer
% value, and a Hamming window of equal length is used. If the length of
% X is such that it cannot be divided exactly into integer number of
% sections with 50% overlap, X will be truncated accordingly. If WINDOW
% is omitted or specified as empty, a default window is used to obtain
% eight sections of X.
%
% Pxx = PWELCH(X,WINDOW,NOVERLAP) uses NOVERLAP samples of overlap from
% section to section. NOVERLAP must be an integer smaller than the WINDOW
% if WINDOW is an integer. NOVERLAP must be an integer smaller than the
:
:
: function
varargout =
pwelch(x,win,noverlap,varargi
n)
%PWELCH Power Spectral
Density estimate via Welch's
method.
% Pxx = PWELCH(X)
returns the Power Spectral
Density (PSD) estimate,
% Pxx, of a discrete-time
signal vector X using Welch's
averaged,
% modified periodogram
method. By default, X is
divided into eight
% sections with 50% overlap,
each section is windowed with
a Hamming
% window and eight modified
periodograms are computed
and averaged.
%
% If the length of X is such
that it cannot be divided
exactly into
% eight sections with 50%
overlap, X will be truncated
accordingly.
%
% Pxx is the distribution of
power per unit frequency. For
real
% signals,PWELCH returns
the one-sided PSD by default;
for complex
% signals, it returns the twosided PSD. Note that a onesided PSD
% contains the total power of
the input signal.
%
% Pxx =
PWELCH(X,WINDOW),
when WINDOW is a vector,
divides X into
% overlapping sections of
length equal to the length of
WINDOW, and
% then windows each section
with the vector specified in
WINDOW. If
% WINDOW is an integer,
X
... [1]
Matlab/Simulink
286
Fs = 1000; t = 0:1/Fs:.296;
%
% See also PERIODOGRAM, PCOV, PMCOV, PBURG, PYULEAR, PEIG, PMTM, PMUSIC
% and PSDPLOT.
DSP
% Author(s): R. Losada
% Copyright 1988-2001 The MathWorks, Inc.
% $Revision: 1.27 $ $Date: 2001/04/02 20:21:06 $
% References:
%
%
%
error(nargchk(1,6,nargin));
error(nargoutchk(0,2,nargout));
x = x(:);
isreal_x = isreal(x);
M = length(x);
if nargin < 3,
noverlap = [];
if nargin < 2,
win = [];
end
end
% Obtain the necessary information to segment X
[L,noverlap,win,msg] = segment_info(M,win,noverlap);
error(msg);
% Parse optional args nfft, fs
[options,msg] = pwelch_options(isreal_x,L,varargin{:});
% Compute the number of segments
k = (M-noverlap)./(L-noverlap);
% Uncomment the following line to produce a warning each time the data
% segmentation does not produce an integer number of segements.
%if fix(k) ~= k),
% warning('The number of segments is not an integer, truncating data.');
%end
k = fix(k);
287
Matlab/Simulink
288
WIN
(Note that the length of the window determines the length of the segments)
DSP
% Outputs:
%
WIN
MSG
%
%
% The key to this function is the following equation:
%
%
K = (M-NOVERLAP)/(L-NOVERLAP)
%
% where
%
%
- Number of segments
%
% The segmentation of X is based on the fact that we always know M and two of the set
% {K,NOVERLAP,L}, hence determining the unknown quantity is trivial from the above
% formula.
% Initialize outputs
L = [];
msg = '';
% Check that noverlap is a scalar
if any(size(noverlap) > 1),
msg = 'You must specify an integer number of samples to overlap.';
return
end
if isempty(win),
% Use 8 sections, determine their length
if isempty(noverlap),
% Use 50% overlap
L = fix(M./4.5);
noverlap = fix(0.5.*L);
else
L = fix((M+7.*noverlap)./8);
end
% Use a default window
289
Matlab/Simulink
290
win = hamming(L);
else
% Determine the window and its length (equal to the length of the segments)
if ~any(size(win) <= 1) | ischar(win),
msg = 'The WINDOW argument must be a vector or a scalar.';
return
elseif length(win) > 1,
% WIN is a vector
L = length(win);
elseif length(win) == 1,
L = win;
win = hamming(win);
end
if isempty(noverlap),
% Use 50% overlap
noverlap = fix(0.5.*L);
end
end
% Do some argument validation
if L > M,
msg = 'The length of the segments cannot be greater than the length of the input signal.';
return
end
if noverlap >= L,
msg = 'The number of samples to overlap must be less than the length of the segments.';
return
end
%-----------------------------------------------------------------------------function [options,msg] = pwelch_options(isreal_x,N,varargin)
%PWELCH_OPTIONS Parse the optional inputs to the PWELCH function.
% PWELCH_OPTIONS returns a structure, OPTIONS, with following fields:
%
% options.nfft
% options.Fs
% options.range
% Generate defaults
options.nfft = max(256,2^nextpow2(N));
options.Fs = []; % Work in rad/sample
DSP
291
if isreal_x,
options.range = 'onesided';
else
options.range = 'twosided';
end
msg = '';
[options,msg] = psdoptions(isreal_x,options,varargin{:});
% [EOF] pwelch.m
9.1
9.1
e2pi
Matlab/Simulink
292
9.2
9.2
lorenz
DSP
293
9.3
9.3 wrldtrv
:
9.4
Communications Toolbox
/ MATLAB
Matlab/Simulink
294
9.4 9.5
>>x = 4*(rand(1000,2)-1/2);
>>y = demodmap(x,1,1,'psk',4);
>>red = find(y==0);
>>h = scatterplot(x(red,:),1,0,'r.');
DSP
295
9.4 1
>>hold on
>>blue = find(y==2);
>>scatterplot(x(blue,:),1,0,'b.',h);
9.5 2
z
9.6
: ScaTTER Plot
Matlab/Simulink
296
codebook = [-1:.1:1];
t = [0:pi/50:2*pi];
9.6 DPCM
z
>> code2
code2 =
0
DSP
297
>> codeA
codeA =
Columns 1 through 8
0
Columns 9 through 12
0
z
1
:
>> modmap('qam',16)
9.7
9.7
z
16QAM
Matlab/Simulink
298
9.5
MATLAB
/Filter Design Toolbox
9.1 9.2
9.1
:
: 9.1
9.2
.doc
antisymmetricfir
fir
firt
latticema
Lattice MA
symmetricfir
9.2
df1
df1t
df2
II
df2t
II
latticeca
Lattice
latticecapc
Lattice
latticear
Lattice AR
latticearma
Lattice ARMA
statespace
: 9.1 Filter
Design Toolbox
FIR
: 9.2 Filter
Design Toolbox IIR
9.6
z /
z /
z
z
z
9
z
z
DSP
299
9.7
9.8
MATLAB
: 9.8
>> xn=sin(pi/16*(0:31));
>> stem(xn)
9.8
9.8
Matlab/Simulink
300
z
/ 9.9
fdatool
:
:
>>fdatool
9.9
sptool 9.10
>>sptool
9.10 sptool
z
z
DSP
301
IIR
FIR
9.11
: 9.11
:
:
:
9.11
specgramdemo
: n
Matlab/Simulink
302
9.9
Wavelet Toolbox
MATLAB
9.10
Simulink
Simulink 9.12
z /
z /
z
Simulink Simulink
Simulink
Simulink Matlab
Matlab/Simulink
DSP
303
9.12 Simulink
9.11
Stateflow
Stateflow
Matlab/Simulink Stateflow Simulink
z
z
z
z Stateflow / C
9.13 Stateflow
Matlab/Simulink
304
1
:
9.13
9.12
: 15
DSP
305
: 9.14
CDMA Reference Blockset(a)
: 9.14
CDMA Reference Blockset(a)
:
:
: 14
Matlab/Simulink
306
9.16 %MATLABROOT%\toolbox\cdma\cdmademos\is95fwdchendtoend2.mdl
9.13
: 15
Communications Blockset
: 16
:
:
:
DSP
307
9.14
: 16
DSP Blockset
: 17
:
: 17
Matlab/Simulink
308
DSP Blockset
>> demo blocksets dsp
: 18
9.19
9.19 MATLAB
: 18
: Demos
:
: Developer's
:
:
:
: 19
DSP
309
: 19
>> mot_dsp563_filterdemo
9.21 9.22
: 20
: 21
:
310
Matlab/Simulink
9.21
: 20
mot_dsp563_filterdemo.mdl
9.22
: 1
: Scope
9.16
DSP
311
Xilinx Blockset
: 22
: 22
z
z
z S-
z C
z Ada
Real-Time Workshop 9.3
: (
: )
:
:
Matlab/Simulink
312
9.3
GRT
CMES
S-function
noninline
Any
S-functions
inlined
RTW
time
Embedded
malloc
Coder
prototyping
Tomado
S-func
included
TI
DSP
xPC
RTWin
code
RSIM
RAM/ROM usage
Intended for rapid
Ada
DOS
allocation
Continuous time
Real-
Dynamic memory
Real-Time Workshop
: 9.18
Developers Kit for TI DSP
Developers Kit for TI DSP
MathWorks TI
Simulink/Matlab TI
TM
eXpressDSP
Simulink
TI DSP
: s
: C
: (
:
: )
: (
blocks in model
: )
: (
9.18
: )
: (
: )
z
z
DSP
313
9.20
z
z
z
z S- Simulink
9.21
Stateflow Coder
9.24
9.24 Build sfprj\build\sf_car\shiftlogic\src
sfprj\build\sf_car\shiftlogic\info sfprj\build\sf_car\shiftlogic\info
binfo.mat sfprj\build\sf_car\shiftlogic\src Stateflow shift_logic C
Matlab/Simulink
314
: 23
: 9.24
Build
sfprj\build\sf_car\shiftlogic\src
sfprj\build\sf_car\shiftlogic\inf
o
sfprj\build\sf_car\shiftlogic\inf
o
binfo.mat
sfprj\build\sf_car\shiftlogic\src
Stateflow
shift_logic C
:
:
DSP
315
: shift_logic.h
shift_logic.c
/*
*
* Stateflow code generation for machine:
* sf_car
*
* Target Name
: shiftlogic
* Model Version
: 1.188
* Stateflow Version
: 4.1.0.12.10.1.000000
: 09-Mar-2002 02:03:15
*
*/
#define IN_SF_MACHINE_SOURCE
#include "sf_car_shiftlogic.h"
#include "shift_logic.h"
int8_T _sfEvent_sf_car_=CALL_EVENT;
void sf_car_initializer( void )
{
/* Initialize machine's broadcast event variable */
_sfEvent_sf_car_ = CALL_EVENT;
}
void sf_car_terminator(void)
{
}
shift_logic.h
shift_logic.c
/*
*
* Stateflow code generation for chart:
* sf_car/shift_logic
*
* Target Name
: shiftlogic
* Model Version
: 1.188
* Stateflow Version
: 4.1.0.12.10.1.000000
: 09-Mar-2002 02:03:15
Matlab/Simulink
316
*/
#include "sf_car_shiftlogic.h"
#include "shift_logic.h"
#define IN_NO_ACTIVE_CHILD
(0)
#define IN_c1_s2_first
#define IN_c1_s3_fourth
#define IN_c1_s4_second
#define IN_c1_s5_third
#define IN_c1_s7_downshifting
#define IN_c1_s8_steady_state
#define IN_c1_s9_upshifting
#define TWAIT
(2)
#define event_c1_e8_DOWN
#define event_c1_e9_UP
DSP
/* Entry: steady_state */
chartInstance.State.is_c1_s6_selection_state = IN_c1_s8_steady_state;
} else {
c1_s1_gear_state();
{
/* During: selection_state */
if(chartInstance.State.is_active_c1_s6_selection_state != 0) {
broadcast_shift_logic_CALC_TH();
switch(chartInstance.State.is_c1_s6_selection_state) {
case IN_c1_s7_downshifting:
{
/* During: downshifting */
if((_sfEvent_sf_car_ == CALL_EVENT) && (chartInstance.Counters.i1
>= (uint8_T )TWAIT) && (speed <= down_th)) {
{
int8_T previousEvent;
previousEvent = _sfEvent_sf_car_;
_sfEvent_sf_car_ = event_c1_e8_DOWN;
c1_s1_gear_state();
_sfEvent_sf_car_ = previousEvent;
}
/* Exit: downshifting */
/* Entry: steady_state */
chartInstance.State.is_c1_s6_selection_state =
IN_c1_s8_steady_state;
} else if(speed > down_th) {
/* Exit: downshifting */
/* Entry: steady_state */
chartInstance.State.is_c1_s6_selection_state =
IN_c1_s8_steady_state;
}
}
break;
case IN_c1_s8_steady_state:
/* During: steady_state */
if(speed > up_th) {
/* Exit: steady_state */
/* Entry: upshifting */
chartInstance.State.is_c1_s6_selection_state = IN_c1_s9_upshifting;
chartInstance.Counters.i1=0;
} else if(speed < down_th) {
/* Exit: steady_state */
317
Matlab/Simulink
318
/* Entry: downshifting */
chartInstance.State.is_c1_s6_selection_state =
IN_c1_s7_downshifting;
chartInstance.Counters.i1=0;
}
break;
case IN_c1_s9_upshifting:
{
/* During: upshifting */
if((_sfEvent_sf_car_ == CALL_EVENT) && (chartInstance.Counters.i1
>= (uint8_T )TWAIT) && (speed >= up_th)) {
{
int8_T previousEvent;
previousEvent = _sfEvent_sf_car_;
_sfEvent_sf_car_ = event_c1_e9_UP;
c1_s1_gear_state();
_sfEvent_sf_car_ = previousEvent;
}
/* Exit: upshifting */
/* Entry: steady_state */
chartInstance.State.is_c1_s6_selection_state =
IN_c1_s8_steady_state;
} else if(speed < up_th) {
/* Exit: upshifting */
/* Entry: steady_state */
chartInstance.State.is_c1_s6_selection_state =
IN_c1_s8_steady_state;
}
}
break;
}
}
}
}
}
}
static void c1_s1_gear_state(void)
{
{
/* During: gear_state */
DSP
if(chartInstance.State.is_active_c1_s1_gear_state != 0) {
switch(chartInstance.State.is_c1_s1_gear_state) {
case IN_c1_s2_first:
/* During: first */
if(_sfEvent_sf_car_ == event_c1_e9_UP) {
/* Exit: first */
/* Entry: second */
chartInstance.State.is_c1_s1_gear_state = IN_c1_s4_second;
gear = 2;
}
break;
case IN_c1_s3_fourth:
/* During: fourth */
if(_sfEvent_sf_car_ == event_c1_e8_DOWN) {
/* Exit: fourth */
/* Entry: third */
chartInstance.State.is_c1_s1_gear_state = IN_c1_s5_third;
gear = 3;
}
break;
case IN_c1_s4_second:
/* During: second */
if(_sfEvent_sf_car_ == event_c1_e9_UP) {
/* Exit: second */
/* Entry: third */
chartInstance.State.is_c1_s1_gear_state = IN_c1_s5_third;
gear = 3;
} else if(_sfEvent_sf_car_ == event_c1_e8_DOWN) {
/* Exit: second */
/* Entry: first */
chartInstance.State.is_c1_s1_gear_state = IN_c1_s2_first;
gear = 1;
}
break;
case IN_c1_s5_third:
/* During: third */
if(_sfEvent_sf_car_ == event_c1_e9_UP) {
/* Exit: third */
/* Entry: fourth */
chartInstance.State.is_c1_s1_gear_state = IN_c1_s3_fourth;
gear = 4;
} else if(_sfEvent_sf_car_ == event_c1_e8_DOWN) {
319
Matlab/Simulink
320
/* Exit: third */
/* Entry: second */
chartInstance.State.is_c1_s1_gear_state = IN_c1_s4_second;
gear = 2;
}
break;
}
}
}
}
void initialize_shift_logic(void)
{
/* Initializing chart output data */
gear = (uint8_T)0;
/* Initialize chart's state configuration */
memset((void*)&(chartInstance.State),0,sizeof(chartInstance.State));
}
9.22
9.23
: (
: )
:
: (
: )
DSP
321
PC
9.25 9.26
: 5
: 24
: 25
285:
[1]
fcr
2002-9-17 15:50:00
%
% F is the vector of frequencies at which the PSD is estimated and has
% units of Hz. For real signals, F spans the interval [0,Fs/2] when
% NFFT is even and [0,Fs/2] when NFFT is odd. For complex signals, F
% always spans the interval [0,Fs).
%
% [...] = PWELCH(...,'twosided') returns a two-sided PSD of a real
% signal X. In this case, Pxx will have length NFFT and will be
% computed over the interval [0,2*Pi] if Fs is not specified and over
% the interval [0,Fs] if Fs is specified. Alternatively, the string
% 'twosided' can be replaced with the string 'onesided' for a real
% signal X. This would result in the default behavior. The string
% 'twosided' or 'onesided'may be placed in any position in the input
% argument list after NOVERLAP.
%
% PWELCH(...) with no output arguments by default plots the PSD
% estimate in dB per unit frequency in the current figure window.
%
% EXAMPLE:
%
Fs = 1000; t = 0:1/Fs:.296;
%
% See also PERIODOGRAM, PCOV, PMCOV, PBURG, PYULEAR, PEIG, PMTM,
% PMUSIC and PSDPLOT.
% Author(s): R. Losada
% Copyright 1988-2001 The MathWorks, Inc.
% $Revision: 1.27 $ $Date: 2001/04/02 20:21:06 $
% References:
%
%
%
error(nargchk(1,6,nargin));
error(nargoutchk(0,2,nargout));
x = x(:);
isreal_x = isreal(x);
M = length(x);
if nargin < 3,
noverlap = [];
if nargin < 2,
win = [];
end
end
% Obtain the necessary information to segment X
[L,noverlap,win,msg] = segment_info(M,win,noverlap);
error(msg);
% Parse optional args nfft, fs
[options,msg] = pwelch_options(isreal_x,L,varargin{:});
% Compute the number of segments
k = (M-noverlap)./(L-noverlap);
% Uncomment the following line to produce a warning each time the data
% segmentation does not produce an integer number of segements.
%if fix(k) ~= k),
% warning('The number of segments is not an integer, truncating
% data.');
%end
k = fix(k);
% Compute the periodogram power spectrum of each segment and average
% always compute the twosided power spectrum, we force Fs = 1 to get
% a spectrum not a spectral density
Sxx = zeros(options.nfft,1); % Initialize
xindx = 1;
for i = 1:k,
Sxx = Sxx + periodogram(x(xindx:xindx+L-1),win,options.nfft,1,
'twosided');
xindx = xindx + L - noverlap;
end
Sxx = Sxx./k; % Average the sum of the periodograms
% Generate the frequency vector in [rad/sample] at which Sxx was
% computed If Fs is not empty, w will be converted to Hz in computepsd below
w = 2.*pi.*(0:options.nfft-1)./options.nfft;
varargout = {Pxx};
elseif nargout == 2,
varargout = {Pxx,w};
end
%---------------------------------------------------------------------function [L,noverlap,win,msg] = segment_info(M,win,noverlap)
%SEGMENT_INFO Determine the information necessary to segment the input
data.
%
% Inputs:
% M - An integer containing the length of the data to be segmented
% N - A scalar or vector containing the length of the window or the
% window respectively (Note that the length of the window determines
the length of the segments)
%
(may be empty)
%
% Outputs:
% L
K = (M-NOVERLAP)/(L-NOVERLAP)
%
% where
%
%
- Number of segments
%
% The segmentation of X is based on the fact that we always know M and
% two of the set {K,NOVERLAP,L}, hence determining the unknown
% quantity is trivial from the above formula.
% Initialize outputs
L = [];
msg = '';
% Check that noverlap is a scalar
if any(size(noverlap) > 1),
msg = 'You must specify an integer number of samples to overlap.';
return
end
if isempty(win),
% Use 8 sections, determine their length
if isempty(noverlap),
% Use 50% overlap
L = fix(M./4.5);
noverlap = fix(0.5.*L);
else
L = fix((M+7.*noverlap)./8);
end
% Use a default window
win = hamming(L);
else
% Determine the window and its length (equal to the length of the
segments)
if ~any(size(win) <= 1) | ischar(win),
msg = 'The WINDOW argument must be a vector or a scalar.';
return
elseif length(win) > 1,
% WIN is a vector
L = length(win);
elseif length(win) == 1,
L = win;
win = hamming(win);
end
if isempty(noverlap),
% Use 50% overlap
noverlap = fix(0.5.*L);
end
end
% Do some argument validation
if L > M,
msg = 'The length of the segments cannot be greater than the length
of the input signal.';
return
end
if noverlap >= L,
msg = 'The number of samples to overlap must be less than the length
of the segments.';
return
end
%---------------------------------------------------------------------function [options,msg] = pwelch_options(isreal_x,N,varargin)
%PWELCH_OPTIONS Parse the optional inputs to the PWELCH function.
% PWELCH_OPTIONS returns a structure, OPTIONS, with following fields:
%
% Generate defaults
options.nfft = max(256,2^nextpow2(N));
options.Fs = []; % Work in rad/sample
if isreal_x,
options.range = 'onesided';
else
options.range = 'twosided';
end
msg = '';
[options,msg] = psdoptions(isreal_x,options,varargin{:});
% [EOF] pwelch.m
: A
:
: function
commsmtr(varargin)
commsmtr.mdisphelp.m prcsofcmdline.m
>mcc B sgl commsmtr.m
commsmtr.exe
>> !commsmtr sui4bpsk.mat /s 5 /r 0:5:40 /c 4 /m 1 /f 256 /t 10000 /p 0.25
**********system parameter for current simulation**********
the sampling frequency: Fs=5 (MHz)
the ratio of energy of each bit to noise power spectral density: Eb/N0= 0 5 10 15 20 25 30 35 40
the channel mode:
SUI-4 + AWGN
the mapping method:
BPSK
the size of IFFT: 256
the total bits of transmitted data: 10240
the size of cyclic prefix: 64
the simulation results will be saved in file sui4bpsk.mat
>> !commsmtr /?
A certain communications system simulator console application
commsmtr [filename] [/S Fs] [/R Eb_N0] [/C channel_model]
[/M mapping_mode] [/F points_in_a_IFFT] [/T total_transmitted_data_bits]
0 - AWGN
1 - SUI-1 + AWGN
2 - SUI-2 + AWGN
[/P cyclic_prefix_length]
filename
Fs
Eb_N0
% COMMSMTR - simulator
console application for a
certain communications
system
% Please compile it into
windows console application
commsmtr.exe
% as the following MATLAB
commands:
% >>mex -setup
% >>mbuild -setup
% >>mcc -B sgl commsmtr.m
% then run it as a executable
program in Windows console,
just like
% >commsmtr /?
% >commsmtr sui416qam.mat
/s 5 /r 0:5:40 /c 4 /m 1 /f 256 /t
10000 /p
0.25
% and so on.
%
% Note!!!
% This example is just for
explaining how to input
multiple command line
parameters
% not for simulation.
%
% author: YongchunChen
% date: 2002/02/08
% version: 1.0
323
: A
3 - SUI-3 + AWGN
4 - SUI-4 + AWGN
5 - SUI-5 + AWGN
6 - SUI-6 + AWGN
7 - Jakes + AWGN
mapping_mode the mapping method
1 - BPSK
:
2 - QPSK
4 - 16QAM
6 - 64QAM.
points_in_a_IFFT
:
: A.
The argument Eb_N0 must be an array. You can input an array by the
expressions such as 0:30, 0:5:30, [0,1,2,3,4,5,10,20,30], in which
an blank is not permitted. The argument total_transmitted_data_bits
must be a scalar. The arguments Fs, channel_model,mapping_mode,
points_in_a_IFFT and cyclic_prefix_length can be a scalar or an array,
but only one of them can be an array at the same time.
The following examples are all correct using method of commsmtr:
commsmtr /?
commsmtr
commsmtr data.mat /s [3,5] /r 0:5:40 /c 4 /m 6 /F 256 /t 65536 /p 0.25
commsmtr data.mat /s 5 /r 0:5:40 /c 4 /m [1,2,4,6] /F 256 /t 65536 /p 0.25
commsmtr data.mat /s 5 /r 0:5:40 /c 1:4 /m 1 /F 256 /t 65536 /p 0.25
commsmtr data.mat /s 5 /r 0:5:40 /c 4 /m 1 /F 256 /t 65536 /p 0.25
commsmtr data.mat /s 5 /r 0:5:20 /c 4 /m 2 /F 256 /t 65536 /p [0.2,0.25]
:
A.1 DOS
commsmtr.exe
If you want to break the running of this program, please press Ctrl+C.
: (
: )
: ,
:
:
:
: ,
: ,
324
Matlab/Simulink
A MATLAB C:\matlablib\bin\win32
%MATLABROOT%\bin\win32
4. A DOS commsmtr.exe
: (
:
:
: )
1 DOS commsmtr.exe
322:
[1]
function commsmtr(varargin)
% COMMSMTR - simulator console application for a certain communications
system
% Please compile it into windows console application commsmtr.exe
% as the following MATLAB commands:
% >>mex -setup
% >>mbuild -setup
% >>mcc -B sgl commsmtr.m
% then run it as a executable program in Windows console, just like
% >commsmtr /?
% >commsmtr sui416qam.mat /s 5 /r 0:5:40 /c 4 /m 1 /f 256 /t 10000 /p
0.25
% and so on.
%
% Note!!!
% This example is just for explaining how to input multiple command line
parameters
% not for simulation.
%
% author: YongchunChen
% date: 2002/02/08
% version: 1.0
%% defining default system parameters
commSys.Fs=5000000; % sampling frquency=5MHz
commSys.Eb_N0=0:5:40; % the ratio of Energy of each bit to noise
power spectral density
commSys.channelType=4; % SUI-channel type
commSys.channelMode=strvcat('AWGN',... % channel type
'SUI-1 + AWGN',...
'SUI-2 + AWGN',...
'SUI-3 + AWGN',...
'SUI-4 + AWGN',...
'SUI-5 + AWGN',...
'SUI-6 + AWGN',...
'Jakes + AWGN');
commSys.ifftSize=256; % IFFT size
commSys.wordSize=1; % word size corresponding to modulation method
% 1 BPSK <==>2QAM
% 2 QPSK <==>4QAM
% 4 16QAM
% 6 64QAM
commSys.energyNormalized=[1,1/sqrt(2),1,1/sqrt(10),1,1/sqrt(42)];
commSys.mappingMode=strvcat('BPSK',... % mapping type
'QPSK ',...
' ',...
'16QAM',...
2002-9-14 9:26:00
' ',...
'64QAM');
% total transmitted data bits including data used to estimate channel
commSys.totalBits=commSys.ifftSize*commSys.wordSize*256;
commSys.cpLenRatio=1/4; % cyclic prefix length in unit:(ifftSize)
% length of CP equal to 1/4 of IFFT size
commSys.cpLen=round(commSys.ifftSize*commSys.cpLenRatio);
commSys.dataFileName='commsimulation.mat';
commSys.thirdDemension=0; % nothing as the third demension
% preamble symbol column used to estimate channel, here we assume it as 1
commSys.estimatingColumn=1;
%% end of definding default system parameters
% processing command line parameters
paramLen=length(varargin);
% display helping text for the simulator console application
if paramLen==1&strmatch('/?',varargin)
disphelp;
return;
end
if paramLen~=0
[cmdLineErr,commSys]=prcsOfCmdLine(commSys,varargin,paramLen);
if cmdLineErr
return;
end
end
% display system parameters
disp('**********system parameter for current simulation**********');
disp(['the sampling frequency: Fs=',num2str(commSys.Fs/1000000),'
(MHz)']);
disp(['the ratio of energy of each bit to noise power spectral density:
Eb/N0=', ...
num2str(commSys.Eb_N0)]);
disp('the channel mode:');
disp(cat(2,zeros(length(commSys.channelType),17),commSys.channelMode( ...
commSys.channelType+1,:)));
disp('the mapping method:');
disp(cat(2,zeros(length(commSys.wordSize),17),commSys.mappingMode( ...
commSys.wordSize,:)));
disp(['the size of IFFT: ',num2str(commSys.ifftSize)]);
disp(['the total bits of transmitted data: ',num2str (commSys.totalBits)]);
disp(['the size of cyclic prefix: ',num2str(commSys.cpLen)]);
disp(['the simulation results will be saved in file ',commSys.dataFileName]);
disp(' ');
% the processing is omitted
% ......
%
disphelp.m
function disphelp
% DISPHELP - display helping text for communications simulator console
application
disp(strvcat( ...
'communications simulator console application', ...
' ',...
'commsmtr [filename] [/S Fs] [/R Eb_N0] [/C channel_model]',...
'[/M mapping_mode] [/F points_in_a_IFFT] [/T total_transmitted_
data_bits]',...
'[/P cyclic_prefix_length]',...
' ',...
'filename
'
will be saved.',...
'Fs
'Eb_N0
'
0 - AWGN',...
'
1 - SUI-1 + AWGN',...
'
2 - SUI-2 + AWGN',...
'
3 - SUI-3 + AWGN',...
'
4 - SUI-4 + AWGN',...
'
5 - SUI-5 + AWGN',...
'
6 - SUI-6 + AWGN',...
'
7 - Jakes + AWGN',...
1 - BPSK',...
'
2 - QPSK',...
'
4 - 16QAM',...
'
6 - 64QAM.',...
'points_in_a_IFFT
' ',...
'The argument Eb_N0 must be an array. You can input an array by
the',...
'expressions such as 0:30, 0:5:30, [0,1,2,3,4,5,10,20,30], in
which',...
'an blank is not permitted. The argument total_transmitted_
data_bits',...
'must be a scalar. The arguments Fs, channel_model,mapping_mode,',...
spectral',...
prcsofcmdline.m
function [cmdLineErr, commSysNew]=prcsofcmdline(commSysDefault,
varargin,paramLen)
% PRCSOFCMDLINE - processing command line parameters
commSysNew=commSysDefault;
cmdLineErr=0;
cmdLine=lower(varargin);
k=1;
while k<=paramLen % beginning of while
if findstr('.mat',cmdLine{k})~=[] % beginning of if
FID=fopen(cmdLine{k},'w');
if FID~=-1
commSysNew.dataFileName=cmdLine{k};
fclose(FID);
k=k+1;
else
disp('Argument filename error! The filename should be *.mat,
such as data.mat, file1.mat and so on.');
cmdLineErr=1;
end
else % else of if
switch cmdLine{k}
case '/s'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a
sampling frequency
if temp~=-1&isnumeric(temp)
commSysNew.Fs=temp*1000000;
k=k+2;
else
disp('Argument Fs! The Fs should be a positive
scalar or array.');
cmdLineErr=1;
end
else
disp('Argument Fs! The Fs should be a positive scalar or
array.');
cmdLineErr=1;
end
case '/r'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a Eb/N0
if temp~=-1&isnumeric(temp)
commSysNew.Eb_N0=temp;
k=k+2;
else
disp('Argument Eb_N0 error! The Eb_N0 should be a
positive scalar or array.');
cmdLineErr=1;
end
else
disp('Argument Eb_N0 error! The Eb_N0 should be a )
positive scalar or array.');
cmdLineErr=1;
end
case '/c'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a channel
type
if temp~=-1&isnumeric(temp)
commSysNew.channelType=temp;
k=k+2;
else
disp('Argument channel_model error! The channel_model is
presented by a integral scalar or array between 0-7.');
cmdLineErr=1;
end
else
disp('Argument channel_model error! The channel_model is
presented by a integral scalar or array between 0-7.');
cmdLineErr=1;
end
case '/m'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a mapping
mode
if temp~=-1&isnumeric(temp)
commSysNew.wordSize=temp;
k=k+2;
else
disp('Argument mapping_mode error! The mapping_mode is presented by a
integral scalar or array including 1,2,4 or 6.');
cmdLineErr=1;
end
else
disp('Argument mapping_mode error! The mapping_mode is presented by a
integral scalar or array including 1,2,4 or 6.');
cmdLineErr=1;
end
case '/f'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a IFFT
size
if temp~=-1&isnumeric(temp)
commSysNew.ifftSize=temp;
k=k+2;
else
disp('Argument points_in_a_IFFT IFFT size error! The points_in_a_IFFT
should be a positive integral scalar or array.');
cmdLineErr=1;
end
else
disp('Argument points_in_a_IFFT IFFT size error! The points_in_a_IFFT
should be a positive integral scalar or array.');
cmdLineErr=1;
end
case '/t'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a total
transmitted bits
if temp~=-1&isnumeric(temp)
commSysNew.totalBits=temp;
k=k+2;
if length(commSysNew.totalBits)>1|commSysNew.totalBits < 1
disp('Argument total_transmitted_data_bits error! The total_transmitted_
data_bits should be a positive integral scalar.');
cmdLineErr=1;
end
else
disp('Argument total_transmitted_data_bits error! The total_transmitted_
data_bits should be a positive integral scalar.');
cmdLineErr=1;
end
else
disp('Argument total_transmitted_data_bits error! The total_transmitted_
data_bits should be a positive integral scalar.');
cmdLineErr=1;
end
case '/p'
if k+1<=paramLen
temp=eval(cmdLine{k+1},'-1'); % -1 can not be a cyclic
prefix length
if temp~=-1&isnumeric(temp)
commSysNew.cpLenRatio=temp;
if max(commSysNew.cpLenRatio)> 1|
min(commSysNew.cpLenRatio)<0
disp('Argument cyclic_prefix_length error! The cyclic_prefix_length
should be a numeric scalar or array between 0.0-1.0.');
cmdLineErr=1;
end
k=k+2;
else
disp('Argument cyclic_prefix_length error! The cyclic_prefix_length
should be a numeric scalar or array between 0.0-1.0.');
cmdLineErr=1;
end
else
disp('Argument cyclic_prefix_length error! The cyclic_prefix_length
should be a numeric scalar or array between 0.0-1.0.');
cmdLineErr=1;
end
otherwise
disp('Command Line error!');
cmdLineErr=1;
end
end % end of if
if cmdLineErr
disphelp;
return;
end
end % end of while
% check if the input parameters is correct
% .....
%
temp=commSysNew.ifftSize*commSysNew.wordSize;
LstComMult=1;
for i=1:length(temp)
LstComMult=lcm(LstComMult,temp(i));
end
commSysNew.totalBits=max(ceil(commSysNew.totalBits/LstComMult),1)*LstCom
Mult;
commSysNew.cpLen=ceil(max(commSysNew.ifftSize)*commSysNew.cpLenRatio);
6
7
8
25
610
10
9
DOS
Windows
OS/2
Macintosh
Unix
Linux
10
11 PC
12 CD-ROM
(E-mailthjd@thjd.com.cn)
Matlab/Simulink
100084
01062791976
01062788903
www.thjd.com.cn
15%