# Professional Motorsport Data Analysis: Building Math Channels

## Building Math Channels

### 13.37

00:00 | - Now that we have an understanding of what math channels are and how they can be used, the best way to understand how to practically implement them is to build some within our analysis software. |

00:11 | In this section, we'll be building the examples we've talked through in the previous module as well as some that will be completely new. |

00:19 | We'll be using MoTeC's i2 software for these examples and this is a good chance for you to work along with me. |

00:26 | So if you haven't done so already, please take a moment to install your chosen software and download the supplied data from the related resources section you'll find below this video. |

00:36 | With math channels, it's important to understand that there is rarely a hard and fast rule for how something should be done. |

00:43 | There are always multiple ways to achieve a similar useful output. |

00:48 | Once we've gone through this section, and as we move through the course, I encourage you to think of your own ideas for using math channels and try to implement them yourself. |

00:58 | When working with math, there's always a lot of opportunity to use our creativity to make the data more useful. |

01:04 | Just because someone shows you one way to calculate something, doesn't mean there isn't a more suitable method for your particular situation. |

01:12 | First, let's familiarise ourselves with the different parts of the math channel area. |

01:17 | Clearly we have to go work in an actual piece of software to go through real examples but we'll endeavour to make the explanations as generic as possible so you can apply them to your own situation if you're working with a different system for your own car. |

01:32 | Most data analysis systems organise their math channels in a very similar way. |

01:36 | So it won't be too difficult to apply to different systems. |

01:40 | Regardless of which system you're using, you should make use of the help resources included in your software. |

01:46 | In MoTeC's i2 software, we can access the maths area with this button in the toolbar. |

01:52 | Or by using the control M shortcut on our keyboard. |

01:56 | On the left side here, we have the option of organising our math channels into folders. |

02:02 | When you're starting out, this isn't necessary but as we do build up a library of math channels, it'll help to organise them into different folders like powertrain, chassis, brakes and driver etc. |

02:16 | This just makes it easier to find what you're looking for and keep related math channels stored in a common location. |

02:23 | Remember the math channels we define are generally stored as part of our analysis project and aren't attached to the log data itself. |

02:32 | The main part of the screen, shows the channels that are stored within the currently selected folder. |

02:36 | Along with the channel name, a preview of the definition of each channel is also shown which can be helpful when looking through this list. |

02:45 | Double clicking on any existing channel or clicking add expression will bring up the expression editor window. |

02:53 | In the top section of the window, we can define some high level parameters of the math expression. |

02:58 | The channel name, units, the rate or frequency we want to calculate it at and how many decimal points it will be shown as. |

03:06 | In the section below, this is where we enter the actual math that defines the behaviour of the channel. |

03:13 | We can also define the units that the channel will be displayed with, the expression that defines the math and there is also a small help section that gives some hints about how to use some of the available functions. |

03:25 | In the bottom section, there are a range of tools available to us. |

03:29 | We can see all the standard math operators we'd expect, addition, subtraction, multiplication and division along with some boolean operators that we'll be covering later. |

03:39 | The insert range button is used to break the data up into areas of interest which we'll also be looking at soon. |

03:47 | In the bottom left, we have our list of channels. |

03:50 | This list contains every channel that is available to us to use for further calculations. |

03:56 | This will include all the channels that we logged on track as well as any existing math channels. |

04:02 | We can see that there's a small icon to the left of each which helps us identify the source of each channel. |

04:08 | We can search this list and use any of these channels within our new math channels. |

04:14 | To the right of the channel list is a list of the built in functions that we can make use of. |

04:19 | Some examples are trigonometric, conditionals, statistical functions, filtering and smoothing. |

04:25 | We'll use some of these in our following examples as well as later in the course. |

04:31 | The help documentation will be useful here if things are a little unclear on how to use any of these. |

04:37 | Also, note that in some programs, the math channels we have access to, may be limited depending on the level of license we're using. |

04:45 | The final area in the bottom right, is where we can access constants that can be defined for our entire project. |

04:53 | These are values that we may want to refer to in multiple math channels. |

04:57 | Defining and using constants like this allows us to update them in a single place if required. |

05:04 | Examples of common constants would be the value of pi, gravitational acceleration, front and rear track width and the rim diameter for our car. |

05:15 | Any value that we need to reference inside math channels, that'll remain constant, can be defined as a constant. |

05:22 | It also means that if we ever need to update a constant value, we only need to do it in one place and it will automatically propogate throughout all the math channels it's used in. |

05:33 | Let's build the math channel examples we discussed in the previous module, starting with reversing the sign of the G sensor. |

05:40 | Starting in the main math screen, we're going to make a folder for our example channels. |

05:45 | With our folder selected, click the add expression button and start building the new math channel. |

05:52 | First, let's enter the name of the new channel. |

05:54 | I'm going to use the exact same name as the original channel that I'm correcting but I'll add a cor for corrected at the end of it to help me differentiate between the two. |

06:03 | Now I select the quantity which in this case is an acceleration. |

06:08 | We leave the rate as auto and change the display and result units to G which is consistent with the original channel. |

06:16 | I'm happy with the default 2 decimal places so I can leave this as is. |

06:21 | We can also select the channel colour which will be the colour this channel is displayed in in the plots and to keep things easy, we want it to match the original channel colour. |

06:30 | We only need one channel as an input to this expression and by typing the first few letters of the channel into the search area, the options will be narrowed down. |

06:39 | Double click to select which will add it to the expression window. |

06:44 | Put your cursor infront of the channel name and type a negative 1 followed by a multiplication sign which is shown by a star symbol. |

06:53 | MoTeC supplies buttons here to insert any of the operators you'll need but I usually find it quicker to type them instead and that's it, we've finished the corrected channel. |

07:03 | This will now invert the sign of whatever the value of the original channel is. |

07:06 | One other thing to note here in this particular software, the way the expression text is formatted, gives us hints to let us know everything is valid. |

07:15 | If any channel names are invalid, they will change colour to red. |

07:20 | Any invalid math expressions will cause the channels to no longer be shown as bold. |

07:26 | For example, if we remove the multiplication, or if there's a bracket in the wrong place. |

07:31 | There's also a message area that tells us here if the expression we currently have defined is valid or not. |

07:37 | These features are really helpful when we're debugging our math channels. |

07:42 | Now if we go and plot our new channel on a time/distance plot, we can compare it to the original one. |

07:47 | We can see here that the new channel is inverted to the old one which is exactly what we wanted. |

07:53 | Now let's look at averaging the front wheel speeds. |

07:57 | Here I've already set up the basic parts of the math channel and given an abbreviated name that matches the original channels. |

08:04 | We can get the average value by adding both channels together and dividing by two. |

08:10 | I like to leave some extra space around the elements of the math channels as I find it makes them easier to read. |

08:17 | Checking our new channel in the plot, we can see that the calculation looks correct as the value looks to be about halfway between both front wheel speeds. |

08:26 | To calculate the brake bias ratio we're going to need the front and the rear brake pressure. |

08:33 | As we discussed in the previous module, we can calculate the ratio by dividing the front pressure by the sum of the front and rear pressure. |

08:41 | We want to express this value as a percentage for convenience and when we first discuss this, we were going to multiply the expression by 100 in order to display the result as a percentage as I have here. |

08:53 | However, there's a feature available to us that we should make use of instead. |

08:57 | If we remove the multiply by 100, the output of this expression will be a ratio not a percentage. |

09:05 | And this is what is selected in the result units section. |

09:08 | In the box above labelled display unit, if we change this to percentage, the conversion will be done for us. |

09:15 | If they are available in your software, I suggest you make use of the automatic unit conversions and always consider the units you're using when making math functions. |

09:24 | Now, plotting this channel, we can see that there is something weird going on. |

09:28 | But we'll get to that next. |

09:30 | If we zoom into just one of the braking zones, we can see the value for brake bias looks pretty close to what we'd expect so the calculation seems valid at least. |

09:39 | Now let's see what's happening with the brake bias calculation that makes everything outside the braking zones look so strange. |

09:47 | This is due to what we discussed in the previous section where the calculation has gone a bit crazy because the background noise in the pressure signals is giving us unusable data. |

09:58 | Obviously we're only interested in the brake bias when we're actually braking. |

10:02 | Looking at the raw log data for the brake pressure outside of the braking zones, shows us really quickly how the calculation is getting so strange. |

10:11 | Even though the magnitudes are small, the relative difference between them is large and it's all caused by the noise in the signal. |

10:19 | The first thing we need to do is create a channel that we'll use to turn the brake bias calculation on and off. |

10:26 | We could do this directly inside the bias calculation and this would mean creating one less channel however as we touched on earlier, we may want to make use of this condition in other math channels at another time and defining it separately means we only need to update its definition in one single place. |

10:45 | Plus it also makes the channels that rely on it more readable. |

10:49 | I tend to name my gating channels by prefixing a capital IS to make it very clear it's a conditional when I'm looking through my channel list. |

10:58 | In this case, we can think of it as the car is braking. |

11:03 | But you can name these as you please. |

11:05 | Every analysis software has a different name for a different gating function. |

11:09 | In MoTeC's i2, this is called choose and we can find choose in the functions list. |

11:16 | Alternatively we can also type it manually. |

11:19 | Now we've added the function we can see that some help information has shown up for it when we have the cursor on the function. |

11:26 | The help not only explains how the functions work but also give us some examples. |

11:32 | We can see the help is telling us that there are 3 inputs required to satisfy the function. |

11:38 | A condition, a true part, and a false part. |

11:41 | These will become obvious as we move through the example. |

11:45 | The condition we want to use is when the car is braking. |

11:48 | Conditionals like this can rely on a single condition or multiple. |

11:53 | In this case I'm just going to keep it very simple and say the condition is that when the brake pressure is greater than 50 psi, the car is defined as braking. |

12:03 | So we enter the brake pressure followed by a greater than sign and 50. |

12:07 | If this expression is true, we want the output to be 1. |

12:10 | Otherwise we want it to be zero. |

12:13 | So I enter those outputs here, separated by commas. |

12:16 | Now looking at the plot of this channel, we can see that it's doing what we want. |

12:21 | The value is 1 when the car is braking and 0 otherwise. |

12:24 | Now we can make use of this conditional in the brake bias calculation. |

12:28 | There are a few different ways we could approach this but the way I'll do it here is by using the choose function again. |

12:36 | When the car is braking, we want to calculate the bias. |

12:40 | So we add the choose statement and find our new channel. |

12:43 | To check for equality, we use the double = sign. |

12:46 | So from left to right, this reads, if the car is braking, calculate the brake bias. |

12:53 | If not, then give me invalid. |

12:56 | We could enter a 0 here for the false part but in situations like this, I prefer to use the invalid statement as it tends to keep the plots cleaner by showing no value at all rather than a 0. |

13:09 | In i2, you can think of invalid as meaning show nothing. |

13:13 | You can experiment with both to see what you prefer. |

13:17 | Going back to our plot, we can see the brake bias calculation is much more usable with values only being shown when the brakes are being used. |

13:25 | So that was a quick run through of some basic math channels. |