实验原理
实验代码
信噪比为20db时代码:
clear all;
close all;
%%%%%%% parameter settings %%%%%
Rb = 1000;%比特率
Rs = 1000;%符号率
Fs = 10000;%采样频率
N = 100000;%原始消息信号的长度
UpSampleRate = Fs/Rs; % 一个符号周期内采样点数
RollOff = 0.25;
Span = 6;
Sps = UpSampleRate;
SNR = 20;
fc= 2000;
%%%% 信源 %%%%%
%%% 随机信号
src_bit = randi([0,1],1,N);
src_sym= src_bit;
%升采样
src_upsamp_sym = zeros(1,N*UpSampleRate);
src_upsamp_sym(1:UpSampleRate:end) = src_sym;
%脉冲成形
h_rcos = rcosdesign(RollOff,Span,Sps,'sqrt');
rcos_src_sym =conv(h_rcos,src_upsamp_sym);
%上载波
time = [1:length(rcos_src_sym)]/Fs;
rcos_src_sym_carrier = rcos_src_sym.*cos(2*pi*fc.*time);
% 频域观察
fft_rcos_src_sym= abs(fft(rcos_src_sym))/Fs;
fft_rcos_src_sym_carrier= abs(fft(rcos_src_sym_carrier))/Fs;
Ds = Fs/length(rcos_src_sym);%频率分辨率
f_s = -Fs/2:Ds:Fs/2-Ds;
%只关注前20个符号
figure(1);
stem(src_bit(1:20));
title("原始消息序列");
figure(2);
subplot(2,1,1);
plot(rcos_src_sym(1:230));
title("升余弦滚降脉冲成形");
subplot(2,1,2);
plot(f_s,fftshift(fft_rcos_src_sym));
axis([-Fs/2,Fs/2,0,1]);
title("升余弦滚降脉冲成形频域观察");
figure(3);
subplot(2,1,1);
plot(time(1:230),rcos_src_sym_carrier(1:230));
title("2ASK调制后的波形");
subplot(2,1,2);
plot(f_s,fftshift(fft_rcos_src_sym_carrier));
axis([-Fs/2,Fs/2,0,1]);
title("2ASK调制后的波形频域观察");
%信道
rcos_src_sym_carrier_noise = awgn(rcos_src_sym_carrier,SNR);
%接收端
%相干解调
rcos_src_sym_noise = rcos_src_sym_carrier_noise.*cos(2*pi*fc.*time);
LPF_fir128=fir1(128,0.2);%生成低通滤波器
rcos_src_sym_LP = 2*conv(LPF_fir128,rcos_src_sym_noise);
%匹配滤波
h1_rcos = rcosdesign(RollOff,Span,Sps,'sqrt');
rcos_src_sym_MF =conv(h1_rcos,rcos_src_sym_LP );
%抽样判决
delay = Sps*Span+64;
rcos_src_sym_MF_option= rcos_src_sym_MF(delay:UpSampleRate:end);%抽样值中前N个值为有效值
rcos_src_sym_MF_option = rcos_src_sym_MF_option(1:N);
rcos_src_sym_MF_option_judge = [abs(rcos_src_sym_MF_option)>0.5];
figure(4);
subplot(3,1,1);
plot(rcos_src_sym_MF(1:delay+200));
title("匹配滤波后的波形");
subplot(3,1,2);
stem(rcos_src_sym_MF_option(1:20));
title("抽样后的结果");
subplot(3,1,3);
stem(rcos_src_sym_MF_option_judge(1:20));
title("判决后的结果");
绘制误码率曲线代码:(设置不同的信噪比,使用for循环求出不同信噪比条件下的误码率)
%误码率曲线的绘制
clear all;
close all;
%%%%%%% parameter settings %%%%%
Rb = 1000;%比特率
Rs = 1000;%符号率
Fs = 10000;%采样频率
N = 100000;%原始消息信号的长度
UpSampleRate = Fs/Rs; % 一个符号周期内采样点数
RollOff = 0.25;
Span = 6;
Sps = UpSampleRate;
SNR = 20;
fc= 2000;
%%%% 信源 %%%%%
%%% 随机信号
src_bit = randi([0,1],1,N);
src_sym= src_bit;
%升采样
src_upsamp_sym = zeros(1,N*UpSampleRate);
src_upsamp_sym(1:UpSampleRate:end) = src_sym;
%脉冲成形
h_rcos = rcosdesign(RollOff,Span,Sps,'sqrt');
rcos_src_sym =conv(h_rcos,src_upsamp_sym);
%上载波
time = [1:length(rcos_src_sym)]/Fs;
rcos_src_sym_carrier = rcos_src_sym.*cos(2*pi*fc.*time);
% 频域观察
fft_rcos_src_sym= abs(fft(rcos_src_sym))/Fs;
fft_rcos_src_sym_carrier= abs(fft(rcos_src_sym_carrier))/Fs;
Ds = Fs/length(rcos_src_sym);%频率分辨率
f_s = -Fs/2:Ds:Fs/2-Ds;
%只关注前20个符号
figure(1);
stem(src_bit(1:20));
title("原始消息序列");
figure(2);
subplot(2,1,1);
plot(rcos_src_sym(1:230));
title("升余弦滚降脉冲成形");
subplot(2,1,2);
plot(f_s,fftshift(fft_rcos_src_sym));
axis([-Fs/2,Fs/2,0,1]);
title("升余弦滚降脉冲成形频域观察");
figure(3);
subplot(2,1,1);
plot(time(1:230),rcos_src_sym_carrier(1:230));
title("2ASK调制后的波形");
subplot(2,1,2);
plot(f_s,fftshift(fft_rcos_src_sym_carrier));
axis([-Fs/2,Fs/2,0,1]);
title("2ASK调制后的波形频域观察");
snr_db_tab = 1:100;
SER = zeros(size(snr_db_tab));%实际误码率
for index = 1:length(snr_db_tab)
%信道
SNR = snr_db_tab(index);
rcos_src_sym_carrier_noise = awgn(rcos_src_sym_carrier,SNR);
%接收端
%相干解调
rcos_src_sym_noise = rcos_src_sym_carrier_noise.*cos(2*pi*fc.*time);
LPF_fir128=fir1(128,0.2);%生成低通滤波器
rcos_src_sym_LP = 2*conv(LPF_fir128,rcos_src_sym_noise);
%匹配滤波
h1_rcos = rcosdesign(RollOff,Span,Sps,'sqrt');
rcos_src_sym_MF =conv(h1_rcos,rcos_src_sym_LP );
%抽样判决
delay = Sps*Span+64;
rcos_src_sym_MF_option= rcos_src_sym_MF(delay:UpSampleRate:end);%抽样值中前N个值为有效值
rcos_src_sym_MF_option = rcos_src_sym_MF_option(1:N);
rcos_src_sym_MF_option_judge = [abs(rcos_src_sym_MF_option)>0.5];
%计算误码率
[num,ratio]=biterr(src_sym,rcos_src_sym_MF_option_judge);
SER(index) = ratio;
end
figure(4);
subplot(3,1,1);
plot(rcos_src_sym_MF(1:delay+200));
title("匹配滤波后的波形");
subplot(3,1,2);
stem(rcos_src_sym_MF_option(1:20));
title("抽样后的结果");
subplot(3,1,3);
stem(rcos_src_sym_MF_option_judge(1:20));
title("判决后的结果");
figure(5);
semilogy(snr_db_tab,SER);
title("误码率曲线");
运行结果
信噪比为20db时运行结果:(载波频率为2000hz,只绘制了前20个码元)
计算误符号率:
%计算误码率,由于是2ask误符号率与误比特率一样
[num,ratio]=biterr(src_sym,rcos_src_sym_MF_option_judge);
num;
ratio;
Snr=20db时,10万个符号错138个,误符号率为0.0014,可以接受.