Jiro's pick this week is legappend by Chad Greene. Chad is no stranger to MATLAB Central. He has over 50 File Exchange entries, and two of his entries have been highlighted (unit converters and ccc) in Pick of the Week. His entries... read more >>

]]>Jiro's pick this week is `legappend` by Chad Greene.

Chad is no stranger to MATLAB Central. He has over 50 File Exchange entries, and two of his entries have been highlighted (unit converters and ccc) in Pick of the Week. His entries are well-written, and like this one, many of his entries have published example files.

Many of you may know that the command `legend` creates one legend per axes.

t = 0:.1:10; x1 = sin(t); x2 = cos(t); plot(t,x1,t,x2) legend('Sine','Cosine')

Let's say that you wanted to add another line to this plot.

x3 = sin(t).*cos(t); hold on plot(t,x3,'--r')

To add this entry to the legend, you would re-run the `legend` command with the three entries.

legend('Sine','Cosine','Sine*Cosine')

Chad's `legappend` allows you to append new entries to an existing legend. This means that you can simply call it along with the new lines you
create.

% New figure figure; plot(t,x1,t,x2) legend('Sine','Cosine') % Add another line hold on plot(t,x3,'--r') % Append a new legend item legappend('Sine*Cosine')

Great! You can also delete the last legend entry with the following command.

`legappend('')`

If you want to see more examples, check out his published example.

Chad explains that `legappend` simply deletes the current legend and recreates the updated legend. This is a good example of how you can take a normal mode
of operation and tweak it in order to adapt it to your needs.

Give it a try and let us know what you think here or leave a comment for Chad.

Get
the MATLAB code

Published with MATLAB® R2014a

Greg's pick this week is module - encapsulate MATLAB package into a name space module by Daniel Dolan. The concept of namespaces has been available in MATLAB for a number... read more >>

]]>Greg's pick this week is module - encapsulate MATLAB package into a name space module by Daniel Dolan.

The concept of namespaces has been available in MATLAB for a number of years at this point. While the technology is very mature at this point, a common feature of namespaces was not included in the MATLAB implementation. You cannot call one function in the same namespace from another function in the same namespace without including the namespace definition somewhere. Most namespaces in other languages permit functions to call each other within the namespace without needing to identify the namespace.

Daniel’s “MODULE” function provides an interesting means to work around that constraint using a method that demonstrates the powerful concept of function handles in MATLAB.

The nature of Daniel’s solution also provides a means to create namespace specifiers, without needing to continually reference the full namespace.

Finally Daniel makes it possible to have what one might call “dynamic namespaces”.

I selected this submission because it demonstrates the powerful feature of function handles, advertises the use of namespaces in MATLAB, and uses the “DBSTACK” function in a way that surprised me.

Yes, it happens. There’s what appears to be a bug in this File Exchange submission. Change line *110* from

`root=sprintf('%s.',root{:});`

to

`root=sprintf('%s.',root{end:-1:1});`

The order in which package namespaces is being constructed is backward. Changing this line reverses the construction and resolves the issue.

If you’re not familiar with namespaces, don’t fret. It is an advanced software engineering concept. I work with a lot of software engineers all over the world, and many of them are not familiar with namespaces because they work in coding languages or environments that don’t have them (such as C).

A namespace provides a means to specifically call unique functions that share the same name. I like to think of a namespace as a context or a classifier for a function.

Let’s say you have two functions, each named “myDisp”, but they have different behavior.

`>> myDisp('Hello')`

My Display 1 Hello

Versus

`>> myDisp('Hello')`

My Display 2 ------------- Hello

How do you invoke the appropriate *myDisp* at the correct time?

Perhaps you could give the functions different names: *myDisp* and *myDisp2*.

But if you’re concerned about modularity, and these functions are used independently in other projects and code files, changing the name of the functions will be problematic.

What if instead you could include an identifier that would make the call to the *myDisp* function more specific?

>> myFirstNamespace.myDisp('Hello') >> myOtherNamespace.myDisp('Hello')

Now both functions can be available, without introducing a name conflict, or needing to change the name of the function.

To accomplish this in MATLAB, you need to use package folders

While namespaces provide a means to be more specific about function calls, they can be inconvenient when it comes to actually writing them out, and reading them in the code file. Especially as the namespaces get longer.

`>> myMainNamespace.myOtherSubNamespace.myOtherNamespace.myDisp('Hello')`

This seems hard to read, and a pain to write.

We can use the IMPORT function to handle this:

```
>> import myMainNamespace.mySubNamespace.myFirstNamespace.*
>> myDisp('hello')
```

My Display 1 Hello

Now contents of the myFirstNamespace can be referenced without using the full namespace notation. But if you import two functions with the same name but live in different namespaces, you are back to the same problem that namespaces try to solve! You can partially import namespaces, but this gets tedious.

The MODULE function makes it possible to refer to functions in namespace by essentially providing an alias for the namespace. This means you can refer to functions deep within a namespace without needing to write out the full namespace, or have the potential conflict issues using the IMPORT function.

>> myLocalSpace = module('myMainNamespace.mySubNamespace.myFirstNamespace'); >> myLocalSpace.myDisp('Hello')

>> myOtherLocalSpace = module('myMainNamespace.myOtherSubNamespace.myOtherNamespace'); >> myOtherLocalSpace.myDisp('Hello')

Here the calls to the functions in the namespace are concise and specific to the desired function.

This also allows you to do fun things like make the namespace dynamic

if (a < b) myLocalSpace = module('myMainNamespace.mySubNamespace.myFirstNamespace'); else myLocalSpace = module('myMainNamespace.myOtherSubNamespace.myOtherNamespace'); end myLocalSpace.myDisp('Hello')

I cannot say at this point whether or not having dynamic namespaces is a good idea, but it is certainly an interesting concept.

In MATLAB, if a function in a namespace calls another function in the same namespace, it must refer to the full namespace of the function being called.

function myDisp( displayInput ) displayHeader = myMainNamespace.myOtherSubNamespace.myOtherNamespace.otherFunction; disp(displayHeader); disp(displayInput); end

This is fine, until later when you wrap the existing namespace in another parent namespace, and you must go into all of the functions and append the new parent namespace. If you have hundreds of functions, this is going to get old fast.

Daniel provides a really neat mechanism to get around this constraint. Calling MODULE with no inputs assumes the namespace you want is relative to the current function.

function myDisp( displayInput ) localNamespace = module; displayHeader = localNamespace.otherFunction(); disp(displayHeader); disp(displayInput); end

Now, even if the structure of the namespace changes, you can still call the functions local to the namespace, because the
local namespace is automatically updated when the *myDisp* function is called.

This is the part I think is really elegant.

In order to make this work, Daniel takes advantage of function handles. Function handles are pointers or aliases to functions. This means you can use a variable to store a reference to a function.

Daniel creates a collection of these function handles by creating function handles for each of the functions in a specific package folder. Then he stores these function handles in a MATLAB struct. Subreferencing the struct using the dot notation (struct.field) will now act like referencing a function in a namespace. How cool is that!

Finally, to get around the constraint MATLAB imposes of functions in a namespace referencing other functions in the same namespace, Daniel uses the DBSTACK function.

I’m pretty sure he’s using DBSTACK in a way it was never intended, but I think it’s absolutely brilliant!

Daniel uses the DBSTACK function to determine what function called MODULE, so he can then figure out what namespace the function belongs to.

While there may be some performance implications from using DBSTACK, it is an excellent demonstration of the flexibility of the MATLAB environment. You can ask a function “Who called you?” I’ve been working with MATLAB over 15 years now, and I didn’t realize you could do that!

If you would like to leave any comments regarding this post, please click here.

Get
the MATLAB code

Published with MATLAB® R2014a

Sean's pick this week is "C-MEX Programming Tutorial Examples" by Ilias Konsoulas. I spent the last few days at the 2014 SIAM conference in... read more >>

]]>Sean's pick this week is "C-MEX Programming Tutorial Examples" by Ilias Konsoulas.

I spent the last few days at the 2014 SIAM conference in Chicago manning the MathWorks booth with a few of our developers. We were asked many questions about the products, new features, life at MathWorks, and of course for t-shirts and rubik's cubes.

One of the questions I was asked was along the lines of: "How do I get started with MEX?". MEX, which is short for "MATLAB Executable", is compiled C/C++ or Fortran code with the appropriate MATLAB wrappers on it so that it can be called at the command line like any other MATLAB function. Personally, I haven't written any productive C/C++ code since high school about ten years ago. When I need C or C++ code, I develop the algorithm in MATLAB and then use MATLAB Coder to automagically generate equivalent C code.

I had found Ilias' submission a while ago and added it to the "to experiment with list". Now, it allowed me to answer this question while sounding knowledgable and getting the user started on his journey.

The submission comes with nine heavily commented C files that do simple matrix manipulations like summing and reshaping as well as a readme file that documents the package. The C files show the MEX syntax, required headers and some good programming practices like error checking.

Curious if I could actually write my own hand-written MEX file, I challenged myself to write one which calculates the sum
of the diagonal of a matrix. I started by editing Ilias' `transposeM.c` which should be a good blueprint.

After some time, having it fail to compile 20ish times, and getting stuck in an infinite loop only once(!), (I forgot to increment
*i* in the `for`-loop), it works!

Here's a snapshot of the file:

That was an exercise in frustration. How about we just use MATLAB Coder to do this? First, I wrote a MATLAB function to
calculate the sum of the diagonal; there happens to be a function called `trace` that does this:

Now to generate C code, you can use the MATLAB Coder App to generate code interactively, or do it programatically with `codegen`. I'll take the latter approach since it's easier to automate.

% Input must be a double precision matrix of size "up-to-inf" by "up-to-inf" input_specs = coder.typeof(zeros,inf,inf); codegen mytrace -args {input_specs}

This generates `mytrace_mex` which I can call like any other function.

rng(5) % reproducible X = gallery('randhess',7); % a matrix t = mytrace_mex(X); % use mex file disp(t)

-0.1573

Now let's see if the two C implementations and the MATLAB implementation agree using the MATLAB unit testing framework.

% Build interactive test object Tester = matlab.unittest.TestCase.forInteractiveUse; % Assert equality assertEqual(Tester,trace(X),traceM(X)) % My C implementation assertEqual(Tester,trace(X),mytrace_mex(X)) % MATLAB Coder's implementation

Interactive assertion passed. Interactive assertion passed.

Give it a try and let us know what you think here or leave a comment for Ilias.

Get
the MATLAB code

Published with MATLAB® R2014a

Jiro's pick this week is Useful Figure Management Utilities by Michelle Hirsch. One of the reasons I really enjoy programming in MATLAB is the interactive development environment (IDE). The various components allow me to be productive when... read more >>

]]>Jiro's pick this week is Useful Figure Management Utilities by Michelle Hirsch.

One of the reasons I really enjoy programming in MATLAB is the interactive development environment (IDE). The various components allow me to be productive when I'm developing an algorithm or analyzing some data. But what makes the environment even more powerful is the ability to programmatically customize some of the workflows. The 3 useful functions provided by Michelle help with managing your figure windows. The function names are self-explanatory, but here they are.

`figshift`- This is useful when you create a couple of figures and quickly want to be able to click back and forth between the two. Calling this function will shift the current figure window slightly from the previous window, allowing you to easily click between the two.`fillscreen`- As the name suggests, this "maximizes" the figure window to fill the whole screen.`showmethefigs`- This is my favorite. By calling this after you create all the figures, you can cycle through all the figure windows by hitting a key on your keyboard.

While you can use these functions directly from the Command Window, I find them most useful by sprinkling these within my script. This way, my figures will be placed appropriately at the end of the script.

surf(peaks) fillscreen figure plot(rand(10,3)) figure spy(bucky) figshift

**Comments**

This entry was so useful that it inspired Mirko to create "Figure Management Utilities" with additional functionality. Do you have any other favorite utilities that allow you to be more productive with the MATLAB IDE? Tell us about it here or leave a comment for Michelle.

Get
the MATLAB code

Published with MATLAB® R2014a

Idin's pick for this week is Configurable Simulink Model for DC-DC Converters with PWM PI Control by Yi Cao. Dr. Yi Cao has contributed a wealth of useful tools to... read more >>

]]>Idin's pick for this week is Configurable Simulink Model for DC-DC Converters with PWM PI Control by Yi Cao.

Dr. Yi Cao has contributed a wealth of useful tools to the File Exchange (I saw 66 at the time of this writing). This week’s Pick came in handy for me recently as I was trying to investigate and demonstrate the value of Simulink for modeling DC-DC converters .

Power management ICs (PMICs) are critical pieces of most electronic systems, especially battery-operated devices such as mobile phones and tablets. As it was put to me recently, “PMICs are equivalent to the devices that turn the lights on at power-up, and turn them off when powering down.” The PMIC provides required amounts of power to different parts of the system. An important part of a PMIC is typically one or more DC-DC converter to provide regulated voltages to different parts of a system.

In this submission Yi Cao provides a nice example of how the behavior of DC-DC converters can be modeled and simulated in Simulink. These converters fall under three general classes: buck, boost, and buck-boost (buck steps down the input voltage, boost steps it up, and buck-boost inverts the polarity). Yi’s example covers all three classes (using their classic topologies). The core of this submission is a Simulink model that shows how the whole system works.

This model is simulating a full closed-loop system. The converter needs to hold its output voltage constant as the amount of current being drawn varies. The control loop (and the PWM PI controller) work to correct fluctuations in output voltage (usually due to fluctuations in output current). He's done some good work to create one customizable block that can be configured to simulate any desired topology (buck, boost, or buck-boost).

A really nice feature of this submission is the included tutorial (PDF) on deriving the mathematical equations used in the model from circuit diagrams. I highly recommend reading through this document. And if there was any doubt that the derivations were correct, my colleague Dick Benson created a circuit-level model of the same system to check the results.

The results from the circuit simulation were nearly identical to those from Yi’s model. The figure below shows two plots: the output voltage and inductor current. In each plot the result of the circuit simulation is overlaid on top of the output from Yi’s model. The two traces can hardly be distinguished.

If you would like to see some examples of these systems simulated using real circuit elements, download the Mixed-Signal Library from the bottom of this page, and go to the “Switching Power” examples. Note that the examples using circuit elements require SimPowerSystems . As always, your thoughts and comments here are greatly appreciated.

Get
the MATLAB code

Published with MATLAB® R2014a

Sean's pick this week is `mcolon` by Bruno Luong.

Earlier this week there was a question asking how to most efficiently create a vector from multiple colon subscripts, a common enough task. For example:

% Starting index startidx = [1 4 pi] % Stride between each start and ending index stride = [1 -1 pi] % Ending index endidx = [6 0 pi^2]

startidx = 1.0000 4.0000 3.1416 stride = 1.0000 -1.0000 3.1416 endidx = 6.0000 0 9.8696

```
% Desired result
disp(v)
```

1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 4.0000 3.0000 2.0000 1.0000 0 3.1416 6.2832 9.4248This can be accomplished with a simple

To compile the MEX file, you can call the provided

And now the calling syntax:

v = mcolon(startidx,stride,endidx).'; disp(v)

1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 4.0000 3.0000 2.0000 1.0000 0 3.1416 6.2832 9.4248

Jiro's pick this week is cspy by Hugo Gualdron. spy allows you to visualize sparse matrices: spy(bucky) (Anyone know how to get the Easter egg for the spy function?) spy is meant for displaying the... read more >>

]]>Jiro's pick this week is `cspy` by Hugo Gualdron.

`spy` allows you to visualize sparse matrices:

spy(bucky)

(Anyone know how to get the Easter egg for the `spy` function?)

`spy` is meant for displaying the positions of the nonzero elements in the sparse matrix. But if the sparse matrix contains multiple
values (levels), it would be nice to visualize those levels as well. That's where `cspy` comes in. Take the following example:

BW = logical ([... 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0]); imshow(BW,'InitialMagnification','fit')

In the above black and white image, we can say that there are 3 white blobs. We can use the `bwlabel` function from the Image Processing Toolbox to identify the 3 regions and mark them with unique identifiers.

L = bwlabel(BW)

L = 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 2 0 0 0 0 1 1 0 0 0 3 0 0 1 1 1 0 0 3 0 0 1 1 0 0 0 3 0 0 1 0 0 0 3 3 0 0 0 0 0 0 0 0 0

You could imagine that this matrix `L` can be a highly sparse matrix with far more zeros than non-zero elements. Let's store this as a sparse matrix.

Ls = sparse(L)

Ls = (4,2) 1 (5,2) 1 (6,2) 1 (7,2) 1 (4,3) 1 (5,3) 1 (6,3) 1 (5,4) 1 (2,5) 2 (3,5) 2 (2,6) 2 (7,6) 3 (4,7) 3 (5,7) 3 (6,7) 3 (7,7) 3

Even for this small example, you can see some memory savings.

whos L Ls

Name Size Bytes Class Attributes L 8x8 512 double Ls 8x8 328 double sparse

Now, we can use `cspy` to visualize `Ls` with different colors for the different values.

figure cspy(Ls)

Wonderful!

In addition to this useful functionality, I really like the great help that's included. The function has a number of optional parameters to customize the plot, and Hugo explains each syntax in detail. He also includes a number of examples.

**Comments**

Do you work with sparse matrices? Do you have any custom visualizations for them? Let us know about them here. Or give `cspy` a try and leave a comment for Hugo.

Get
the MATLAB code

Published with MATLAB® R2014a

This week, Brett revisits the historical quest for a circle detection algorithm, and pays tribute to the File Exchange files and authors that led to MathWorks' to offer our own officially supported circle detection algorithm.I’ve been supporting MATLAB users as an application engineer for nearly 10 years now, and writing... read more >>

]]>This week, Brett revisits the historical quest for a circle detection algorithm, and pays tribute to the File Exchange files and authors that led to MathWorks' to offer our own officially supported circle detection algorithm.

I’ve been supporting MATLAB users as an application engineer for nearly 10 years now, and writing about files on the MATLAB Central File Exchange for nearly as long. In my role at MathWorks, I get to talk to people frequently about how they use our tools, and about how they would *like* to use our tools in ways that are not “officially” supported. It's part of my job to feed that information back to our developers, and it helps them to decide where they should be spending their development efforts.

Back in May, 2008, I wrote about the difficulty of detecting circles in images using MATLAB; people asked for that capacity often, but we had no in-product tools to facilitate that detection process. Tao Peng's File Exchange submission was my go-to recommendation whenever customers asked.

Partly because you asked so often, and partly because Tao's solution was so popular, we finally introduced in 2012 a couple of different Hough transforms for circle detection; if you haven't used it, `imfindcircles` now makes easy work of the difficult task of finding circles in images.

If you need to detect circles in images, and if you have the Image Processing Toolbox, `imfindcircles` will be your friend; it's fast, and flexible. (I haven't seen a robust solution that works independently of that Toolbox. Correct me, please, if I've overlooked something.)

Also, if you have a compelling use case for a generalized Hough transform--for detecting shapes in images *other than circles or lines*--please add a comment below to let us know!

In the meantime, try out `FindCirclesGUI` if you haven't already done so; it allows you to change any of the input parameters to `imfindcircles`, and to interactively see the results:

As always, I welcome your thoughts and comments.

Get
the MATLAB code

Published with MATLAB® R2014a

Sean's pick this week is also Wing Designer by John Rogers. Contents Background ... read more >>

]]>Sean's pick this week is also Wing Designer by John Rogers.

A few weeks ago when Will picked Wing Designer I immediately had to go download it and try to beat his high score of 29252. After a bit of twiddling I was able to! By hand, I got a score of 30706.9.

But then I wondered what kind of score I could get with an optimizer from the Optimization Toolbox or the Global Optimization Toolbox?

Fortunately with the way John wrote this, I could tie into the scoring engine by emulating the output of user selections from the user interface.

Looking at the tunable parameters there are quite a few and many of them are integer constrained. Since the actual engine
for this app is a black box to me, I am *assuming* that the score function is highly nonlinear with lots of local minima. Thus I need to take a global approach to this. The
first function that jumps out is `ga` since this allows integer constraints. However, genetic algorithms don't always hold up well in as many dimensions as we
have.

So instead I turned to `patternsearch`. Patternsearch is a direct search method that is often recommended over `ga` by Alan, who's a genius. But since `patternsearch` does not support integer constraints, I need to evaluate it on every combination of integers and then pick the best from
these results.

Wing Designer's user interface returns a geometry structure that I needed to emulate. Here's an example of part of the structure:

I wrote a function that takes in some of the various parameters that would be selectable in the user interface to create this structure.

Next, I needed to make some design decisions regarding my wing since trying every integer combination is just not feasible in the amount of time allotted. I spoke with one of our aerospace experts and he provided a few suggestions:

- Wings should be long and narrow.
- Don't break the sound barrier.
- Probably use a jet.
- Fly between 35k and 50k.
- Some of the parameters like friction would be known before hand so don't include them in the optimization.

I made an additional few:

- Root and Tip should have the same airfoil.
- I will use 10 spanwise panels and 6 chordwise panels. More than this dramatically slows the computation.

Since `patternsearch` has to run many times, once for each of the airfoils, and the function is called many times inside of `patternsearch`, I have to parallelize it. I could set the *'UseParallel'* flag in `psoptimset`, but this would only parallelize individual `patternsearch` polls. Ideally, the calls to `patternsearch` should be parallelized, so instead we'll use a parallel for-loop (parfor) over the airfoils.

My laptop only has two cores, not enough to make this happen in the 12 hours before the blog post is due. So instead, I used a cluster running MATLAB Distributed Computing Server on Amazon EC2. I fired up a cluster with 36 workers which makes it much more feasible. I chose 36 workers: one for each airfoil, one to run the job itself, and an extra because it likes even numbers.

This is the body of `OptimizeWing.m`, the function that calls `patternsearch`.

% Lower and upper bounds lb = [50 10 5 0 0 0 0 300 35000 0 0 5000 0]; ub = [200 40 10 5 5 5 5 660 50000 7 15 80000 100]; % x0, half way between bounds x0 = lb + ((ub-lb)./2); % Options options = psoptimset('TolMesh',0.1,'MaxIter',100); nfoils = 34; % 34 airfoils fval = zeros(nfoils,1); % fval at xopt xopt = zeros(nfoils,numel(x0)); % optimal x % Run the parfor loop parfor ii = 1:nfoils % Wrap the call in a try block in case some air foils cause failure try [xopt(ii,:), fval(ii)] = patternsearch(@(x)wingdesignerScore(x,ii),x0,[],[],[],[],lb,ub,[],options) catch % iith airfoil failed xopt(ii,:) = nan; fval(ii) = nan; end end

First, I ran `patternsearch` once on one airfoil with very loose tolerances just to make sure it worked as expected. It did! Then it was time to submit
the main function to the cluster, using `batch`.

batch('OptimizeWing.m',2,'Pool',34,'AttachedFiles',files)

And wait... Well actually, shut off my computer and go home for the evening. Since the job is running on EC2 somewhere in Virginia, there is no dependency on my machine.

After retrieving the completed job in the morning, the best score is found by taking the minimum of the scores vector, *fval* and putting the corresponding *xopt* parameters into the App.

That's about 153000x better than we did by hand! The optimized wing is large, symmetric, and mostly filled with fuel. I'd be curious to hear thoughts from someone in the industry on the feasibility of a wing like this?

Do you have a challenging optimization problem or some really computationally expensive work where cluster or cloud computing could help?

Let us know about it in the comments!

Get
the MATLAB code

Published with MATLAB® R2014a

Jiro's pick this week is "Automatic enveloping, variance change and activity detection with Hilbert Transform" by Hooman Sedghamiz. This entry by Hooman brought back memories from my graduate school days. Back then, I was involved with experimental biomechanics. ... read more >>

]]>Jiro's pick this week is "Automatic enveloping, variance change and activity detection with Hilbert Transform" by Hooman Sedghamiz.

This entry by Hooman brought back memories from my graduate school days. Back then, I was involved with experimental biomechanics. One of the types of measurements I took was EMG (electromyography), which represents muscle activity. Depending on the quality and the placement of the sensors, the measured signals can vary greatly in quality. From the EMG, I needed to determine the frequency and the duration of the muscle activations. Back then, I investigated a few different methods, ranging from manual inspection to using signal processing techniques with wavelets. That was when I really got to learn and use the Wavelet Toolbox.

This function by Hooman would have certainly helped me with this task. It uses Hilbert transform, smoothing, and adaptive thresholding to identify the activations of the signal. The function has a few parameters you can specify:

- (2nd input) Smoothing window length
- (3rd input) Whether or not to use adaptive thresholding
- (4th input) Minimum number of samples where the signal needs to stay above the threshold in order to be considered active
- (5th input) Whether or not to create a summary plot

load data act = envelop_hilbert_v2(sig,20,true,20,false); plot(sig) hold on plot(act,'r') legend('Raw signal','Activations')

If you ask for a summary plot, it generates the following plot.

**Comments**

Let us know what you think here or leave a comment for Hooman.

Get
the MATLAB code

Published with MATLAB® R2014a