Azzera filtri
Azzera filtri

Input of array into equation update

1 visualizzazione (ultimi 30 giorni)
I need to update a simple Matlab code shown below. What the code is doing is converting dB values to its respective magnitude ranging from 0dB to 20dB in increments of 0.5dB. This is done in the third line of code for the b variable. I ran it without the semicolon and all 40 values were correct. However, I want the last line of code to take those 40 magnitude values and calculate them into the variable v equation. When I ran the code the 40 values produced did not match my calculator calculations. Is there a better way for me to run through the loop of 40 magnitude values into the last equation for variable v? Can someone please update this code maybe with a for loop or anything you can recommend? I am calculating the variance values from the SNR values that were converted to their magnitudes. This is for a 4-QAM modulation. Thank you in advance!
a = 4;
x = (0:0.5:20);
b = 10.^(x/10);
v = 2*a^2./(b)

Risposta accettata

Joseph
Joseph il 4 Apr 2023
A couple of thoughts here. First the small nuance that "x" is actually a vector of length of 41. Second you mention that you are attempting to go from dB values to magnitude, however you are using the formula for dB to power. This could be how you are getting different answers. To try it with the strictly "db-to-magnitude" forumula, just change the third line.
a = 4;
x = 0:0.5:20;
b = 10.^(x./20); %note the 20 instead of the 10
v = 2*a.^2./b;
Otherwise I cannot replicate the difference in answers with and without semicolons that you described.
  1 Commento
Jose Iglesias
Jose Iglesias il 4 Apr 2023
Joseph, I was able to figure what I was trying to do. The following is the updated code although the answers seem to repeat themsleves. As far as the v goes, it is reperesenting the noise variance. The formula I used in line three is to go from dB to to its magnitude.
a = 4;
x = (0:0.5:20);
b = 10.^(x/10);
v = zeros(size(b)); % initialize v as a vector of zeros
for i = 1:length(b)
v(i) = 2*a^2/b(i); % calculate variance value for each magnitude value
end

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by