MathWorks News & Notes
MathWorks News & Notes
Generating C Code
from MATLAB
Internet of Things
Cleves Laboratory
MATLAB SPEAKS
WIRELESS
DESIGN
MATLAB CENTRAL
TURNS FIFTEEN!
Tap into the knowledge and experience of thousands of community members.
Find or contribute downloadable code, technical tips, and answers.
2000
25,000
Downloadable files
on File Exchange
120,000
Questions answered
on MATLAB Answers
3000
Posts on MATLAB
and Simulink blogs
mathworks.com/matlabcentral
10
14
18
22
MathWorks News&Notes
featu res
14 HS Bochum Students Design and Build a Motor Controller for an E-Longboard
with Model-Based Design
When the company learned of Kevins success with the e-longboard, they hired him on the spot.
30
18 Creating Computer Vision and Machine Learning Algorithms That Can Analyze
Works of Art
Using MATLAB and a database of thousands of paintings, Rutgers University researchers discovered that an
algorithm could classify a painting as easily as a non-expert human.
abo ut th e cov e r
The cover shows a rendering of a commercial aircraft, highlighting the THSA (trimmable
horizontal stabiliser actuator). On a more electric aircraft, mechanical actuators are replaced with
all-electric actuators, reducing weight, improving reliability, and minimizing environmental
impact. The article on page 6 describes how engineers in Microsemis Aviation Center of Excellence
developed a power core module (PCM) for a more electric aircraft. The PCM controls the electric
motors used in primary flight control actuation and landing gear systems.
de partm e nts
4 MATLAB and Simulink in the World: Physical
Modeling
Managing Editor
Linda Webb
Production Staff
L. Bai, J. Mespelli, A. Pollack
Editor
Rosemary Oxenford
Editorial Board
T. Andraczek, S. Gage, C. Hayhurst,
M.Hirsch, S. Lehman, D. Lluch,
M.Maher, A. May, C. Moler,
M. Mulligan, L.Shure, J. Tung
Art Director
Robert Davison
Graphic Designer
Chris Roth
Technical Writer
Jack Wilber
Production Editor
Julie Cornell
Printer
DS Graphics
Subscribe
mathworks.com/subscribe
Comments
mathworks.com/contact
Find Us Online
Physical Modeling
Engineers in the automotive, aerospace, manufacturing, and other industries use Simulink and Simscape to assemble
system-level models that include the control system and span mechanical, electrical, and other physical domains. By
simulating the plant model and the controller in a single environment, they optimize system-level performance and test their
designs under scenarios that would be difficult, expensive, or unsafe to test on physical prototypes.
enabled them to test the system under conditions that would be difficult or unsafe to test at sea.
mathworks.com/dcns
AIRBUS
Developing a fuel management system for the
A380 aircraft
The Airbus A380 is the largest commercial aircraft currently in
operation. Its 11 fuel tanks enable nonstop flights of more than
8000 miles. Airbus engineers modeled the control logic for the
A380s fuel management system in Simulink and Stateflow. This
model defines modes of operation on the ground (including refuel,
defuel, and ground transfer) and in flight (including center of gravity
control, load alleviation, and fuel jettison). The team developed
a parameterized plant model of the tanks, pumps, and valves, and
incorporated relays and other elements of the electrical power system
with Simscape. Engineers can reconfigure this model to represent
fuel systems for any Airbus aircraft.
mathworks.com/airbus
DCNS
Modeling and simulating a helicopter handling system
The SAMAHE handling system can transfer a 10-ton helicopter between a hangar and a navy ships flight deck in less than two minutes.
It operates safely in waves up to 6 meters high, and can be configured
for use on a variety of ships, from corvettes to frigates. Working in
Simulink and Simscape, DCNS built a three-dimensional mechanical model of the system model comprising the handling system, helicopter, and ship. DCNS ran more than 1200 simulations for various
helicopter mass configurations, center of gravity locations, and positions, as well as ship motion and wind conditions. The simulations
MathWorks News&Notes | 2 0 1 6 2 0 1 7
METSO
Developing a controller for an energy-saving digital
hydraulic system for papermaking equipment
In industrial papermaking equipment, the calender rolls must be precisely controlled to ensure smoothness and glossiness in the paper.
VINTECC
PLC system development for a multi-axle harvesting
machine
With a 780hp engine driving three independent rear axles and two
independent wheels on the front axle, the JPS Mega Star harvester
can collect and haul 100 tons of produce in a single load. Vintecc developed the harvesters complex control system. Using Simscape they
modeled tire and vehicle body elements; hydraulic pumps, motors,
and cylinders; powertrain components; and mechanical linkages.
LEARN MORE
Physical Modeling Solutions
mathworks.com/physical-modeling
User Stories
mathworks.com/user-stories
MathWorks News&Notes | 2 0 1 6 2 0 1 7
control module uses this information to direct the PCM to speed the motor up or slow it
down. Because this was a new design, we had
to develop the PCM without having working
versions of the monitoring module or control
module available to test it.
We modeled the PCM in Simulink, using Simscape Power Systems and Simscape
Electronics to model the three-phase PMSM
drive and electronic components and the control and monitoring modules. We then ran
MathWorks News&Notes | 2 0 1 6 2 0 1 7
MathWorks News&Notes | 2 0 1 6 2 0 1 7
What We Learned
Through our extensive modeling and simulations, we established that units equipped with
motor drives based on silicon carbide (SiC)
MOSFETs operate at a temperature approximately 40 Celsius lower than similar units
with IGBTs.
Because active cooling is not possible with
todays smaller and lighter hardware designs,
managing the temperature of the device while
in operation is vital to ensuring that it will func-
tion reliably for 150,000 flight hours. Simulations also showed that power dissipation with
IGBTs is considerably higher than with SiC
MOSFETs (Figure 4). These insights informed
our design decisions for the PCM and point to
SiC MOSFETS as an enabling technology as the
industry moves towards increased fly-by-wire
controls in the more electric aircraft (MEA).
Simulink, Simulink Real-Time, and
Speedgoat target hardware have enabled us to
demonstrate the application-specific reliabil-
LEARN MORE
Real-Time Simulation and Testing with
Simulink Real-Time 39:57
mathworks.com/video-100956
both the PCM controller and the other modules were run on the target hardware for realtime tests. In a different setup, we deployed our
controller to a production ProASIC3 FPGA on
the PCM and ran hardware-in-the-loop tests
with the target hardware system performing
the functions of the control and monitoring
modules. We tested normal operation using
both test setups. We also tested the controllers
response to several fault conditions to perform
failure mode, effects, and criticality analysis.
FIGURE 3. A plot of motor current for a typical
flight mission of a single-aisle aircraft.
MathWorks News&Notes | 2 0 1 6 2 0 1 7
ingthe motor current demands for an aileron actuator, for example, vary significantly.
Simulations that we ran using our Simulink
and Stateflow mission and flight profile models enabled us to accurately estimate motor
current demands for ailerons and other components on specific aircraft (Figure 3).
For our reliability tests, we generated aircraft-specific motor current demands based
on the flight profile simulation results. We use
environmental chambers that vary the pressure and temperature. For example, the ambient temperature in Boston is much lower than
that of Dubai in summer, and our tests must
take that into account. With the environmental chambers, we can expose the systems to
temperatures of -55 Celsius and pressures of
less than 0.2 bar. Long-term reliability tests
representative of 150,000 flight hours require
careful monitoring and thorough analysis of
the results. We conduct this monitoring and
data analysis in MATLAB.
FIGURE 4. Plots showing power dissipation over time for an IGBT 3-phase bridge (top) and
SiC MOSFET 3-phase bridge (bottom).
MathWorks News&Notes | 2 0 1 6 2 0 1 7
10
MathWorks News&Notes | 2 0 1 6 2 0 1 7
ike other advanced driver assistance systems (ADAS), an AEBS uses input from sensors to screen the environment. When a collision is imminent, the system warns the driver
with an audio alarm. If the driver does not respond, it applies a warning brake. If the driver
still does not respond, the system applies the
brakes fully to avoid the collision (Figures 1a
and 1b). The AEBS also provides brake assist: When the driver brakes, but with insufficient force to avoid a collision, the system
calculates and then applies the required extra
braking force.
AEBS uses both radar and camera sensors mounted on the front of the vehicle to
scan for objects in the area ahead. The system leverages the particular strengths of each
sensor to gain a more precise environment
model. Radar sensors excel at determining
an objects range, relative velocity, and solidity but are less able to determine its shape or
lateral position. A system using radar alone
would find it difficult to distinguish a car
parked at the side of the road from one in the
drivers lane. Cameras, on the other hand, can
pinpoint an objects size and lateral position
but do not detect range well and are unable
to assess density (a dense cloud may be perceived as a solid object).
My colleagues and I built a sensor fusion
system that matches and merges data from
both sensors into a single object. The system
uses four weighted propertieslongitudinal
speed and position and lateral speed and positionto calculate the probability that both
sensors have detected the same object. Once
the sensor fusion system has identified an object in the host vehicles path, it passes the ob-
FIGURE 1B. A typical AEBS scenario: truck with AEBS installed approaching a slow-moving vehicle.
MathWorks News&Notes | 2 0 1 6 2 0 1 7
11
FIGURE 2. Simulink model of the sensor fusion system showing independent functional blocks.
12
MathWorks News&Notes | 2 0 1 6 2 0 1 7
FIGURE 5. The Situation Classification Assistant Module, a MATLAB based tool for processing
logged ECU data and automatically identifying situations relevant to emergency braking.
LEARN MORE
Radar System Modeling and Simulation for
Automotive Advanced Driver Assistance
Systems 26:00
mathworks.com/video-107121
mathworks.com/video-92771
MathWorks News&Notes | 2 0 1 6 2 0 1 7
13
14
MathWorks News&Notes | 2 0 1 6 2 0 1 7
FIGURE 1. The underside of the e-longboard showing two BLDC motors on the left.
MathWorks News&Notes | 2 0 1 6 2 0 1 7
15
boards range. It wasnt long before the students were competing to see who could
deplete the batteries fastest by maintaining
the top average speed. Following test runs,
Kevin post-processed metrics captured during the runs. To visualize the e-longboards
speed response, for example, he created a
combined graph of desired speed and actual
speed in MATLAB (Figure 4).
Next Steps for the Student and
the Course
When Kevin completed his studies at HS
Bochum he began working for an engineering company that uses Model-Based
LEARN MORE
Simulation of FOC Using PMSM Model
mathworks.com/foc-pmsm
FIGURE 2. Simulink model for simulating field-oriented control with a permanent magnet synchronous machine.
16
MathWorks News&Notes | 2 0 1 6 2 0 1 7
to measure rotor position, which is a key input to both the field-oriented control and the
boards speed control loop.
Kevin based his controller design on an
example field-oriented control project from a
MathWorks webinar. The example included a
Simulink model for controlling the speed and
torque of a three-phase permanent magnet
synchronous machine (PMSM), which was
modeled using Simscape Power Systems
(Figure 2). We found the example to be a good
implementation of field-oriented control.
After downloading the example project
from mathworks.com, Kevin modified the
parameters for the e-longboard, removed
unneeded parts, and added features. After
running simulations in Simulink, Kevin used
Embedded Coder to generate C code for
the boards TI F28069 microcontroller. At
that point, he began evaluating the real-time
response of the system to see if it met the realtime requirements he had established.
Kevin and Raphael worked largely on
their own, meeting me once a week so that I
could monitor their progress. On this project, Kevin applied and expanded the basic
knowledge of Model-Based Design with
MATLAB and Simulink that he had acquired in earlier control design electives at HS
Bochum. He relied on technical support from
MathWorks to resolve any technical issues that
he encountered, and that enabled him to work
with surprisingly little assistance from me.
Once the printed circuit board was ready
(Figure 3) and the rest of the e-longboard had
been constructed, Kevin and his classmates
began testing the board in and around the HS
Bochum campus.
Kevin rode around a nearby lakea
distance of more than 25 kmto test the
FIGURE 4. Plot of desired speed (pink) and actual speed (yellow) showing how closely the
two matched during a test run.
MathWorks News&Notes | 2 0 1 6 2 0 1 7
17
18
MathWorks News&Notes | 2 0 1 6 2 0 1 7
FIGURE 1. Left: Diego Velzquezs Portrait of Pope Innocent X. Right: Francis Bacons
Study After Velzquezs Portrait of Pope Innocent X.
techniques. We began by testing support vector machines (SVMs) and other classification
algorithms in Statistics and Machine Learning
Toolbox to identify visual features that are useful in style classification. In MATLAB, we then
applied distance metric learning techniques to
weight the features and thereby improve the
algorithms ability to classify paintings.
The algorithms we developed classified the
styles of paintings in our database with 60%
accuracy, where chance performance would
have been about 2%. While art historians can
perform this task with much more than 60%
MathWorks News&Notes | 2 0 1 6 2 0 1 7
19
FIGURE 2. Left: Frederic Bazilles Bazilles Studio; 9 rue de la Condamine. Right: Norman Rockwells Shuffletons Barbershop. Yellow circles
indicate similar objects, red lines indicate similar composition, and the blue rectangle indicates a similar structural element.
20
MathWorks News&Notes | 2 0 1 6 2 0 1 7
FIGURE 3. Computed creativity scores (y-axis) for paintings from 1400 to 2000 (x-axis), showing selected highest scoring paintings for
individual periods.
LEARN MORE
Machine Learning with MATLAB 41:26
mathworks.com/video-81984
MathWorks News&Notes | 2 0 1 6 2 0 1 7
21
techniques for decades to detect objects of interest in images and to classify or identify categories of objects.
They extract features representing points, regions, or objects of interest and then use those features to train a
tbl = countEachLabel(imds)
ismatrix(I)
I = cat(3,I,I,I);
end
n traditional machine learning, feature selection is a time-consuming manual process. Feature extraction usually involves processing each image with one or more image processing operations, such
as calculating gradient to extract the discriminative information
from each image.
Enter deep learning. Deep learning algorithms can learn features,
representations, and tasks directly from images, text, and sound, eliminating the need for manual feature selection.
Using a simple object detection and recognition example, this article illustrates how easy it is to use MATLAB for deep learning, even
without extensive knowledge of advanced computer vision algorithms
or neural networks.
Getting Started
The goal in this example is to train an algorithm to detect a pet in a
video and correctly label the pet as a cat or a dog. Well be using a
convolutional neural network (CNN), a specific type of deep learning algorithm that can both perform classification and extract features
from raw images.
To build the object detection and recognition algorithm in MATLAB,
all we need is a pre-trained CNN and some dog and cat images. Well use
the CNN to extract discriminative features from the images, and then
use a MATLAB app to train a machine learning algorithm to discriminate between cats and dogs.
22
MathWorks News&Notes | 2 0 1 6 2 0 1 7
websave('\networks\imagenet-caffe-alex.mat',...
imagenet-caffe-alex.mat');
end
'randomize');
'http://www.vlfeat.org/matconvnet/models/beta16/
countEachLabel(imds)
convnet.Layers
Weve stored the images in separate cat and dog folders under a parent
called pet_images. The advantage of using this folder structure is that
the MATLAB imageDatastore we create will be able to automatically
read and manage image locations and class labels. (imageDatastore
is a repository for collections of data that are too large to fit in memory.)
(filename);
0.3, 'randomize');
MathWorks News&Notes | 2 0 1 6 2 0 1 7
23
w1 = convnet.Layers(2).Weights;
% Scale and resize the weights for visualization
w1 = mat2gray(w1);
w1 = imresize(w1,5);
% Display a montage of network weights. There are 96
% individual sets of weights in the first layer.
figure
montage(w1)
title('First convolutional layer weights')
Notice that the first layer of the network has learned filters for capturing blob and edge features. These primitive features are then processed by deeper network layers, which combine the early features to
form higher-level image features. These higher-level features are better
suited for recognition tasks because they combine all the primitive features into a richer image representation. You can easily extract features
from one of the deeper layers using the activations method.
The layer right before the classification layer fc7 is a good place to
start. We extract training features using that layer.
featureLayer = 'fc7';
trainingFeatures = activations(convnet, ...
24
MathWorks News&Notes | 2 0 1 6 2 0 1 7
The Classification Learner app in Statistics and Machine Learning Toolbox lets us train and compare multiple models interactively (Figure 3).
Alternatively, we could train the classifier in our MATLAB script.
We split the data into two sets, one for training and one for
testing. Next, we train a support vector machine (SVM) classifier
using the extracted features by calling the fitcsvm function using
trainingFeatures as the input or predictors and trainingLabels
as the output or response values. We will cross-validate the classifier on
the test data to determine its validation accuracy, an unbiased estimate
of how the classifier would perform on new data.
LEARN MORE
Deep Learning for Computer Vision with MATLAB 36:50
mathworks.com/video-116080
1-cvmdl.kfoldLoss)
MathWorks News&Notes | 2 0 1 6 2 0 1 7
25
f
or (i2 = 0; i2 < 4;
i2++) {
c[i0 + 3 * i1] +=
#include "myMult.h"
function c = myMult(a, b)
void myMult(const double a[12],
% Multiply two inputs
c = a * b;
{
int i0;
int i1;
int i2;
for (i0 = 0; i0 < 3; i0++) {
#include "myMult.h"
26
MathWorks News&Notes | 2 0 1 6 2 0 1 7
FIGURE 2. Left: Automated checks for features and functions not supported for code generation. Right: Automated analysis and proposal for input data
type and sizes.
f
or (i1 = 0; i1 < 5; i1++)
MathWorks News&Notes | 2 0 1 6 2 0 1 7
27
compiled it into a DLL, which was then integrated into their C# ap-
28
MathWorks News&Notes | 2 0 1 6 2 0 1 7
tions of your MATLAB code by generating a MEX function that calls the compiled C/C++ code.
int i2;
for (i0 = 0; i0 < 3; i0++) {
for (i1 = 0; i1 < 5; i1++) {
c[i0 + 3 * i1] = 0.0;
for (i2 = 0; i2 < 4; i2++) {
c[i0 + 3 * i1] += a[i0 +
3 * i2] * b[i2 + (i1 <<
2)];
}
}
}
}
diagnose injury.
VivaQuant generated fixed-point C code from heart rhythm monitoring algorithms and compiled it for an ARM Cortex-M processor.
f
or (i3 = 0; i3 < loop_ub;
i3++) {
planeHist_data[i3] =
originalHist_data[plane +
originalHist_size[0] * i3];
}
int i0;
int i1;
originalImage->size[i1];
}
N = sz[0];
M = sz[1];
normalizer = (L - 1.0) /
((double)sz[0] * (double)sz[1]);
#pragma omp parallel for \
num_threads(omp_get_max_threads()\
) private(s,r,planeHist_data,\
loop_ub,i3,y,x,j,d0,u0)
for (plane = 0; plane < 3;
plane++) {
loop_ub = originalHist_size[1];
LEARN MORE
Generating C Code from MATLAB
(download)
mathworks.com/fx-56270
MathWorks News&Notes | 2 0 1 6 2 0 1 7
29
CLEVES CORNER
logo_wave. The MathWorks logo is the solution to the wave equation, a foundation of mathematical physics. MathWorks is the only
company in the world whose logo is the solution to a partial differential equation. This program demonstrates the vibration of a membrane stretched over an L-shaped region.
T puzzle image courtesy of Shop New Zealand www.shopnewzealand.co.nz Shop New Zealand
30
MathWorks News&Notes | 2 0 1 6 2 0 1 7
of fire grows until its radius is just large enough for all the oxygen
available through the surface to be consumed by combustion in the
interior. The equation for the radius is rdot = r^2 - r^3. The problem
becomes stiff as the radius approaches its limiting value.
MathWorks News&Notes | 2 0 1 6 2 0 1 7
31
CLEVES CORNER
eigsvdapp. With this program you can watch how MATLAB handles three different matrix eigenvalue problems: the eigenvalues of a
nonsymmetric matrix, the eigenvalues of a symmetric matrix, and
the singular values of any matrix. Watch the reduction to Hessenberg, tridiagonal, or bidiagonal form, then the QR iteration to obtain
Schur or diagonal form.
golden_spiral. In this program you can see a continuously expanding sequence of golden rectangles and inscribed quarter circles.
tictactoe. This program combines three games that initially appear to be unrelated: Pick15, TicTacToe, and Magic3. In Pick15, the
object is to generate a total of 15 using exactly three digits, where
each digit can be chosen only once. TicTacToe follows the traditional
game, but replaces Xs and Os with blue and green. The object is to
get three in a row, column, or diagonal. Magic3 superimposes a magic square of order three on TicTacToe to show that Pic15 is actually
the same game.
32
MathWorks News&Notes | 2 0 1 6 2 0 1 7
LEARN MORE
Cleve's Laboratory App
(download)
mathworks.com/cleves-lab
blogs.mathworks.com/cleve
mathworks.com/cleves-corner
MathWorks News&Notes | 2 0 1 6 2 0 1 7
33
TECH SPOTLIGHT
2. An analytic IoT platform processes and stores the sensor data. It
may integrate information from other sources, such as business
systems. It analyzes and takes action on the incoming data.
3. A systems engineer or data scientist accesses the historical data
from the cloud or the device and develops algorithms to preprocess and analyze it. These algorithms may involve machine learning techniques for predicting future values of a sensor quantity or
for classifying the sensor data.
4. The algorithm is deployed in the cloud or on a smart device, where
it operates on incoming live data.
Creating an IoT System with MATLAB and Simulink
MATLAB and Simulink support IoT systems by helping you develop and test smart connected devices, access and collect data in the
cloud, and analyze sensor data. Lets look at two examples.
34
MathWorks News&Notes | 2 0 1 6 2 0 1 7
depth, and write the data to a new ThingSpeak channel. The result
was an internet-connected tide gauge that can be viewed on a mobile
phone or a web browser (Figure 6).
The boater set up additional MATLAB code to detect tidal thresholds. He then used the Twitter integration in ThingSpeak to send
alerts when particular conditions were met.
As these examples show, analytics is a vital ingredient of the innovations occurring in IoT. With MATLAB and Simulink you can
develop analytics that run on your smart devices or in the cloud.
With ThingSpeak, you can easily collect data from your devices in
the cloud. You can then use MATLAB to gain insight into the sensor
data you have collected.
LEARN MORE
Developing Internet of Things Systems with MATLAB
mathworks.com/iot
ThingSpeak
thingspeak.com
MathWorks News&Notes | 2 0 1 6 2 0 1 7
35
WHAT IF EVERYONE
THIRD-PARTY PRODUCTS
MATLAB and Simulink provide a platform for engineers to explore images, develop computer vision algorithms,
and evaluate implementation tradeoffs. Third-party imaging hardware enables them to acquire visible, thermal, depth,
microscopy, and a range of other images. Engineers can analyze images, via live acquisition or by postprocessing
in MATLAB, and then deploy computer vision applications such as object detection, tracking, and recognition onto
embedded processors, FPGAs, multicore GPU systems, and other hardware.
More than 1 million students and 700 universities around the world
including the top 10 ranked universitieshave unlimited access to MATLAB and
Simulink with a Total Academic Headcount (TAH) license.
Xilinx Zynq-7000
All-Programmable SoC
The Xilinx Zynq-7000 All-Programmable
SoC combines a dual-core ARM Cortex-A9
with Xilinx 7-series FPGA logic on a single
chip. As a result, users can integrate camera
control and image processing functions in a
single device while enabling hardware acceleration of video analytics. Evaluation kits include
hardware I/O, design tools, IP, and pre-verified
reference designs. MATLAB, Simulink, HDL
Coder, Embedded Coder, and Vision HDL
Toolbox support the design and simulation of
image processing applications and automated
deployment to the Zynq device.
xilinx.com/zynq
42,000
JOB OPPORTUNITIES
82%
Hardware Support
mathworks.com/hardware
LEARN MORE
HANDS-ON LEARNING
RESEARCH PRODUCTIVITY
1,970,000
Google Scholar results referencing MATLAB
mathworks.com/solutions/image-video-processing
mathworks.com/matlab-campus
36
MathWorks News&Notes | 2 0 1 6 2 0 1 7
MATLAB SPEAKS
ARDUINO
so you dont have to
92984v00 11/16