返回顶部

PAM咨询——

%定义参数
M = 2;    %定义为M元调制
Rs = 1000; % 定义波特率
Rb = Rs*log2(M); %计算比特率
Ts = 1/Rs;   %计算符号发送间隔
sample_rate = 100*Rs; % 采样率
EbN0 =0:15;%传送每个比特所用能量平均值/噪声单边功率谱密度(单位:dB)

% 生成随机比特序列
num_bits = 100000;% 比特数
bit_sequence = randi([0, 1], 1, num_bits);
bit_sequence_dou = bit_sequence*2-1;
t_origin = (0:num_bits-1)*Ts; %显示时间(按发送间隔)

% ber = zeros(1,length(EbN0));
% ber_dou =zeros(1,length(EbN0));

%设置矩形脉冲NRZ发送滤波器
% 脉冲的幅度
A = 1; 
% 生成时间向量
t_sendfilter = 0:1/sample_rate:Ts-1/sample_rate;
% 生成矩形脉冲滤波器
rect_pulse_filter = [A * ones(1, length(t_sendfilter))];

% 上采样发送序列(每个数据后添0)
upsampled_bits = zeros(1, length(bit_sequence)*sample_rate*Ts);
upsampled_bits(1:sample_rate*Ts:end) = bit_sequence;
t_upsampled = 0:1/sample_rate:(length(upsampled_bits)-1)/sample_rate;
%Double
upsampled_bits_dou = zeros(1, length(bit_sequence_dou)*sample_rate*Ts);
upsampled_bits_dou(1:sample_rate*Ts:end) = bit_sequence_dou;

% 将上采样的发送序列通过滤波器
s_rz = conv(upsampled_bits, rect_pulse_filter, 'full');
s_rz = s_rz(1:sample_rate/Rs*num_bits);

% 将上采样的发送序列通过滤波器 Double
s_rz_dou = conv(upsampled_bits_dou, rect_pulse_filter, 'full');
s_rz_dou = s_rz_dou(1:sample_rate/Rs*num_bits);

% 生成时间向量
t_send = (0:length(s_rz)-1) / sample_rate;
% %求s_rz的功率谱
% [P_srz, f_srz] = periodogram(s_rz,[],[],sample_rate);

for indx=1:length(EbN0)
%加噪声
s_rz_noise=awgn(s_rz,EbN0(indx)+10*log10(2*Rb/sample_rate),'measured');
s_rz_noise_dou = awgn(s_rz_dou,EbN0(indx)+10*log10(2*Rb/sample_rate),'measured');
%LPF
% d = designfilt('lowpassfir', 'FilterOrder', 50,  'CutoffFrequency', 2*Rs, 'SampleRate', sample_rate);
% y_first = filter(d, s_rz_noise);
% % y_first = conv(s_rz_noise, b);          % 通过滤波器  
% y = y_first(n/2+1:end-n/2);     % 移除滤波器产生的过渡带  

d = designfilt('lowpassfir', 'FilterOrder', 80,  'CutoffFrequency', 2*Rs, 'SampleRate', sample_rate);
y = filter(d, s_rz_noise);

% 验证基带信号带宽B
% passband = [0 2*Rs]; % 通带频率范围
% original_signal = s_rz_noise;
% fs = sample_rate;
%     % 使用傅里叶变换将modulated_signal转换为频域表示  与前面画频谱的时候是一样的操作 但是不在乎复杂度 hhh
% original_signal_spectrum = fftshift(fft(original_signal));
%     % 确定要保留的频率范围,将其他频率分量置零
% f1 = (-fs/2 : fs/length(original_signal) : fs/2 - fs/length(original_signal));
% original_signal_spectrum(abs(f1) < passband(1) | abs(f1) > passband(2)) = 0;
% filtered_signal_spectrum = original_signal_spectrum;
%     % 使用逆傅里叶变换将修改后的频域信号转换回时域表示
% filtered_original_signal = ifft(ifftshift(filtered_signal_spectrum));
% y = filtered_original_signal;
%采点
rn = y(Ts*sample_rate/2:Ts*sample_rate:num_bits*Ts*sample_rate);

% 生成时间向量2
t_rev = (0:length(y)-1) / sample_rate;

%判决
%计算门限值
threshold = 0.5;

rev_bit_sequences = zeros(1, length(rn)); % 预分配决策向量的空间

for i = 1:length(rn)
    if rn(i) > threshold
        rev_bit_sequences(i) = 1;
    else
        rev_bit_sequences(i) = 0;
    end
end



% original_signal_dou = s_rz_noise_dou;
% original_signal_spectrum_dou = fftshift(fft(original_signal_dou));
%     % 确定要保留的频率范围,将其他频率分量置零
% f1_dou = (-fs/2 : fs/length(original_signal_dou) : fs/2 - fs/length(original_signal_dou));
% original_signal_spectrum_dou(abs(f1_dou) < passband(1) | abs(f1_dou) > passband(2)) = 0;
% filtered_signal_spectrum_dou = original_signal_spectrum_dou;
%     % 使用逆傅里叶变换将修改后的频域信号转换回时域表示
% filtered_original_signal_dou = ifft(ifftshift(filtered_signal_spectrum_dou));
% y_dou = filtered_original_signal_dou;
%采点

d = designfilt('lowpassfir', 'FilterOrder', 80,  'CutoffFrequency', 2*Rs, 'SampleRate', sample_rate);
y = filter(d, s_rz_noise_dou);
rn_dou = y_dou(Ts*sample_rate/2:Ts*sample_rate:num_bits*Ts*sample_rate);

rev_bit_sequences_dou = zeros(1, length(rn_dou)); % 预分配决策向量的空间

for i = 1:length(rn)
    if rn_dou(i) > 0
        rev_bit_sequences_dou(i) = 1;
    else
        rev_bit_sequences_dou(i) = -1;
    end
end
%计算误比特率
[numErrors, ber80(indx)] = biterr(bit_sequence, rev_bit_sequences);
error_count80(indx) = ;
ber_dou80(indx) = error_count80(indx) / length(bit_sequence);
bit_error_theory80(indx) =qfunc(sqrt((10.^(EbN0(indx)/10))/2));
bit_error_dou80(indx)=qfunc(sqrt((10.^(EbN0(indx)/10))));
end

%以下绘图
figure;
plot(EbN0, ber, '-r*', EbN0, ber_dou, '-k*', EbN0, bit_error_theory, '-ro',EbN0, bit_error_dou, '-ko');
title('2-PAM信号在AWGN信道下的性能(线性坐标)')
xlabel('Eb/N0(dB)');ylabel('误符号率')
legend('单极性误比特率','双极性误比特率','单极性理论误比特率','双极性理论误比特率')
grid  on

figure;
semilogy(EbN0,bit_error_theory,'-ro',EbN0,ber,'-co',EbN0,ber200,'-r*',EbN0,ber80,'-k^',EbN0,ber70,'-g*',EbN0,ber60,'-c*',EbN0,ber1,'-k*',EbN0,ber40,'-m*',EbN0,ber30,'-b*',EbN0,ber20,'-y*');
title('2-PAM信号在AWGN信道下的性能(对数坐标)')
xlabel('Eb/N0(dB)');ylabel('误符号率')
legend('理论误比特率','误比特率-理想LPF','误比特率-200阶','误比特率-80阶','误比特率-70阶','误比特率-60阶','误比特率-50阶','误比特率-40阶','误比特率-30阶','误比特率-20阶')
grid  on

关于实现低通滤波器 一定要考虑延时 收、发节拍一定要踩准

posted @ 2023-11-05 16:40  YuhangLiuCE  阅读(5)  评论(0编辑  收藏  举报