How to convert dbm to watts on Matlab - matlab

Good day
I want to convert PT=47dbm to watts,how can i do that conversion on matlab?
On my code I have it as PT=50,12watts, but i want to do the proper conversion from dbm to watts using Matlab.

The watt to dBm conversion follows the following rule:
dBW = 10 * log10(P[w])
dBm = 10 * log10(1000 * P[w])
= 10 * log10(P[w]) + 10 * log10(1000)
= 10 * log10(P[w]) + 10 * 3
= 10 * log10(P[w]) + 30
= dBW + 30
Hence, the inverse path will be:
P[w] = 10 ^ ((P[dBm] - 30) / 10);
Thus, in Matlab:
P_w = 47;
P_dBm = 10 ^ ((P_w - 30) / 10); % 50.12

Related

Cut audio signal in specific Segments. (Matlab)

I am trying to cut the audio signal in a specific segment in ms. I have tried the below code and it works okay but only for one segment. How can I cut the signal in multiple segments?
[y,Fs] = audioread('myAudioData.wav');
cutData = y((Fs * (1 - 1)) + 1 : Fs * (2 - 1), :);
plot(linspace(1, 2, length(cutData)), cutData);
EDITED
[y,Fs] = audioread('myAudioData.wav');
nSamOr=length(y);
zVec=7865657/10^9;
zVecE=zVec+0.050;
zVecS=zVec-0.050;
startTime = ((zVecS + (zVecE-zVecS))/(2 - 10));
EndTime = ((zVecS + (zVecE-zVecS))/(2 + 10));
cutData = y((Fs * (startTime)) + 1 : Fs * (EndTime ), :);
plot(linspace(1, 2, length(cutData)), cutData);
I am getting the below error:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Test1 (line 9)
cutData = y((Fs * (startTime)) + 1 : Fs * (EndTime ), :);
Anyone who can help why I am getting this error?

Matlab - Plotting with for loop

I am new to matlab and am trying to loop through an equation from 1 to 1000 and plot the result, but every value is turning out the same and the plot is incrorrect.
Here is my current attempt, but the variable Rm is giving only one results (instead of 1000 separate ones):
Ds = 1.04e-10;
Gamma = 1.9;
Omega = 1.09e-29;
Deltas = 2.5e-10;
Boltzmann = 1.3806e-23;
T = 1123.15;
Beta = 0.83;
Zo = 6.7;
EtaNi = 0.39;
EtaYSZ = 0.61;
Rm0 = 0.29;
RmYSZ0 = 0.265;
lambda = 4.70e-3;
C = Ds * ((Gamma * Omega * Deltas) / (2 * Boltzmann * T)) * (Beta / ((1 - Beta^2) * ((1 + Beta^2)^0.5) * ((1 + Beta)^3))) * Zo * (EtaNi/((EtaNi/Rm0) + (EtaYSZ/RmYSZ0)));
tinit=1; % Initial time value (h)
tend=1000; % End time value (h)
tinc=1; % Increment in time value (h)
t= [tinit:tinc:tend]; % Time vector
n = 1000;
for i=1:n
Rm(i) = (((5*C)/lambda) * (1 - exp(-lambda*i)) + (Rm0)^5)^(1/5);
end
plot(t,Rm);
Expected result is an exponential curve, any help would be appreciated
Your term before R0 is an exponential that ranges from 0 to 4.5e-27. R0^5 is 0.0021. Floating point precision is not enough to preserve the first term when it is added to the second. So (5C/L*(...) + Rm0^5) == Rm0^5, so it is constant.

How can we measure the similarity distance between categorical data ?

How can we measure the similarity distance between categorical data ?
Example:
Gender: Male, Female
Numerical values: [0 - 100], [200 - 300]
Strings: Professionals, beginners, etc,...
Thanks in advance.
There are different ways to do this. One of the simplest would be as follows.
1) Assign numeric value to each property so the order matches the meaning behind the property if possible. It is important to order property values from lower to higher if property can be measured. If it is not possible and property is categorical (like gender, profession, etc), just assign number to each possible value.
P1 - Gender
-------------------
0 - Male
1 - Female
P2 - Experience
-----------
0 - Beginner
5 - Average
10 - Professional
P3 - Age
-----------
[0 - 100]
P4 - Body height, cm
-----------
[50 - 250]
2) For each concept find scale factor and offset so all property values fall in the same chosen range, say [0-100]
Sx = 100 / (Px max - Px min)
Ox = -Px min
In sample provided you would get:
S1 = 100
O1 = 0
S2 = 10
O2 = 0
S3 = 1
O3 = 0
S4 = 0.5
O4 = -50
3) Now you can create a vector containing all the property values.
V = (S1 * P1 + O1, S2 * P2 + O2, S3 * P3 + O3, S4 * P4 + O4)
In sample provided it would be:
V = (100 * P1, 10 * P2, P3, 0.5 * P4 - 50)
4) Now you can compare two vectors V1 and V2 by subtracting one from other. The length of resulting vector will tell how different they are.
delta = |V1 - V2|
Vectors are subtracted by subtracting each dimension. Vector length can be calculated as square root of sum of squared vector dimensions.
Imagine we have 3 persons:
John
P1 = 0 (male)
P2 = 0 (beginner)
P3 = 20 (20 years old)
P4 = 190 (body height is 190 cm)
Kevin
P1 = 0 (male)
P2 = 10 (professional)
P3 = 25 (25 years old)
P4 = 186 (body height is 186 cm)
Lea
P1 = 1 (female)
P2 = 10 (professional)
P3 = 40 (40 years old)
P4 = 178 (body height is 178 cm)
Vectors would be:
J = (100 * 0, 10 * 0, 20, 0.5 * 190 - 50) = (0, 0, 20, 45)
K = (100 * 0, 10 * 10, 25, 0.5 * 186 - 50) = (0, 100, 25, 43)
L = (100 * 1, 10 * 10, 40, 0.5 * 178 - 50) = (100, 100, 40, 39)
To determine we need to subtract vectors:
delta JK = |J - K| =
= |(0 - 0, 0 - 100, 20 - 25, 45 - 43)| =
= |(0, -100, -5, 2)| =
= SQRT(0 ^ 2 + (-100) ^ 2 + (-5) ^ 2 + 2 ^ 2) =
= SQRT(10000 + 25 + 4) =
= 100,14
delta KL = |K - L| =
= |(0 - 100, 100 - 100, 25 - 40, 43 - 39)| =
= |(-100, 0, -15, 4)| =
= SQRT((-100) ^ 2 + 0 ^ 2 + (-15) ^ 2 + 4 ^ 2) =
= SQRT(10000 + 225 + 16) =
= 101,20
delta LJ = |L - J| =
= |(100 - 0, 100 - 0, 40 - 20, 39 - 45)| =
= |(100, 100, 20, -6)| =
= SQRT(100 ^ 2 + 100 ^ 2 + (20) ^ 2 + (-6) ^ 2) =
= SQRT(10000 + 10000 + 400 + 36) =
= 142,95
From this you can see that John and Kevin are more similar than any other as delta is smaller.
There are a number of measures for finding similarity between categorical data. The following paper discuses briefly about these measures.
https://conservancy.umn.edu/bitstream/handle/11299/215736/07-022.pdf?sequence=1&isAllowed=y
If you're trying to do this in R, there's a package named 'nomclust', which has all these similarity measures readily available.
Hope this helps!
If you are using python, there is a latest library which helps in finding the proximity matrix based on similarity measures such as Eskin, overlap, IOF, OF, Lin, Lin1, etc.
After obtaining the proximity matrix we can go on clustering using Hierarchical Cluster Analysis.
Check this link to the library named "Categorical_similarity_measures":
https://pypi.org/project/Categorical-similarity-measures/0.4/
Just a thought, We can also apply euclidean distance between two variables to find a drift value. If it is 0, then there is no drift or else call as similar. But the vector should be sorted and same length before calculation.

Convert output from symbolic math (sym) to float

My question is similar to this question but I believe it to be more general.
I use Matlab's symbolic math toolbox to solve an equation:
MAZ = 0.5;
MAU = 1.0;
XI = 1.0;
ALPHA = 2.0;
DRG = 0.5;
SRG = 1.0;
PHI = 1 / (2 * MAU);
syms L;
f = 1 - DRG - sqrt(1 + (ALPHA * XI - L / (2 * XI * PHI) ) ^ 2 ) / ...
sqrt(1 + (ALPHA * XI) ^ 2) + L / (4 * PHI * SRG * sqrt(1 + (ALPHA * XI)^2));
a = solve(f,L,'Real',true);
The answer is:
a =
5^(1/2)/3 + (10*((4*5^(1/2))/25 + 6/25)^(1/2))/3 + 8/3
5^(1/2)/3 - (10*((4*5^(1/2))/25 + 6/25)^(1/2))/3 + 8/3
How do I automatically convert these expressions for a - which do not contain any symbolic expressions - to floats so that I can access them later in my code?
Matlab's symbolic math toolbox contains a function called double.
This function converts the result of the solve function - which is a sym - to a double:
double(a)
ans =
5.98921078320145
0.834834535131742
While double is correct, it is limited to the precision of 64bit floating points. Use vpa if a higher precision is needed:
>> vpa(a)
ans =
5.9892107832014511063435699584181
0.83483453513174202459587915406938
>> digits(99)
>> vpa(a)
ans =
5.98921078320145110634356995841813862213621375395128614574627036653958858547362556353272837962692249
0.834834535131742024595879154069378868157531819123064337100994463734092031618244369410214559292265698

Matlab symbolic function with normcdf

I have the following function for which I want to find the extrema using matlab.
That function has to use the "normcdf" function in matlab in order to get the results but when I'm trying to create the symbolic function I get back some errors.
The input I give is the following:
syms z fz t sz
fv = 1000 * ((z * fz * normcd(t,fz,sz)) / (20 * 50 * normcd(t,50,20))) + 1000 * normcdf((20 * 50 * normcd(t,50,20) + z * fz * normcd(t,fz,sz)) / 2000, 50 * normcd(t,50,20), 20) - 10 * z
and the errors I get back are the following:
??? Error using ==> sym.le at 11
Function 'le' is not implemented for MuPAD symbolic objects.
Error in ==> normcdf at 57
sigma(sigma <= 0) = NaN;
Does anyone know how I can get around that? Thanks in advance.
I forgot to mention that I use matlab version R2009a.
It appears to work for me:
>> syms z fz t sz
>> fv = 1000 * ((z * fz * normcdf(t,fz,sz)) / (20 * 50 * normcdf(t,50,20))) + 1000 * normcdf((20 * 50 * normcdf(t,50,20) + z * fz * normcdf(t,fz,sz)) / 2000, 50 * normcdf(t,50,20), 20) - 10 * z
>> subs(fv,{fz,sz,t,z},{1,2,3,4});
ans =
809.2922
Take a look at the Subs.
I found a way around it. Instead of using normcdf one can use its equivalent equation with erf which then works fine.
normcdf(x,mu,sig) = (1+erf((x-mu)/sig/sqrt(2)))/2