Input of array into equation update

조회 수: 2 (최근 30일)
Jose Iglesias
Jose Iglesias 2023년 4월 4일
댓글: Jose Iglesias 2023년 4월 4일
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에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by