matlab编写2psk、qpsk、8psk的调制解调误码分析
时间: 2023-06-10 20:09:13 浏览: 84
2PSK调制解调:
以下是MATLAB代码示例:
% 生成2PSK调制所的随机比特串
N = 100; % 比特串长度
bits = rand([0 1],N,1);
% 将特串变为符号
symbols = 2*bits-1;
% 生成调制波形
fc = 100; % 载波频率
t = 0:1e-5:(N/2e6-1e-5); % 时间轴
carrier = cos(2*pi*fc*t);
modulated = symbols.'.*carrier;
% 生成加性高斯白噪声
EbNo = 10; % 信噪比
snr = EbNo + 10*log10(log2(length(symbols))); % SNR
noise = randn(1,length(modulated));
noise_power = 10^(-snr/10);
scaled_noise = sqrt(noise_power)*noise;
% 加入噪声得到接收信号
received = modulated + scaled_noise;
% 解调
demodulated = received.*carrier;
demodulated_symbols = sign(demodulated);
% 误码分析
errors = sum(bits~=((demodulated_symbols+1)/2));
BER = errors/N;
QPSK调制解调:
以下是MATLAB代码示例:
% 生成QPSK调制所需的随机比特串
N = 1000; % 比特串长度
bits = randi([0 1],N,1);
% 将比特串转换为符号
I = 2*bits(1:2:end)-1; % 一个符号的I部分
Q = 2*bits(2:2:end)-1; % 一个符号的Q部分
symbols = I + 1i*Q;
% 生成调制波形
fc = 100; % 载波频率
t = 0:1e-5:(N/4e6-1e-5); % 时间轴
carrier = cos(2*pi*fc*t) + 1i*sin(2*pi*fc*t);
modulated = symbols.'.*carrier;
% 生成加性高斯白噪声
EbNo = 10; % 信噪比
snr = EbNo + 10*log10(log2(length(symbols))); % SNR
noise = randn(1,length(modulated));
noise_power = 10^(-snr/10);
scaled_noise = sqrt(noise_power/2)*(noise+1i*noise);
% 加入噪声得到接收信号
received = modulated + scaled_noise;
% 解调
demodulated = received./carrier;
I_demod = real(demodulated);
Q_demod = imag(demodulated);
demodulated_symbols = zeros(N/2,1);
demodulated_symbols(1:2:end) = (I_demod>0)*2-1;
demodulated_symbols(2:2:end) = (Q_demod>0)*2-1;
% 误码分析
errors = sum(bits~=reshape(de2bi((demodulated_symbols+1)/2,2).',[],1));
BER = errors/N;
8PSK调制解调:
以下是MATLAB代码示例:
% 生成8PSK调制所需的随机比特串
N = 1000; % 比特串长度
bits = randi([0 1],N,1);
% 将比特串转换为符号
symbols = zeros(N/3,1);
for i = 1:N/3
symbols(i) = bi2de(bits((i-1)*3+1:i*3).','left-msb');
end
symbols = exp(1i*2*pi/8*(symbols-1));
% 生成调制波形
fc = 100; % 载波频率
t = 0:1e-5:(N/3e6-1e-5); % 时间轴
carrier = cos(2*pi*fc*t) + 1i*sin(2*pi*fc*t);
modulated = symbols.'.*carrier;
% 生成加性高斯白噪声
EbNo = 10; % 信噪比
snr = EbNo + 10*log10(log2(length(symbols))); % SNR
noise = randn(1,length(modulated));
noise_power = 10^(-snr/10);
scaled_noise = sqrt(noise_power/2)*(noise+1i*noise);
% 加入噪声得到接收信号
received = modulated + scaled_noise;
% 解调
demodulated = received./carrier;
angles = angle(demodulated);
angles(angles<0) = angles(angles<0)+2*pi;
demodulated_symbols = ceil(angles/(2*pi/8));
% 将符号转换为比特串
bits_received = de2bi(demodulated_symbols-1,3,'left-msb');
bits_received = reshape(bits_received.',[],1);
% 误码分析
errors = sum(bits~=bits_received);
BER = errors/N;
阅读全文