【matlab】绘制PARR

2023-09-24 5 0

作者在使用matlab编程时,常忘记一些函数的使用规则,因此在这里记录,先起二级标题,如果能够记录达到一定规模,就归纳一级标题。

matlab官方文档

配色

fillcolor1=[0.85, 0.33, 0.10]、fillcolor2=[0.93, 0.69, 0.13]、fillcolor3=[0.00, 0.45, 0.74]

在这里插入图片描述

绘制PARR

关于如何求PAPR的CCDF以及ecdf函数的使用

% Code to simuulate PAPR for OFDMA
clc
clearM = 16; % M-ary QAM
totalSubcarriers = 512; % Number of total subcarriers.
numSymbols = 32; % Input Data block size.
Q = totalSubcarriers/numSymbols; % Bandwidth spreading factor of IFDMA.
Q_tilda = 15; % Bandwidth spreading factor of DFDMA. Q_tilda < Q.
numRuns = 1e5; % Number of runs.
papr = zeros(1,numRuns); % Initialize the PAPR results. (LFDMA)
papr1 = zeros(1,numRuns); % Initialize the PAPR results. (IFDMA)
papr2 = zeros(1,numRuns); % Initialize the PAPR results. (DFDMA)
for n = 1:numRuns% Generate random data.inputData = randi([0 M-1], 1, numSymbols);inputSymbols = qammod(inputData, M, 'UnitAveragePower', false);% Initialize the subcarriers.Y = zeros(totalSubcarriers,1); %For LFDMAY1 = zeros(totalSubcarriers,1); %For IFDMAY2 = zeros(totalSubcarriers,1); %For DFDMA% Subcarrier mapping. LFDMAY(1:numSymbols) = inputSymbols;% Subcarrier mapping. IFDMAY1(1:Q:totalSubcarriers) = inputSymbols;% Subcarrier mapping. DFDMAY2(1:Q_tilda:Q_tilda*numSymbols) = inputSymbols;% IDFTy = ifft(Y);y1 = ifft(Y1);y2 = ifft(Y2);% Calculate PAPR.papr(n) = 10*log10(max(abs(y).^2)/mean(abs(y).^2));papr1(n) = 10*log10(max(abs(y1).^2)/mean(abs(y1).^2));papr2(n) = 10*log10(max(abs(y2).^2)/mean(abs(y2).^2));
end% Plot CCDF.
%X是横轴
%N是每个bin的值
[N,X] = histcounts(papr, 200,'Normalization','count');
[N1,X1] = histcounts(papr1, 200,'Normalization','count');
[N2,X2] = histcounts(papr2, 200,'Normalization','count');
figuresemilogy(X(1:end-1),1-cumsum(N)/max(cumsum(N)),'-r') % For LFDMAhold onsemilogy(X1(1:end-1),1-cumsum(N1)/max(cumsum(N1)),'-g') % For IFDMAhold onsemilogy(X2(1:end-1),1-cumsum(N2)/max(cumsum(N2)),'-b') % For DFDMAhold onlegend('LFDMA','IFDMA','DFDMA')grid onxlabel('PAPR')ylabel('CCDF')title('OFDMA PAPR')

在这里插入图片描述
纵坐标表示的是, ρ \rho ρ>PAPR(PAPR0是横坐标)的概率,
ρ = max ⁡ ∣ x R F ( t ) ∣ 2 E [ ∣ x R F ( t ) ∣ 2 ] \rho=\frac{\max \left|x_{\mathrm{RF}}(t)\right|^2}{\mathbb{E}\left[\left|x_{\mathrm{RF}}(t)\right|^2\right]} ρ=E[xRF(t)2]maxxRF(t)2

histcounts

matlab计算概率密度函数pdf,使用ksdensity histcounts区别
用于计算概率和概率密度的相关函数

clear;
clc;
close all
%X = randn(n) 返回由正态分布的随机数组成的 n×n 矩阵
x = randn(100000,1);%生成服从正态分布的数
width = 0.2;
xi = -4:width:4;
edge = [xi-0.5*width,xi(end)+0.5*width];%   -4-0.5*width:width:4+0.5*width;
%直方图的根数(nbin)
%直方图的宽度设置(edge,即每根的左右边界)),得到的值与nbin一致,比edge少一个
[dens,edge,bin] = histcounts(x,edge,'normalization','pdf');%可以计数,计算概率密度,概率密度函数,累积概率密度函数等,通过‘normalization'来选择
[yi,xi]=ksdensity(x,xi);
figure
hold on 
%把x的数值用edge个直方图表示
histogram(x,edge,'normalization','pdf')
plot(xi,dens,'o-')
plot(xi,yi,'*-')
legend('histogram','histcounts','ksdensity')id = ismember(bin,1); %bin矩阵中是否包含1,返回0或1
x(id);
id = ismember(bin,20);
a = categorical(bin);
summary(a)

高斯分布概率密度柱状图

semilogy

clc
clear
x = 0:0.1:10;
y = exp(x);
figure
semilogy(x,10.^x) %如何理解对数坐标:我们可以保持对数值等距离摆放,这就是对数坐标系。

y=10^x

代码编程
赞赏

相关文章

LeetCode之Isomorphic Strings
LeetCode之Combination Sum III
LeetCode之Find Minimum in Rotated Sorted Array II
LeetCode之Majority Element II
LeetCode之Product of Array Except Self
LeetCodeConvert Sorted List to Binary Search Tree