Search icon
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Learning Hub
Free Learning
Arrow right icon
Over 7,000 tech titles at $9.99 each with AI-powered learning assistants on new releases
Getting Started with Simulink
Getting Started with Simulink

Getting Started with Simulink: Written by an experienced engineer, this book will help you utilize the great user-friendly features of Simulink to advance your modeling, testing, and interfacing skills. Packed with illustrations and step-by-step walkthroughs.

By Luca Zamboni
$22.99 $9.99
Book Oct 2013 132 pages 1st Edition
$22.99 $9.99
$15.99 Monthly
$22.99 $9.99
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now
Table of content icon View table of contents Preview book icon Preview Book

Getting Started with Simulink

Chapter 1. Simulink Facts

In this chapter, we'll explain what Simulink is, and why it has been so widely adopted in the academic and the industrial world.

After reading this chapter, you'll have learned about the limits of the usual C software development cycle, and how Simulink helps to address these limits.

What is Simulink?

Simulink is best described as a graphical programming tool. Let's elaborate a little on these two words.


Since the start of the digital era, telling a computer what to do has been a huge problem. Humans communicate through a set of conventions—languages—with very elaborate rules, definitions, and exceptions. New languages aren't easily born in the human world. But what about computers? They operate by means of a stream of zeros and ones, using Boolean logic; that's the binary system. The computer language is nowhere as complex as the human language, but how fast are computers at solving logical problems! The difficulty is in telling the computer how to solve a given problem, and this is the art of programming.

Nowadays there are so many programming languages that knowing at least one is as common as knowing more than one human language. Those lucky ones who do are called programmers. They're able to write the instructions that a computer has to execute (and the computer understands them—well, most of the time).

Writing and debugging a complex, real-time, safety-critical application is not a trivial task, and in big automotive/aerospace industries, a misbehaving software is definitely not an option. As an example, the 327.6 million dollars NASA Mars Climate Orbiter space probe disintegrated before landing because the ground control software used the imperial metric system instead of the international one. It sounds funny, but imagine what would happen if your car maker made such a mistake in the brake control software?

The problem with using the venerable, almighty C—still the language of choice for embedded systems—is that it isn't easy to scale up the system complexity. It's interesting to note that while the system gets bigger, the deadlines get narrower. The good old tools (code editors, compilers, and debuggers) aren't effective anymore to keep the whole development time constant while raising the software requirements.


This is the next step.

Imagine an Italian guy in Moscow willing to buy a bottle of water. Chances are that he doesn't know one word of Russian, nor the Russian shop owner knows more than two words of Italian (bella and ciao).

Our Italian guy would likely point at a bottle of water with his finger and mimic the act of drinking. The Russian shop owner would smile to acknowledge the request, and then use his fingers (or pencil and paper) to communicate the price to pay.

So what? We had visual communication. The simplest of all languages are the visual ones.

When a programmer tries to explain to his manager how a code works, he usually starts drawing blocks on a piece of paper—something like the following oversimplified example:

It isn't hard to understand that the logic flows from left to right (because of the arrows), and that two inputs will be multiplied together to obtain the output. With nothing more than a simple glance, you've understood what the computer has been programmed to do.

Let's compare it with a warning-free, standards-compliant C code:

#include <stdio.h>
#include <stdlib.h>

int mul(int, int);

int main()
    int u1, u2, y1;
    printf("Enter two numbers\n");
    scanf("%d%d", &u1, &u2);
    y1 = mul(u1, u2);
    printf("Here's your result,the operation done is a shining 'x'!\n%d\n", y1);
    return EXIT_SUCCESS;

int mul(int input1, int input2)
    return input1*input2;

Now chances are one of the following:

  • You know C, and you understood what the code does after reading through it

  • You don't know C, but you know other programming languages; maybe you haven't understood every line, but you are still able to figure out what the program does

  • You don't know any programming language; you're almost clueless and you understand what's going on only because you've seen the figure first

Either way, a visual representation of the code is much easier to understand and maintain.

Now imagine a long (several hundred lines), complex (tens of source files) code, poorly commented, highly optimized for a certain processor architecture, edited by several people without a strict style policy—the classic spaghetti code that many programmers are faced with in their job. They'll spend a huge amount of time understanding what the code does, no matter how skilled they are. Explaining that code to a colleague who doesn't know programming is out of the question.

That's where visual programming comes the rescue. A graphical programming tool can save countless hours of work in a job where explaining the code is as important as a code without bugs, or where a bug can have disastrous (safety-critical) effects.

Simulink is such a tool.

Problems solved by Simulink

Simulink is a true life saver in large companies manufacturing safety-critical products, or where the software development is usually split into three different phases:

  • Specification phase: The algorithm is planned or updated by the specification team and a new specification is released

  • Development phase: The algorithm is implemented by the development team and a software release is made

  • Testing phase: The software undergoes an extensive testing phase both on simulated and on real hardware; only when the test results are positive, the testing team states that the software is ready for production

Software specification

In every software project where safety is an issue, the software development starts only when a stable specification has been released.

Specifications are usually written as text documents where each sentence describes an atomic requirement and must be highly detailed.

The problem with specifications as text documents is that there isn't any way of verifying the correctness of the specified logic until the development phase or even the testing phase.

Every time that the specification is found to be incorrect or incomplete, the specification team must be notified and must make a new release. So the development team has to develop the new release, likewise the testing team will have to test the new software.

A specification error is one of the worst things that can happen in a big manufacturing company, often leading to production delays, while underspecified software can lead to unwanted behavior.

Simulink can be used to achieve the goal of writing correct and complete specifications, without losing anything in readability. Let's consider the following atomic requirement:


If InputSignal is greater than 0, the InputSignalFlag variable must be set.

The corresponding Simulink block would be as follows:

What's the real deal? It is that you can test the requirement before it's released. With Simulink, it's easy to generate input signals and register the output as shown in the following diagram:

When viewing the display on Scope, the result will look like the following diagram:

But wait! Let's examine the textual requirement; it says that the flag must be set. It's unclear (not specified) whether the InputSignalFlag variable should be reset when InputSignal becomes 0 or less than 0.

But the difference is very clear in a specification done with Simulink. The following is the block diagram that describes the requirement with the InputSignalFlag variable remaining set until the end of the execution cycle:

We can see that the simulation result is very different from the previous one, as seen in the following diagram:

With textual requirements, there's always a gray area due to the fact that human languages, despite their richness (or because of it), have problems in describing a Boolean logic. And it's extremely difficult, if not impossible, to test the requirement before the release.

With Simulink models as requirements, there is no room for doubt. The requirement is complete and easily understandable by nonprogrammers, and a preliminary test can be made with little to zero effort by the very same team that wrote it.

Software development

The development team has the responsibility of maintaining and updating the software for a certain project or series of projects. The usual work flow for the embedded C developer of an automotive industry is shown in the following diagram:

The first problem developers are faced with is the code itself. A well-commented code with strict coding-style guidelines will be easily understandable and maintainable, but sadly, that's not the common situation. Code maintainability is a major issue almost everywhere, strictly dependent on code readability.

The second problem is the formal code-correctness checking. This means doing a static code analysis to check compliance with one or more sets of formal rules (for example, the MISRA-C rule set).

The third and the most important problem is code debugging. This is done by running the code to do an early testing (for example, with valgrind) and applying well-known input patterns to detect and correct the blocking bugs.

Simulink helps the pressed developer solve these problems in the following ways:.

  • Code readability: Being a graphical development tool, developers have an intuitive way of dividing the code into multilayered virtual blocks. The topmost layers give a representation of the functionality subsets implemented, while the lower layers contain the code primitives (logical and mathematical operators, memories, state machines, and so on).

  • Static code analysis: By using Simulink with code generation software (Simulink coder—formerly Real-Time Workshop—and DSpace TargetLink are the most popular), it is possible to produce error-free embedded C code. They guarantee that the produced code offers the same functionality described in the model.

  • Code debugging: During model development, Simulink offers the option to do an early testing; the developer can apply an input pattern to a well-known problematic algorithm and visualize the simulation result, inspect every signal, do a step-by-step debug, and stop the simulation on selected events on the same model used for code generation.

By using Simulink, the development team can apply the required updates in a shorter time and use the remaining time to perform a quick preliminary testing of the code.

Static code analysis becomes almost irrelevant since coding rules and conventions are enforced by the code generation software.

Finally, with the autogenerated code being free of syntax errors, the compilation phase is usually straightforward. This greatly helps the programmer who is not familiar with the C syntax.

Software testing

The released code needs an extensive testing phase before being put into production. The testing team's objective is to confirm that the software is compliant with the specifications.

This usually involves breaking the specifications into atomic requirements and having one or more test cases for each requirement (the so-called functional testing), or defining what should never happen and automatically apply every possible combination of inputs to the software component (a subset of destructive testing).

By using Simulink models, the testing team can easily perform automatic model-in-the-loop (MIL) testing on their computers; the logical correctness is demonstrated by applying inputs to the Simulink models and comparing the outputs to the expected behavior. MIL testing easily spots failures in a very short time and generates a detailed test report, even pinpointing the model block where the problem resides. MATLAB already has everything needed to perform an MIL test, while automated tests can be coded using the MATLAB scripting language.

Once the MIL testing is successful, the software-in-the-loop (SIL) testing is performed by running the autogenerated code on standard computers. It is usually aimed at finding discrepancies between the model and the code behaviors, and it requires another software monitoring the process's I/O or the inclusion of debug headers into the tested code, or a mixture of both.

The next testing step is the processor-in-the-loop(PIL) testing, where the software is programmed into the target processor and debugged via an external high-speed bus connected to a standard computer, such as a JTAG connection. Of course this requires having the target processor available on a board with a testing connection.

The last step is to perform hardware-in-the-loop (HIL) testing, which is running the software on the target hardware connected to a real-time system. It requires a custom test bench to be purchased or made internally, and some test steps have to be executed manually.

The biggest advantage of MIL testing is to reduce the number of times SIL, PIL, and HIL tests are performed. This is because most of the problems are caught during the fast, nonexpensive MIL tests, thereby reducing the overall time spent to generate, build, and validate the produced code.

Simulink drawbacks

Simulink isn't the way to go for small projects with a low budget: a MATLAB license is rather expensive: like the additional packages that may be required for testing on dedicated hardware. It is suited for big projects with a large number of developers working on them. A skilled C developer can write code for simple to trivial projects in a much shorter time than by dragging blocks in Simulink.

MATLAB and Simulink are targeted specifically to engineering and scientific applications; they aren't general-purpose-programming tools. It's difficult, though not impossible, to develop desktop applications or web services using Simulink.

Finally, it's hard to track model changes with software versioning and revision control systems (such as CVS, SVN, Git, Bazaar, or Mercurial). While, to a certain degree, it is possible to spot the differences when saving models with the .mdl format (because it's a structured text file), this has become difficult with the .slx format (a zipped archive with more information on the model). To see and highlight the differences between two versions of the same model, separate software has to be purchased.

Where Simulink excels

There are two main use cases for Simulink.

The first one is in the academic research world where Simulink is used to simulate multidomain dynamic systems. Typically, Simulink is used in a continuous-time environment with variable step-size implicit solvers; the main scope of the simulation is to reproduce the behavior of a real system in order to predict the answer to the applied stimuli.

The second one is in the automotive, aerospace, avionics, and the defense industry where Simulink is used to build models for real-time, safety-critical, embedded targets with many people involved in the specification, development, and testing phases. The main scope of the simulation is to find and correct bugs in order to produce (through the appropriate code-generation software) a final C code to compile in the target processor. The simulation solver used in this environment is the fixed-size step explicit one, and the model doesn't contain any continuous states.


In this chapter we learned what benefits Simulink brings in and where Simulink has become a de-facto standard and why. We explained how the software development process is simplified using Simulink and cases where Simulink is not the right solution. After reading this chapter, you should be able to decide whether Simulink can be used for your projects.

In the following chapters, we'll take a learn-by-doing approach where we'll go through the whole software development process while developing and testing a cruise controller model for a real-world car.

Left arrow icon Right arrow icon

Key benefits

  • Dig deep into Simulink
  • No unnecessary theory - start modelling right away
  • Complex concepts made easy through examples
  • Packed with illustrations and detailed step-by-step walkthroughs


Simulink is an engineer's Swiss army knife: instead of spending the day typing out complex formulas, Simulink enables you to both draw and execute them. Block after block, you can develop your ideas without struggling with obscure programming languages and you don't have to wait to debug your algorithm - just launch a simulation! Getting Started with Simulink will give you comprehensive knowledge of Simulink's capabilities. From the humble constant block to the S-function block, you will have a clear understanding of what modelling really means, without feeling that something has been left out. By the time you close the book, you'll be able to further extend your modelling skills without any help. We''ll start with a brief introduction, and immediately start placing the first blocks. Little by little, you'll build a car cruise controller model, followed by the mathematical model of a sports car in order to calibrate it. Then you'll learn how to interface your Simulink model with the external world. This book will give you an easy understanding of the tools Simulink offers you, guiding you through a complex exercise split into the three main phases of Simulink development: modelling, testing, and interfacing.

What you will learn

Understand the pros and cons of Simulink Describe your ideas using block diagrams Tune your simulation parameters Draw clean, uncluttered models by reusing the logic and subdividing it into inner blocks Run simulations with the appropriate source blocks Analyse the simulation results with the scope block Implement S-functions to reuse legacy code Interface Simulink with applications outside the MATLAB environment

Product Details

Country selected

Publication date : Oct 25, 2013
Length 132 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782171386
Vendor :
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details

Publication date : Oct 25, 2013
Length 132 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782171386
Vendor :
Languages :
Concepts :

Table of Contents

11 Chapters
Getting Started with Simulink Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. Simulink Facts Chevron down icon Chevron up icon
2. Creating a Model Chevron down icon Chevron up icon
3. Simulating a Model Chevron down icon Chevron up icon
4. Using the Model Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by

No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial


How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to
  • To contact us directly if a problem is not resolved, use
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.