Matlab Utilities
M-Files | Analysis Files
M-Files
These files are found in the MechaWare\Matlab\Utilities directory and are used by Matlab to generate the configuration files for either a BiQuad or an Observer block
LowPass
MechaWare\Matlab\Utilities\Lowpass.m
The LowPass Matlab utility program generates a text file that implements a low pass filter in a Biquad block. The filter type is a second order Butterworth Design. The structure is also returned in an output variable.
Matlab Command Line |
BIQ=Lowpass
(Hertz, Ts, name) |
Input Argument |
Description |
Hertz |
Filter Break Point in Hertz |
Ts |
Controller Sample Rate |
name |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
Example |
BIQ=Lowpass (250, Ts, 'BIQ') |


MultiStageBIQ
MechaWare\Matlab\Utilities\MultiStageBIQ.m
The MultiStageBIQ Matlab utility program generates a text file that implements a multistage-cascaded biquad filter in a Biquad block. The structure is also returned in an output variable.
Matlab Command Line |
[BIQ]=MultiStageBIQ
(b, a. Ts, blockname) |
Input Argument |
Description |
b |
Numerator of Z-domain transfer function. |
a |
Denominator of Z-domain transfer function. |
Ts |
Controller Sample Rate |
blockName |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
MWOBS
MechaWare\Matlab\Utilities\MWOBS.m
The MWOBS Matlab utility program generates a text file that configures the Observer block. The structure is also returned in an output variable.
Matlab Command Line |
[OBS]=MakeEcaOBS (Obs, blockname) |
Input Argument |
Description |
Obs |
The state space description of the observer block in discrete time. MechaWare Observers are 2 input, 1 output, Nth order systems. Obs is a Matlab LTI (Linear Time Invariant) Structure. |
blockName |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
OBS |
Name of MechaWare structure used by Simulink. |
Notch
MechaWare\Matlab\Utilities\Notch.m
The Notch Matlab utility program generates a text file that implements a second order notch filter in a Biquad block. The filter type is a second order Butterworth Design transformed to a notch filter. The structure is also returned in an output variable.
Matlab Command Line |
BIQ=Notch
(Hertz,BW,Ts,name) |
Input Argument |
Description |
Hertz |
Notch Center Frequency in Hertz |
BW |
Notch Width in Hertz |
Ts |
Controller Sample Rate |
name |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
Example |
BIQ=Notch(100,100,Ts,'BIQ') |


PID2BIQ
MechaWare\Matlab\Utilities\PID2BIQ.m
The PID2BIQ Matlab utility program generates a text file that implements a PID algorithm in a Biquad block. The structure is also returned in an output variable.
Matlab Command Line |
BIQ=Notch
(Hertz,BW,Ts,name) |
Input Argument |
Description |
Ypid |
A matlab structure that defines pid gains and sample rate. The structure has the following elements:
Ypid.Kp
Ypid.Ki
Ypid.Kd
Ypid.Ts |
name |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
Example |
ypid =
Kp: 1
Ki: 0.5000
Kd: 50
Ts: 1.2500e-004
BIQ=PID2BIQ(ypid,'BIQ') |


Resonator
MechaWare\Matlab\Utilities\Resonator.m
The Resonator Matlab utility program generates a text file that implements a resonator filter in a Biquad block. The structure is also returned in an output variable.
Matlab Command Line |
BIQ=Resonator (
fn,bw,depth,Ts,name
) |
Input Argument |
Description |
fn |
Center Frequency in Hertz |
bw |
Width in Hertz |
depth |
Depth or Height of filter Magnitude in dB. |
Ts |
Controller Sample Rate |
name |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
Example |
BIQ=Resonator(100,100,20,Ts,'BIQ') |


BIQ=Resonator(100,100,-20,Ts,'BIQ')


UnityGain
MechaWare\Matlab\Utilities\UnityGain.m
The UnityGain Matlab utility program generates a text file that implements a unity gain filter in a Biquad block. The structure is also returned in an output variable.
Matlab Command Line |
BIQ=UnityGain
(Ts, name) |
Input Argument |
Description |
Ts |
Controller Sample Rate |
name |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
Example |
BIQ=UnityGain(Ts,’BIQ’) |
ZP2BIQ
MechaWare\Matlab\Utilities\ZP2BIQ.m
The ZP2BIQ Matlab utility program generates a text file that implements a second order filter specified with 2 poles, 2 zeros, and DC gain filter in a Biquad block. The structure is also returned in an output variable.
Matlab Command Line |
BIQ=UnityGain
(Ts, name) |
Input Argument |
Description |
z |
Transfer Function zeros in Hertz;
z is a matlab array
z=[z1;z2] |
p |
Transfer Function poles in Hertz;
p is a matlab array
p=[p1;p2] |
k |
DC gain of Transfer Function |
Ts |
Controller Sample Rate |
name |
Name of Parameter text file. This should be the same name as the output variable. |
Output Variable |
Output Variable |
BIQ |
Name of MechaWare structure used by Simulink. |
Example |
BIQ=ZP2BIQ([-80; -100],
[-20 ;-1000],
10,
Ts,
'BIQ') |


MATLAB Analysis Files
fftcalc
MechaWare\Matlab\Analysis\fftcalc.m
The fftcalc.m Matlab analysis program calculates and plots the Frequency Response transer function of Y(s)/U(s) of two input vectors: u and y.
fftcalc uses Welch's Method to calculate the frequency response.
Matlab Command Line |
[P,F]=fftcalc(u, y, Fs, Measpar); |
Input Argument |
Description |
u |
Input data vector |
y |
Output vector |
Fs |
Corresponding Sample Rate for input and output data |
Measpar |
Matlab structure that defines FFT and plotting parameters. |
Measpar,NFFT |
Number of points in FFT. |
Measpar. WINDOW |
Window vector used for analysis has the same number of points as NFFT. |
Measpar,OVERLAP |
Overlap specified as number of points. |
Measpar,Fs |
Sample Rate of Data Collection |
Measpar.MagRange |
Vector [min max], containing minimum and maximum values plotted on the magnitude plot. |
Measpar.PhasRange |
Vector [min max], containing minimum and maximum values plotted on the phase plot. |
Measpar.FreqRange |
Vector [min max], containing minimum and maximum values that Frequency is plotted. |
Output Variable |
Output Variable |
P |
Complex Frequency Response |
Fs |
Corresponding Frequency in Hertz for P |
Example |
[P,F]=fftcalc(u,y,Fs,measpar); |
|
measpar =
NFFT: 8192
WINDOW: [8192x1 double]
OVERLAP: 4096
Fs: 8000
MagRange: [0.0100 100]
PhasRange: [-180 180]
FreqRange: [1 1000] |
|