Input of array into equation update

1 次查看(过去 30 天)
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)

采纳的回答

Joseph
Joseph 2023-4-4
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 个评论
Jose Iglesias
Jose Iglesias 2023-4-4
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by