分析2ASK信号在高斯信道和瑞利衰落信道的性能的matlab代码
时间: 2023-06-27 12:05:44 浏览: 75
以下是在高斯信道和瑞利衰落信道下分析2ASK信号的Matlab代码:
首先,我们需要生成2ASK信号:
```matlab
% 设置参数
fc = 1e6; % 信号频率
fs = 10e6; % 采样频率
t = 0:1/fs:1/fc; % 时间
A = 1; % 信号幅度
f = 2e3; % 调制频率
m = A*cos(2*pi*f*t); % 调制信号
% 生成2ASK信号
f0 = 10e3; % 基带信号频率
f1 = 20e3; % 高频载波频率
s = A/2*(1+m/f0).*cos(2*pi*f1*t); % 2ASK信号
```
接下来,我们可以在高斯信道和瑞利衰落信道下进行模拟。在高斯信道下,我们可以使用AWGN信道模型:
```matlab
% 在高斯信道下模拟
EbN0dB = 0:2:16; % 信噪比范围
EbN0 = 10.^(EbN0dB/10); % 转换为线性值
sigma = sqrt(1./(2*EbN0)); % 噪声标准差
numBits = 10000; % 模拟的比特数
BER_Gaussian = zeros(1,length(EbN0dB)); % 初始化误码率数组
for i=1:length(sigma)
% 添加高斯噪声
r = s + sigma(i)*randn(size(s));
% 解调信号
m_hat = r.*cos(2*pi*f1*t);
m_hat_filt = lowpass(m_hat,f0,fs);
m_hat_dec = downsample(m_hat_filt,fs/f0);
m_hat_dec(m_hat_dec>=0.5) = 1;
m_hat_dec(m_hat_dec<0.5) = 0;
% 计算误码率
BER_Gaussian(i) = sum(abs(m(1:length(m_hat_dec))-m_hat_dec))/length(m);
end
% 绘制误码率曲线
semilogy(EbN0dB,BER_Gaussian,'-o');
xlabel('Eb/N0 (dB)');
ylabel('BER');
title('2ASK in Gaussian Channel');
grid on;
```
在瑞利衰落信道下,我们可以使用Rayleigh信道模型:
```matlab
% 在瑞利衰落信道下模拟
numBits = 10000; % 模拟的比特数
BER_Rayleigh = zeros(1,length(EbN0dB)); % 初始化误码率数组
for i=1:length(sigma)
% 添加瑞利衰落
h = 1/sqrt(2)*(randn(size(s))+1j*randn(size(s))); % 生成复高斯随机数
r = s.*h;
% 解调信号
m_hat = r.*cos(2*pi*f1*t);
m_hat_filt = lowpass(m_hat,f0,fs);
m_hat_dec = downsample(m_hat_filt,fs/f0);
m_hat_dec(m_hat_dec>=0.5) = 1;
m_hat_dec(m_hat_dec<0.5) = 0;
% 计算误码率
BER_Rayleigh(i) = sum(abs(m(1:length(m_hat_dec))-m_hat_dec))/length(m);
end
% 绘制误码率曲线
semilogy(EbN0dB,BER_Rayleigh,'-o');
xlabel('Eb/N0 (dB)');
ylabel('BER');
title('2ASK in Rayleigh Fading Channel');
grid on;
```
完整的代码如下:
```matlab
% 设置参数
fc = 1e6; % 信号频率
fs = 10e6; % 采样频率
t = 0:1/fs:1/fc; % 时间
A = 1; % 信号幅度
f = 2e3; % 调制频率
m = A*cos(2*pi*f*t); % 调制信号
% 生成2ASK信号
f0 = 10e3; % 基带信号频率
f1 = 20e3; % 高频载波频率
s = A/2*(1+m/f0).*cos(2*pi*f1*t); % 2ASK信号
% 在高斯信道下模拟
EbN0dB = 0:2:16; % 信噪比范围
EbN0 = 10.^(EbN0dB/10); % 转换为线性值
sigma = sqrt(1./(2*EbN0)); % 噪声标准差
numBits = 10000; % 模拟的比特数
BER_Gaussian = zeros(1,length(EbN0dB)); % 初始化误码率数组
for i=1:length(sigma)
% 添加高斯噪声
r = s + sigma(i)*randn(size(s));
% 解调信号
m_hat = r.*cos(2*pi*f1*t);
m_hat_filt = lowpass(m_hat,f0,fs);
m_hat_dec = downsample(m_hat_filt,fs/f0);
m_hat_dec(m_hat_dec>=0.5) = 1;
m_hat_dec(m_hat_dec<0.5) = 0;
% 计算误码率
BER_Gaussian(i) = sum(abs(m(1:length(m_hat_dec))-m_hat_dec))/length(m);
end
% 绘制误码率曲线
semilogy(EbN0dB,BER_Gaussian,'-o');
xlabel('Eb/N0 (dB)');
ylabel('BER');
title('2ASK in Gaussian Channel');
grid on;
% 在瑞利衰落信道下模拟
numBits = 10000; % 模拟的比特数
BER_Rayleigh = zeros(1,length(EbN0dB)); % 初始化误码率数组
for i=1:length(sigma)
% 添加瑞利衰落
h = 1/sqrt(2)*(randn(size(s))+1j*randn(size(s))); % 生成复高斯随机数
r = s.*h;
% 解调信号
m_hat = r.*cos(2*pi*f1*t);
m_hat_filt = lowpass(m_hat,f0,fs);
m_hat_dec = downsample(m_hat_filt,fs/f0);
m_hat_dec(m_hat_dec>=0.5) = 1;
m_hat_dec(m_hat_dec<0.5) = 0;
% 计算误码率
BER_Rayleigh(i) = sum(abs(m(1:length(m_hat_dec))-m_hat_dec))/length(m);
end
% 绘制误码率曲线
semilogy(EbN0dB,BER_Rayleigh,'-o');
xlabel('Eb/N0 (dB)');
ylabel('BER');
title('2ASK in Rayleigh Fading Channel');
grid on;
```
阅读全文