仿真学习记录帖子(持续更新)

通信仿真中各种问题

1.路径损耗仿真

β k [ m ] = β 0 d k − α [ m ] = β 0 ( H 2 + ∣ ∣ q [ m ] − w k ∣ ∣ 2 ) α / 2 \beta_k[m]=\beta_0d_k^{-\alpha}[m]=\frac{\beta_0}{(H^2+||\mathbf q[m]-\mathbf w_k||^2)^{\alpha/2}} βk[m]=β0dkα[m]=(H2+q[m]wk2)α/2β0
其中 β 0 \beta_0 β0一般表示在 d 0 = 1 m d_0=1m d0=1m处的参考信道功率增益,那么路径损耗可以写为:

function [pathloss] = getPathLoss(d)
% input, d is decimal scale,d是一个十进制位
% output pathloss is dB scale 输出的路径损耗是dB维度的
    global beta0 alpha

    da = -alpha*dec2dB(d);
    pathloss = beta0 + da;
end

%% local functions
function [dB] = dec2dB(dec)
dB = 10*log10(dec);
end

function [dec] = dB2dec(dB)
dec = 10^(dB/10);
end
  1. 可达速率仿真
    R k [ m ] = l o g 2 ( 1 + F − 1 ( η ) P k β 0 σ 2 τ ( H 2 + ∣ ∣ q [ m ] − w k ∣ ∣ 2 ) α / 2 ) ) R_k[m]=\mathrm {log_2}(1+\frac{F^{-1}(\eta)P_k\beta_0}{\sigma^2\tau(H^2+||\mathbf q[m]-\mathbf w_k||^2)^{\alpha/2})}) Rk[m]=log2(1+σ2τ(H2+q[m]wk2)α/2)F1(η)Pkβ0)
    其中 F ( ⋅ ) F(·) F()表示与小尺度衰落 ∣ p k [ m , l ] ∣ 2 |p_k[m,l]|^2 pk[m,l]2相同的累计分布方程
%% getAchievableRate
% input, pathloss is dB scale
% output, R's unit is bps/hz
function [R] = getAchievableRate(pathloss)

global F_1 Pk sigma_2 Lamda

R = log2(1+F_1*Pk*dB2dec(pathloss)/(dB2dec(sigma_2)*dB2dec(Lamda)));

end

%% local functions
function [dB] = dec2dB(dec)
dB = 10*log10(dec);
end

function [dec] = dB2dec(dB)
dec = 10^(dB/10);
end

MATLAB

全局变量global的使用

若将一个变量声明为全局变量,则它所占的内存为全局内存,而不是本地工作区内存。因此全局变量就可以被所有工作区访问,修改。
初始化的时候声明一次,调用的时候再声明一次【在一个内存空间里声明global,在另一个内存空间里使用这个global的时候需要再次声明 global,当然,各内存空间里声明一次就可以了】。

  1. 自定义函数:global_p.m
function y=global_p(x)
%H1注释行
%测试全局变量的用法
global p; %3、声明p是全局变量
p=p+1;    %4、对全局变量p的操作
fprintf('全局变量须先声明,然后操作:自加一次\n');
y=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1. 调用函数test_global.m:
clc;
clear;
% 测试说明:
% 本程序主要是测试全局变量的使用,以及对其的改变操作
% 自定义函数的输入变量(形参)和输出变量均没有意义,只是为了匹配格式而定义的
global p;  %1、定义p是全局变量
p=0;      %2、p初始化
for i=1:5
result=global_p(0); %5、调用函数
end

CVX工具箱

expression的用法

在优化问题的时候遇到提示变量被重写,系统提示是这样子的
在这里插入图片描述
解决方法就是把variable v2注释掉(自己都赋值了,还设什么变量),因为,cvx中的variable变量不是允许人为赋值的,只有在最后得出结果才会被结果覆盖,而expression变量是可以使用“=”的临时变量,在完成cvx后其值清零。
expression的用法:

cvx_begin

expression z=zeros(1,N) 这里表示expression做为临时变量

z(:,n)=x; 将x赋值给z

cvx_end

{convex} .* {convex}

可以用quad_over_lin(X, Y)函数,这个函数等于
S U M ( A B S ( x ) . \mathrm {SUM(ABS(x).} SUM(ABS(x).^ 2. / Y ) \mathrm {2./Y)} 2./Y),其中X是向量,Y是标量,

{convex} .^2

^2–>square_pos,平方替换:
square_pos(norm( Q(:,m) - u(:,k)))

CVX论坛网址:
cvx forum.

abs{convex}

值得注意的是
Trigonometric functions are neither convex nor concave,. They can only be “convexified” by means of an approximation, such as a suitable Taylor series. The one term Taylor series approximation for sin(x) is x, and the two term Taylor series approximation is x - x^3/6, which is concave if e is positive, and convex if e is negative.However, it is doubtful either of those will work well in your optimization problem. A higher order Taylor series approximation for sin(x) will be neither convex nor concave.

Edit: Now I see you have an absolute value around the sin term. So only the one term Taylor series approximation could be used, unless a binary is introduced to handle the absolute value.

I recommend you use a non-convex nonlinear solver, which you can not do via CVX. You can consider using YALMIP. Why isn’t CVX accepting my model? READ THIS FIRST!

解决办法:
I think you can do this by using the MIDCP capability of CVX and declaring a binary variable beta_binary§, and adding suitable constraints, as shown in the MOSEK Modeling Cookbook version 3.0, section 9.1.6 “Exact absolute value” https://docs.mosek.com/MOSEKModelingCookbook-letter.pdf 4 .

To do this, you will need to use an upper bound on the absolute value of the beta components, which you should not make larger than necessary. If the optimal solution hits a bound, you will need to re-do.

You will need a version of CVX capable of handling binary variables (MIDCP), and the problem should be formulated by CVX and submitted to the solver (you will need MOSEK or Gurobi) as an MISOCP.

The following code snippet with the MOSEK solver worked for me, where I used M > 0 to define the upper bound.


% fit in cvx using mosek solver
cvx_begin
    variables betas(p) betas_abs(p) betas_pos(p) betas_neg(p);
    variable betas_binary(p) binary;
    minimize(square_pos(norm(y - X * betas)) / (2 * n) + lambda * square_pos(norm(betas_abs - Z * alphas)) / 2);
    subject to
        betas == betas_pos - betas_neg;
        betas_abs == betas_pos + betas_neg;
        betas_pos >= 0;
        betas_neg >= 0;
        betas_pos <= M * betas_binary;
        betas_neg <= M * (1 - betas_binary);
cvx_end

链接: abs处理.

数学领域上的

二元泰勒展开

f ( x 0 + h , y 0 + k ) = f ( x 0 + y 0 ) + ( h ∂ ∂ x + k ∂ ∂ x ) f ( x 0 , y 0 ) + 1 2 ! ( h ∂ ∂ x + k ∂ ∂ x ) 2 f ( x 0 , y 0 ) + . . . f(x_0+h,y_0+k)=f(x_0+y_0)+(h\frac{ \partial }{ \partial x}+k\frac{ \partial }{ \partial x})f(x_0,y_0)+\frac{1}{2!}(h\frac{ \partial }{ \partial x}+k\frac{ \partial }{ \partial x})^2f(x_0,y_0)+... f(x0+h,y0+k)=f(x0+y0)+(hx+kx)f(x0,y0)+2!1(hx+kx)2f(x0,y0)+...

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值