%% 2ASK调制解调仿真
clear;clc;
close all;
%% 系统仿真参数
A = 1; %载波信号振幅
fc = 2; %载波信号频率
snr = 15; %信噪比
N_Sample = 8; %基带信号中每个码元的采样点数
N = 10000; %码元个数
Ts = 1; %码元宽度
df = 0.01; %频率分辨率
B = 1/Ts; %码元带宽
f_start = fc - B; %滤波器起始频率
f_cutoff = fc + B; %滤波器截至频率
fs = fc *N_Sample; %系统采样频率,即考虑载波后,一个码元内的采样点数
ts = Ts/fs; %系统采样间隔
t = 0:ts:N*Ts-ts;
Lt = length(t);
%% 调制信号及其功率谱密度
%% 单极性不归零信号
d = sign(randn(1,N));
dd = sigexpand((d+1)/2,fc*N_Sample);
gt = ones(1,fc*N_Sample);%NRZ波形
d_NRZ = conv(dd,gt);
d_NRZ1 = d_NRZ(1:Lt);
figure(1);
subplot(221);
plot(t,d_NRZ1);
axis([0,10,-0.2,1.2]);
xlabel('t');title('单极性NRZ信号');
subplot(222);
[d_NRZ1f,d_NRZ1,df1,f] = T2F_new(d_NRZ1,ts,df,fs);
plot(f,10*log10(abs(fftshift(d_NRZ1f).^2/length(f))));
axis([-5*B,5*B,-50,0]);
xlabel('f');title('单极性NRZ信号功率谱密度');
%% 2ASK
%对数字基带信号进行2ASK调制
ht = A * sin(2*pi*fc*t); %载波
s_2ask = d_NRZ(1:Lt).*ht; %生成2ASK信号
subplot(223);
plot(t,s_2ask);
axis([0,10,-1.2,1.2]);
xlabel('t');title('2ASK信号波形');
[s_2askf,s_2ask,df1,f] = T2F_new(s_2ask,ts,df,fs);
subplot(224);
plot(f,10*log10(abs(fftshift(s_2askf).^2/length(f))));
axis([-fc-3*B,fc+3*B,-50,0]);
xlabel('f');title('2ASK信号功率谱密度');
%% 生成信道加性高斯白噪声
snr_lin = 10^(snr/10);
signal_energy = 0.5 * A^2 * Ts;%接收信号的平均能量
noise_power = (signal_energy * fs) / (snr_lin * 4);%求出噪声方差(噪声均值为0)
noise_std = sqrt(noise_power);%求出噪声均方差
noise = noise_std .* randn(1,Lt);%以噪声均方差作为幅度产生高斯白噪声
figure(2);
subplot(221);
plot(t,noise(1:Lt));
xlabel('t');title('信道噪声');
axis([0,10,-3,3]);
[noisef,noise,df1,f] = T2F_new(noise,ts,df,fs);
subplot(222);
plot(f,10*log10(abs(fftshift(noisef).^2/length(f))));
axis([-fc-3*B,fc+3*B,-50,0]);
xlabel('f');title('信道噪声功率谱密度');
%% 将2ASK信号送入信道
r = s_2ask(1:Lt) + noise(1:Lt);%叠加了噪声的已调信号,相当于将已调信号送入理想信道
subplot(223);
plot(t,r);%画出叠加噪声后的已调2PSK信号
xlabel('t');title('加燥2ASK信号');
axis([0,10,-3,3]);
[rf,r,df1,f] = T2F_new(r,ts,df,fs);
subplot(224);
plot(f,10*log10(abs(fftshift(rf).^2/length(f))));
axis([-fc-3*B,fc+3*B,-50,0]);
xlabel('f');title('加燥2ASK信号功率谱密度');
%% 在接收端准备进行解调,先通过带通滤波器
%% 带通滤波器
[H,f] = bp_f(length(rf),f_start,f_cutoff,df1,fs,1);
figure(3);
subplot(311);
plot(f,abs(fftshift(H)));
axis([-fc-3*B,fc+3*B,-0.2,1.2]);
xlabel('f');title('理想带通滤波器');
%% 信号经过理想带通滤波器
DEM = H .* rf;
[dem] = F2T_new(DEM,fs);
dem1 = dem(1:Lt);
subplot(323);
plot(t,dem1);
axis([0,10,-4,4]);
xlabel('t');title('理想带通滤波器输出信号');
[demf1,dem1,df1,f] = T2F_new(dem1,ts,df,fs);
subplot(324);
plot(f,10*log10(abs(fftshift(demf1).^2/length(f))));
axis([-fc-3*B,fc+3*B,-50,0]);
xlabel('f');title('理想带通滤波器输出信号功率谱密度');
%% 本地载波
subplot(325);
plot(t,ht);
axis([0,10,-1.2,1.2]);
xlabel('t');title('本地载波');
subplot(326);
[htf,ht,df1,f] = T2F_new(ht,ts,df,fs);
plot(f,fftshift(abs(htf)));
axis([-fc-3*B,fc+3*B,0,15]);
xlabel('f');title('本地载波频谱');
%% 混频
figure(4);
der = dem(1:Lt) .* ht(1:Lt);%和本地载波相乘,即混频
subplot(221);
plot(t,der);
axis([0,10,-2,2]);
xlabel('t');title('混频后的信号');
[derf,der,df1,f] = T2F_new(der,ts,df,fs);
subplot(222);
plot(f,10*log10(abs(fftshift(derf).^2/length(f))));
axis([-fc-3*B,fc+3*B,-50,0]);
xlabel('f');title('混频信号功率谱密度');
%% 低通滤波器
[LPF,f] = lp_f(length(derf),B,df1,fs,1);%求低通滤波器
subplot(212);
plot(f,fftshift(abs(LPF)));
axis([-fc-3*B,fc+3*B,-0.2,1.2]);
xlabel('f');title('理想低通滤波器');
%% 信号经过低通滤波器
figure(5);
DM = LPF .* derf;%信号经过理想低通滤波器
[dm] = F2T_new(DM,fs);
subplot(221);
plot(t,dm(1:Lt));
axis([0,10,-1.2,1.2]);
xlabel('t');title('低通滤波器输出信号');
set(gca,'YTick',-1:1:1);
set(gca,'YGrid','on');
subplot(222);
[demf,dem,df1,f] = T2F_new(dm,ts,df,fs);
plot(f,10*log10(abs(fftshift(demf).^2/length(f))));
axis([-fc-3*B,fc+3*B,-50,0]);
xlabel('f');title('低通滤波器输出信号功率谱密度');
%% 抽样判决
dm = dm(1:Lt);
panjue = zeros(1,N);%建立存储判决值的矩阵
for i = 1:N
if dm(fc * N_Sample * (i-1) + fc * N_Sample/2+1) >= 1/2*(max(dm) + min(dm)) %抽样判决时刻
panjue(i) = 1;
else
panjue(i) = 0;
end
end
%% 判决后得到的基带信号
rr = sigexpand(panjue,fc*N_Sample);
rrt = ones(1,fc*N_Sample);%NRZ波形
huifu_NRZ = conv(rr,rrt);
subplot(224);
plot(t,d_NRZ(1:Lt));
axis([0,10,min(d_NRZ)-0.2,max(d_NRZ)+0.2]);
xlabel('t');title('调制信号');
subplot(223);
plot(t,huifu_NRZ(1:Lt));
axis([0,10,min(huifu_NRZ)-0.2,max(huifu_NRZ)+0.2]);
xlabel('t');title('解调信号');
%% 统计误码数
numoferr = sum(abs(panjue-d)/2)/N; %计算出错误码元数
fprintf('误码率为:%d\n',numoferr);
小贝德罗
- 粉丝: 85
- 资源: 1万+
最新资源
- C语言-leetcode题解之28-implement-strstr.c
- C语言-leetcode题解之27-remove-element.c
- C语言-leetcode题解之26-remove-duplicates-from-sorted-array.c
- C语言-leetcode题解之24-swap-nodes-in-pairs.c
- C语言-leetcode题解之22-generate-parentheses.c
- C语言-leetcode题解之21-merge-two-sorted-lists.c
- java-leetcode题解之Online Stock Span.java
- java-leetcode题解之Online Majority Element In Subarray.java
- java-leetcode题解之Odd Even Jump.java
- 计算机毕业设计:python+爬虫+cnki网站爬
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈