Convert magnitude to decibels (dB)
ydb = mag2db(y)
example
ydb = mag2db(y) expresses in decibels (dB) the magnitude measurements specified in y. The relationship between magnitude and decibels is ydb=20∗log10(y)
ydb
y
collapse all
For this example, consider the following SISO feedback loop where the system contains multiple gain crossover or phase crossover frequencies, which leads to multiple gain or phase margin values:
Create the transfer function.
G = tf(20,[1 7]) * tf([1 3.2 7.2],[1 -1.2 0.8]) * tf([1 -8 400],[1 33 700]);
Use the allmargin command to compute all stability margins.
allmargin
m = allmargin(G)
m = struct with fields: GainMargin: [0.3408 3.3920] GMFrequency: [1.9421 16.4807] PhaseMargin: 68.1178 PMFrequency: 7.0762 DelayMargin: 0.1680 DMFrequency: 7.0762 Stable: 1
Note that gain margins are expressed as gain ratios and not in decibels (dB). Use mag2db to convert the values to dB.
mag2db
GainMargins_dB = mag2db(m.GainMargin)
GainMargins_dB = 1×2 -9.3510 10.6091
Input array, specified as a scalar, vector, matrix, or an array. When y is nonscalar, mag2db is an element-wise operation.
Data Types: single | double Complex Number Support: Yes
single
double
Magnitude measurements in decibels, returned as a scalar, vector, matrix, or an array of the same size as y.
db2mag
You have a modified version of this example. Do you want to open this example with your edits?