Post Go back to editing

Calculating the difference (in decibels) between the RMS levels of two signals

Comparing the linear level of two signals is fairly simple in SigmaStudio. You can basically calculate the envelope of each signal (using peak, MS, or running average), and then subtract the two outputs to find the linear difference in amplitude.

However, what about if you want to compare two signals to see if their RMS levels are a certain number of decibels apart? Logarithmic calculations are more difficult.

Parents
  • If you'd like to use this functionality, then the RMS Table is exactly what you need. However, in order to implement it correctly, you'll need to manipulate SigmaDSP's number representation to get it to work. Essentially, you need to map the logarithmic scale to the linear scale before performing the comparison. I'll show you how it works.

    The RMS Table has 33 points in it. Each point maps to an RMS level spaced 3 dB apart from its neighbor. This table mapping is shown below RMS_Table_Mapping.txt (it's also in the help file).

    Index    RMS Level (dB)
    1    -90
    2    -87
    3    -84
    4    -81
    5    -78
    6    -75
    7    -72
    8    -69
    9    -66
    10    -63
    11    -60
    12    -57
    13    -54
    14    -51
    15    -48
    16    -45
    17    -42
    18    -39
    19    -36
    20    -33
    21    -30
    22    -27
    23    -24
    24    -21
    25    -18
    26    -15
    27    -12
    28    -9
    29    -6
    30    -3
    31    0
    32    3
    33    6
    

    So, the RMS level of the input is measured, compared to the points on the table, and with some interpolation, the proper value is output. For example, if my input is at -61.5 dB RMS, then the points corresponding to -63 dB and -60 dB will be chosen, and the output will be a kind of interpolation between those two points, and the output will basically be the mean of the value at -63 dB and the value at -60 dB.

    In any event, that's a bit too much detail for this example. Basically, you need to create your list of output values that will correspond to each of those inputs - the goal is to map the logarithmic value (i.e. detected RMS level in dB) to a linear value that's easier to work with.

    The natural idea would be to just start at -90, -87, -84, etc... and enter those values directly in your table, but since the SigmaDSP's number system can only represent values between +16 and -16, that's not an option. So, for my project, I decided to just start at 0.1 and increment by 0.1 on each index. What you're essentially doing here is taking an RMS measurement and mapping it to a linear value so it can be easily added/subtracted. For lack of a better system, I simply picked the index number and divided it by ten in order to make it fit SigmaDSP's number system.

    It may be a little confusing, but the main point is this: We're essentially representing the dB value using arbitrary numbers that work with the number format in the DSP. The important thing is to remember that for the scale I picked, a difference of 3 dB RMS maps to a step of 0.1 in the linear scale.

    Here's the completed table:

    Index  RMS Level (dB) Arbitrarily Mapped Linear Value
    1          -90        0.1
    2          -87        0.2
    3          -84        0.3
    4          -81        0.4
    5          -78        0.5
    6          -75        0.6
    7          -72        0.7
    8          -69        0.8
    9          -66        0.9
    10         -63        1.0
    11         -60        1.1
    12         -57        1.2
    13         -54        1.3
    14         -51        1.4
    15         -48        1.5
    16         -45        1.6
    17         -42        1.7
    18         -39        1.8
    19         -36        1.9
    20         -33        2.0
    21         -30        2.1
    22         -27        2.2
    23         -24        2.3
    24         -21        2.4
    25         -18        2.5
    26         -15        2.6
    27         -12        2.7
    28          -9        2.8
    29          -6        2.9
    30          -3        3.0
    31           0        3.1
    32           3        3.2
    33           6        3.3
    

    Next, I set up one RMS table for each input. Each cell must have the exact same settings for this to work - using the Cell Settings Copy/Paste options from the right-click menu is a good way to ensure this. Next, I need to compare the outputs of each table. This is accomplished using a subtraction cell. Because I want to check to make sure the difference of the two signals' amplitudes exceeds a certain amount, and not necessarily that one is greater than or less than the other, I use an absolute value cell to make sure this difference is always positive. Finally, I use a logic AB comparison cell to determine if the result of that subtraction (i.e. the difference of the two signals' RMS levels) exceeds some threshold.

    The completed flow looks like this:

    So, here's an example that you can test in the project: If my 1st input is measuring -3 dB RMS, then its table will output 3.0 (see table above). If my 2nd input is measuring -15 dB RMS, then its table will output 2.6. Then I can simply linearly subtract these signals and find that the difference is 0.4. Because I've mapped a linear change of 0.1 to represent 3 dB, I cal calculate that a linear change of 0.4 means a change of 12 dB. Thus, you can see that -3 dB and -15 dB are indeed 12 dB apart. It works!

    Next, in the logic cell, I can compare that 0.4 value to any threshold I choose (for example I will choose 0.2, or 6 dB). I can then tell the logic cell to output different control signals based on the result of the conditional. Since, in this example, 0.4 is greater than 0.2 (i.e. 12 dB is greater than 6 dB), my logic cell tells me that the conditional is true. Indeed, the difference of 12 dB is greater than my threshold of 6 dB.

    Please try this out using the attached project. It was built using an ADAU1781 SigmaDSP but could easily be ported to other processors. If the two input signals have a difference of 6 dB or greater, then the logic cell will output a '1', signifying that the condition is met.

Reply
  • If you'd like to use this functionality, then the RMS Table is exactly what you need. However, in order to implement it correctly, you'll need to manipulate SigmaDSP's number representation to get it to work. Essentially, you need to map the logarithmic scale to the linear scale before performing the comparison. I'll show you how it works.

    The RMS Table has 33 points in it. Each point maps to an RMS level spaced 3 dB apart from its neighbor. This table mapping is shown below RMS_Table_Mapping.txt (it's also in the help file).

    Index    RMS Level (dB)
    1    -90
    2    -87
    3    -84
    4    -81
    5    -78
    6    -75
    7    -72
    8    -69
    9    -66
    10    -63
    11    -60
    12    -57
    13    -54
    14    -51
    15    -48
    16    -45
    17    -42
    18    -39
    19    -36
    20    -33
    21    -30
    22    -27
    23    -24
    24    -21
    25    -18
    26    -15
    27    -12
    28    -9
    29    -6
    30    -3
    31    0
    32    3
    33    6
    

    So, the RMS level of the input is measured, compared to the points on the table, and with some interpolation, the proper value is output. For example, if my input is at -61.5 dB RMS, then the points corresponding to -63 dB and -60 dB will be chosen, and the output will be a kind of interpolation between those two points, and the output will basically be the mean of the value at -63 dB and the value at -60 dB.

    In any event, that's a bit too much detail for this example. Basically, you need to create your list of output values that will correspond to each of those inputs - the goal is to map the logarithmic value (i.e. detected RMS level in dB) to a linear value that's easier to work with.

    The natural idea would be to just start at -90, -87, -84, etc... and enter those values directly in your table, but since the SigmaDSP's number system can only represent values between +16 and -16, that's not an option. So, for my project, I decided to just start at 0.1 and increment by 0.1 on each index. What you're essentially doing here is taking an RMS measurement and mapping it to a linear value so it can be easily added/subtracted. For lack of a better system, I simply picked the index number and divided it by ten in order to make it fit SigmaDSP's number system.

    It may be a little confusing, but the main point is this: We're essentially representing the dB value using arbitrary numbers that work with the number format in the DSP. The important thing is to remember that for the scale I picked, a difference of 3 dB RMS maps to a step of 0.1 in the linear scale.

    Here's the completed table:

    Index  RMS Level (dB) Arbitrarily Mapped Linear Value
    1          -90        0.1
    2          -87        0.2
    3          -84        0.3
    4          -81        0.4
    5          -78        0.5
    6          -75        0.6
    7          -72        0.7
    8          -69        0.8
    9          -66        0.9
    10         -63        1.0
    11         -60        1.1
    12         -57        1.2
    13         -54        1.3
    14         -51        1.4
    15         -48        1.5
    16         -45        1.6
    17         -42        1.7
    18         -39        1.8
    19         -36        1.9
    20         -33        2.0
    21         -30        2.1
    22         -27        2.2
    23         -24        2.3
    24         -21        2.4
    25         -18        2.5
    26         -15        2.6
    27         -12        2.7
    28          -9        2.8
    29          -6        2.9
    30          -3        3.0
    31           0        3.1
    32           3        3.2
    33           6        3.3
    

    Next, I set up one RMS table for each input. Each cell must have the exact same settings for this to work - using the Cell Settings Copy/Paste options from the right-click menu is a good way to ensure this. Next, I need to compare the outputs of each table. This is accomplished using a subtraction cell. Because I want to check to make sure the difference of the two signals' amplitudes exceeds a certain amount, and not necessarily that one is greater than or less than the other, I use an absolute value cell to make sure this difference is always positive. Finally, I use a logic AB comparison cell to determine if the result of that subtraction (i.e. the difference of the two signals' RMS levels) exceeds some threshold.

    The completed flow looks like this:

    So, here's an example that you can test in the project: If my 1st input is measuring -3 dB RMS, then its table will output 3.0 (see table above). If my 2nd input is measuring -15 dB RMS, then its table will output 2.6. Then I can simply linearly subtract these signals and find that the difference is 0.4. Because I've mapped a linear change of 0.1 to represent 3 dB, I cal calculate that a linear change of 0.4 means a change of 12 dB. Thus, you can see that -3 dB and -15 dB are indeed 12 dB apart. It works!

    Next, in the logic cell, I can compare that 0.4 value to any threshold I choose (for example I will choose 0.2, or 6 dB). I can then tell the logic cell to output different control signals based on the result of the conditional. Since, in this example, 0.4 is greater than 0.2 (i.e. 12 dB is greater than 6 dB), my logic cell tells me that the conditional is true. Indeed, the difference of 12 dB is greater than my threshold of 6 dB.

    Please try this out using the attached project. It was built using an ADAU1781 SigmaDSP but could easily be ported to other processors. If the two input signals have a difference of 6 dB or greater, then the logic cell will output a '1', signifying that the condition is met.

Children
No Data