L_rem=L-l,其中,L符合均值为11.16,标准差为2.7的正态分布概率密度函数, l符合0到100范围内的随机分布函数。求解L_rem的概率密度函数的matlab代码
时间: 2024-05-06 16:18:39 浏览: 22
假设L和l是独立的随机变量,其中L符合均值为11.16,标准差为2.7的正态分布概率密度函数,l符合0到100范围内的均匀分布函数。则L_rem=L-l也是一个随机变量,其概率密度函数可以通过卷积计算得到。
以下是MATLAB代码:
```matlab
% 定义正态分布函数
mu = 11.16;
sigma = 2.7;
L = makedist('Normal', mu, sigma);
% 定义均匀分布函数
a = 0;
b = 100;
l = makedist('Uniform', a, b);
% 计算L_rem的概率密度函数
L_rem = conv(L.pdf, l.pdf, 'full');
x = linspace(-100, 100, length(L_rem));
plot(x, L_rem)
xlabel('L_{rem}')
ylabel('概率密度函数')
title('L_{rem}的概率密度函数')
```
运行后,就可以得到L_rem的概率密度函数的图像。
相关问题
def fpe(frame_phone_input,root): phone_input = frame_phone_input.get() def fpe_encrypt(plaintext, key, radix=10, rounds=4): # 对明文进行哈希 hash_val = hmac.new(key.encode(), plaintext.encode(), hashlib.sha256).digest() # 将哈希值转换为整数 num_val = int.from_bytes(hash_val, byteorder='big') # 将整数转换为指定进制的字符串 str_val = '' while num_val > 0: num_val, rem = divmod(num_val, radix) str_val = str(rem) + str_val # 对字符串进行 FPE 加密 for i in range(rounds): str_val = ''.join([chr((ord(c) - ord('0') + i) % (radix - 1) + ord('0')) for c in str_val]) # 返回加密后的字符串 return str_val key = 'my-secret-key' encrypted = fpe_encrypt(phone_input, key) phone_label = tk.Label(root, text=("加密后的手机号:", encrypted), font=("微软雅黑 -20")) phone_label.place(x=500, y=560)怎么把加密后的手机号分三行显示
你可以使用字符串的切片功能将加密后的手机号分成三段,然后分别显示在三个 Label 中。下面是一个修改过的代码示例:
```
def fpe(frame_phone_input, root):
phone_input = frame_phone_input.get()
def fpe_encrypt(plaintext, key, radix=10, rounds=4):
# 对明文进行哈希
hash_val = hmac.new(key.encode(), plaintext.encode(), hashlib.sha256).digest()
# 将哈希值转换为整数
num_val = int.from_bytes(hash_val, byteorder='big')
# 将整数转换为指定进制的字符串
str_val = ''
while num_val > 0:
num_val, rem = divmod(num_val, radix)
str_val = str(rem) + str_val
# 对字符串进行 FPE 加密
for i in range(rounds):
str_val = ''.join([chr((ord(c) - ord('0') + i) % (radix - 1) + ord('0')) for c in str_val])
# 返回加密后的字符串
return str_val
key = 'my-secret-key'
encrypted = fpe_encrypt(phone_input, key)
# 将加密后的手机号分成三段
chunk_size = len(encrypted) // 3
chunk1 = encrypted[:chunk_size]
chunk2 = encrypted[chunk_size:2*chunk_size]
chunk3 = encrypted[2*chunk_size:]
# 在三个 Label 中分别显示加密后的手机号的三段
phone_label1 = tk.Label(root, text=("加密后的手机号:", chunk1), font=("微软雅黑 -20"))
phone_label1.place(x=500, y=560)
phone_label2 = tk.Label(root, text=chunk2, font=("微软雅黑 -20"))
phone_label2.place(x=500, y=590)
phone_label3 = tk.Label(root, text=chunk3, font=("微软雅黑 -20"))
phone_label3.place(x=500, y=620)
```
这样,加密后的手机号就会分成三行显示。
clear all; close all; clc;ticits_option = 2;noise_option = 1;raw_bit_len = 2592-6;interleaving_num = 72;deinterleaving_num = 72;N_frame = 1e4;SNRdBs = [0:2:20];sq05 = sqrt(0.5);bits_options = [0, 1, 2]; % 三种bits-option情况obe_target = 500;BER_target = 1e-3;for i_bits = 1:length(bits_options) bits_option = bits_options(i_bits); BER = zeros(size(SNRdBs)); for i_SNR = 1:length(SNRdBs) sig_power = 1; SNRdB = SNRdBs(i_SNR); sigma2 = sig_power * 10^(-SNRdB/10); sigma = sqrt(sigma2/2); nobe = 0; for i_frame = 1:N_frame switch bits_option case 0 bits = zeros(1, raw_bit_len); case 1 bits = ones(1, raw_bit_len); case 2 bits = randi([0,1], 1, raw_bit_len); end encoding_bits = convolution_encoder(bits); interleaved = []; for i = 1:interleaving_num interleaved = [interleaved encoding_bits([i:interleaving_num:end])]; end temp_bit = []; for tx_time = 1:648 tx_bits = interleaved(1:8); interleaved(1:8) = []; QAM16_symbol = QAM16_mod(tx_bits, 2); x(1,1) = QAM16_symbol(1); x(2,1) = QAM16_symbol(2); if rem(tx_time - 1, 81) == 0 H = sq05 * (randn(2,2) + j * randn(2,2)); end y = H * x; if noise_option == 1 noise = sigma * (randn(2,1) + j * randn(2,1)); y = y + noise; end W = inv(H' * H + sigma2 * diag(ones(1,2))) * H'; K_tilde = W * y; x_hat = QAM16_slicer(K_tilde, 2); temp_bit = [temp_bit QAM16_demapper(x_hat, 2)]; end deinterleaved = []; for i = 1:deinterleaving_num deinterleaved = [deinterleaved temp_bit([i:deinterleaving_num:end])]; end received_bit = Viterbi_decode(deinterleaved); for EC_dummy = 1:1:raw_bit_len if nobe >= obe_target break; end if received_bit(EC_dummy) ~= bits(EC_dummy) nobe = nobe + 1; end end if nobe >= obe_target break; end end BER(i_SNR) = nobe / (i_frame * raw_bit_len); fprintf('bits-option: %d, SNR: %d dB, BER: %1.4f\n', bits_option, SNRdB, BER(i_SNR)); end figure; semilogy(SNRdBs, BER); xlabel('SNR (dB)'); ylabel('BER'); title(['Bits-Option: ', num2str(bits_option)]); grid on;end注释这段matlab代码
这是一段 Matlab 代码,以下是对其的注释:
```
% 清空所有变量、关闭所有图形窗口、清空命令行窗口、开始计时
clear all; close all; clc; tic
% 设置模拟参数
its_option = 2; % 暂时不知道其含义
noise_option = 1; % 噪声选项,1表示添加高斯白噪声,0表示不添加
raw_bit_len = 2592-6; % 原始比特长度,不包括尾部比特
interleaving_num = 72; % 扰码器长度
deinterleaving_num = 72; % 解扰码器长度
N_frame = 1e4; % 帧数
SNRdBs = [0:2:20]; % 信噪比范围
sq05 = sqrt(0.5); % sqrt(0.5)的值
bits_options = [0, 1, 2]; % 三种bits-option情况
obe_target = 500; % 最大误比特数目
BER_target = 1e-3; % 误比特率目标
% 循环处理三种bits-option情况
for i_bits = 1:length(bits_options)
bits_option = bits_options(i_bits);
BER = zeros(size(SNRdBs)); % 初始化误比特率
for i_SNR = 1:length(SNRdBs)
sig_power = 1; % 信号功率
SNRdB = SNRdBs(i_SNR); % 当前信噪比
sigma2 = sig_power * 10^(-SNRdB/10); % 方差
sigma = sqrt(sigma2/2); % 标准差
nobe = 0; % 误比特数目
for i_frame = 1:N_frame
switch bits_option
case 0
bits = zeros(1, raw_bit_len);
case 1
bits = ones(1, raw_bit_len);
case 2
bits = randi([0,1], 1, raw_bit_len);
end
encoding_bits = convolution_encoder(bits); % 卷积编码
% 扰码器
interleaved = [];
for i = 1:interleaving_num
interleaved = [interleaved encoding_bits([i:interleaving_num:end])];
end
temp_bit = [];
for tx_time = 1:648
tx_bits = interleaved(1:8);
interleaved(1:8) = [];
QAM16_symbol = QAM16_mod(tx_bits, 2); % 16QAM调制
x(1,1) = QAM16_symbol(1);
x(2,1) = QAM16_symbol(2);
if rem(tx_time - 1, 81) == 0 % 每81个时隙变化一次信道
H = sq05 * (randn(2,2) + j * randn(2,2));
end
y = H * x; % 信道传输
if noise_option == 1 % 添加高斯白噪声
noise = sigma * (randn(2,1) + j * randn(2,1));
y = y + noise;
end
W = inv(H' * H + sigma2 * diag(ones(1,2))) * H'; % MMSE检测
K_tilde = W * y;
x_hat = QAM16_slicer(K_tilde, 2); % 16QAM解调
temp_bit = [temp_bit QAM16_demapper(x_hat, 2)]; % 16QAM解调映射
end
% 解扰码器
deinterleaved = [];
for i = 1:deinterleaving_num
deinterleaved = [deinterleaved temp_bit([i:deinterleaving_num:end])];
end
received_bit = Viterbi_decode(deinterleaved); % Viterbi译码
% 统计误比特数目
for EC_dummy = 1:1:raw_bit_len
if nobe >= obe_target
break;
end
if received_bit(EC_dummy) ~= bits(EC_dummy)
nobe = nobe + 1;
end
end
if nobe >= obe_target
break;
end
end
BER(i_SNR) = nobe / (i_frame * raw_bit_len); % 计算误比特率
fprintf('bits-option: %d, SNR: %d dB, BER: %1.4f\n', bits_option, SNRdB, BER(i_SNR));
end
% 画图
figure;
semilogy(SNRdBs, BER);
xlabel('SNR (dB)');
ylabel('BER');
title(['Bits-Option: ', num2str(bits_option)]);
grid on;
end
% 结束计时
toc
```
注释解释:
- `%` 表示单行注释,用于注释代码的某一行。
- `clear all; close all; clc; tic` 表示清空所有变量、关闭所有图形窗口、清空命令行窗口、开始计时。
- `its_option = 2;` 表示设置模拟参数 `its_option`,但是没有注释说明其具体含义。
- `noise_option = 1;` 表示设置噪声选项,`1` 表示添加高斯白噪声,`0` 表示不添加。
- `raw_bit_len = 2592-6;` 表示设置原始比特长度,不包括尾部比特。
- `interleaving_num = 72;` 表示设置扰码器长度。
- `deinterleaving_num = 72;` 表示设置解扰码器长度。
- `N_frame = 1e4;` 表示设置帧数。
- `SNRdBs = [0:2:20];` 表示设置信噪比范围。
- `sq05 = sqrt(0.5);` 表示设置 sqrt(0.5) 的值。
- `bits_options = [0, 1, 2];` 表示设置三种 `bits-option` 情况。
- `obe_target = 500;` 表示设置最大误比特数目。
- `BER_target = 1e-3;` 表示设置误比特率目标。
- `for i_bits = 1:length(bits_options)` 开始循环处理三种 `bits-option` 情况。
- `switch bits_option` 根据 `bits-option` 的值选择不同的情况。
- `QAM16_symbol = QAM16_mod(tx_bits, 2);` 表示进行 16QAM 调制。
- `if rem(tx_time - 1, 81) == 0` 表示每 81 个时隙变化一次信道。
- `if noise_option == 1` 表示添加高斯白噪声。
- `x_hat = QAM16_slicer(K_tilde, 2);` 表示进行 16QAM 解调。
- `temp_bit = [temp_bit QAM16_demapper(x_hat, 2)];` 表示进行 16QAM 解调映射。
- `received_bit = Viterbi_decode(deinterleaved);` 表示进行 Viterbi 译码。
- `BER(i_SNR) = nobe / (i_frame * raw_bit_len);` 表示计算误比特率。
- `semilogy(SNRdBs, BER);` 表示画图,使用对数坐标轴。
- `toc` 表示结束计时。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)