clear all;
Ts = 1; %码元周期
N_sample = 1000; %每个码元抽样点数
fs=N_sample; %抽样频率
fs_c1 = 5; %载波1频率
fs_c2 = 15; %载波2频率
dt = Ts/N_sample; %抽样的时间间隔
N = 200; %码元数
t = 0:dt:(N*N_sample-1)*dt;
df = fs/length(t);
f = -fs/2:df:fs/2-df; %定义频率矢量(频谱图的横坐标)
% 基本码元 g(t) = 1
gt0 = zeros(1,N_sample);
gt1 = ones(1,N_sample); %单极性不归零
%生成随机码元
random_code = randi([0,1],1,N);
%单极性波形的最后结果
yt1 = zeros(1,N*N_sample-1); %单极性不归零NRZ波形
for i = 1:N
if random_code(i) == 1 %得到波形图
yt1((i-1)*N_sample+1:i*N_sample) = gt1; %单极性不归零NRZ波形
else
yt1((i-1)*N_sample+1:i*N_sample) = gt0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
subplot(211)
plot(t,yt1);
axis([0 8 -0.1 1.1]);
title('单极性不归零二进制基带信号');
xlabel('时间t/s');
grid;
subplot(212)
carrier1 = cos(2*pi*fs_c1*t);
carrier2 = cos(2*pi*fs_c2*t);
for i=1:length(t)
if yt1(i) == 0
yt1_mod(i) = carrier1(i);
else
yt1_mod(i) = carrier2(i);
end
end
plot(t,yt1_mod);
axis([0 8 -1.1 1.1]);
title('2FSK调制信号');
xlabel('时间t/s');
grid;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%频谱图
figure(2)
subplot(211)
fmt=fft(yt1); % 对时域信号进行FFT变换,计算其频谱
fmt=fftshift(fmt);
fmt=abs(fmt);
fmt_dB=fmt.^2/Ts;
maxF=max(fmt_dB);
fmt_dB=fmt_dB/maxF;
fmt_dB= 10*log10(fmt_dB +eps);
plot(f,fmt_dB);grid on;
axis([-5 5 -150 0]);
xlabel('频率(Hz)');ylabel('功率谱幅度值(dB)');
title('单极性不归零二进制基带信号功率谱密度(db)');
subplot(212)
fmt=fft(yt1_mod); % 对时域信号进行FFT变换,计算其频谱
fmt=fftshift(fmt);
fmt=abs(fmt);
fmt_dB=fmt.^2/Ts;
maxF=max(fmt_dB);
fmt_dB=fmt_dB/maxF;
fmt_dB= 10*log10(fmt_dB +eps);
plot(f,fmt_dB);grid on;
axis([-25 25 -150 0]);
xlabel('频率(Hz)');ylabel('功率谱幅度值(dB)');
title('2FSK调制信号功率谱密度(db)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%叠加噪声
figure(3)
subplot(211)
plot(t,yt1_mod);
axis([0 8 -1.1 1.1]);
title('2FSK调制信号');
xlabel('时间t/s');
grid;
subplot(212)
yt1_mod_awgn = awgn(yt1_mod,10,'measured');
plot(t,yt1_mod_awgn);
axis([0 8 -2 2]);
title('接收端叠加噪声后的FSK调制信号波形图');
xlabel('时间t/s');
grid;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%低通滤波,以5hz为中心
figure(4)
subplot(211)
% 进行低通滤波
fpass = 0;
fstop = 7;
[f1,fmt1] = IdealFilter(length(t),fs,fpass,fstop,fft(yt1_mod_awgn)); % 进行理想带通滤波
spf_t1 = ifft(fmt1);
plot(t,spf_t1);grid on;
axis([0 8 -1.1 1.1]);
xlabel('时间(s)');ylabel('电压值(V)');
title('FSK调制信号理想低通滤波后信号波形图mt1');
subplot(212)
spf1=fft(spf_t1); % 对时域信号进行FFT变换,计算其频谱
spf1=fftshift(spf1);
plot(f,abs(spf1));grid on;
axis([-30 30 -1000 40000]);
xlabel('频率(Hz)');ylabel('频谱幅度值');
title('FSK调制信号理想低通滤波结果f1');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%带通滤波,以10hz为中心
figure(5)
subplot(211)
% 进行低通滤波
fpass = 12;
fstop = 17;
[f2,fmt2] = IdealFilter(length(t),fs,fpass,fstop,fft(yt1_mod_awgn)); % 进行理想带通滤波
spf_t2 = ifft(fmt2);
plot(t,spf_t2);grid on;
axis([0 8 -1.1 1.1]);
xlabel('时间(s)');ylabel('电压值(V)');
title('FSK调制信号理想低通滤波后信号波形图mt2');
subplot(212)
spf2=fft(spf_t2); % 对时域信号进行FFT变换,计算其频谱
spf2=fftshift(spf2);
plot(f,abs(spf2));grid on;
axis([-30 30 -1000 40000]);
xlabel('频率(Hz)');ylabel('频谱幅度值');
title('FSK调制信号理想低通滤波结果f2');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%全波整流以5HZ载波进行
figure(6)
subplot(211)
spf_t1 = abs(spf_t1);
plot(t,spf_t1);
axis([0 8 -0.2 1.2]);
title('m1(t)全波整流信号波形图');
xlabel('时间t/s');
grid;
subplot(212)
spf1=fft(spf_t1); % 对时域信号进行FFT变换,计算其频谱
spf1=fftshift(spf1);
plot(f,abs(spf1));grid on;
axis([-30 30 -100 61000]);
xlabel('频率(Hz)');ylabel('频谱幅度值');
title('m1(t)全波整流信号幅频特性');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%包络检波,以频率为5hz的载波
figure(7)
subplot(211)
% 进行低通滤波
fpass = 0;
fstop = 5;
[f1,spf1] = IdealFilter(length(t),fs,fpass,fstop,fft(spf_t1)); % 此处的频谱不能用fftshift后的!!!!!
spf_t1 = ifft(spf1);
plot(t,spf_t1);grid on;
axis([0 8 -0.1 0.9]);
xlabel('时间(s)');ylabel('电压值(V)');
title('m1(t)包络检波信号波形图');
subplot(212)
spf=fft(spf_t1); % 对时域信号进行FFT变换,计算其频谱
spf1=fftshift(spf);
plot(f,abs(spf1));grid on;
axis([-15 15 -1 61000]);
xlabel('频率(Hz)');ylabel('频谱幅度值');
title('m1(t)包络检波信号的幅频特性');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%全波整流以10HZ载波进行
figure(8)
subplot(211)
spf_t2 = abs(spf_t2);
plot(t,spf_t2);
axis([0 8 -0.2 1.2]);
title('m2(t)全波整流信号波形图');
xlabel('时间t/s');
grid;
subplot(212)
spf2=fft(spf_t2); % 对时域信号进行FFT变换,计算其频谱
spf2=fftshift(spf2);
plot(f,abs(spf2));grid on;
axis([-40 40 -1000 61000]);
xlabel('频率(Hz)');ylabel('频谱幅度值');
title('m2(t)全波整流信号幅频特性');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%包络检波,以频率为10hz的载波
figure(9)
subplot(211)
% 进行低通滤波
fpass = 0;
fstop = 5;
[f1,spf2] = IdealFilter(length(t),fs,fpass,fstop,fft(spf_t2)); % 此处的频谱不能用fftshift后的!!!!!
spf_t2 = ifft(spf2);
plot(t,spf_t2);grid on;
axis([0 8 -0.1 0.8]);
xlabel('时间(s)');ylabel('电压值(V)');
title('m2(t)包络检波信号波形图');
subplot(212)
spf=fft(spf_t2); % 对时域信号进行FFT变换,计算其频谱
spf2=fftshift(spf);
plot(f,abs(spf2));grid on;
axis([-15 15 -1 61000]);
xlabel('频率(Hz)');ylabel('频谱幅度值');
title('m2(t)包络检波信号的幅频特性');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%恢复基带信号
r=zeros(1,N_sample*N);
for i = 1:N-1
if spf_t1((i-0.5)*N_sample) < spf_t2((i-0.5)*N_sample) %得到波形图
r((i-0.5)*N_sample+1:(i+0.5)*N_sample) = gt1; %单极性不归零NRZ波形
else
r((i-0.5)*N_sample+1:(i+0.5)*N_sample) = gt0;
end
end
figure(10)
subplot(211)
plot(t,yt1);
axis([0 12 -0.1 1.1]);
title('发送端的被调制信号波形图');
xlabel('时间t/s');
grid;
subplot(212)
plot(t,r);
axis([0 12 -0.1 1.1]);
title('接收采样判决后恢复的被调制信号波形图');
xlabel('时间t/s');
grid;
小王曾是少年
- 粉丝: 1w+
- 资源: 42
最新资源
- cTrader指标:Variety Period clock control panel:品种周期时钟控制面板
- cTrader指标:Variety Period time switching panel:品种周期时间切换面板
- 字符串遗传算法-excited-JS-plus1S.zippython
- 附件文件下载安装啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
- sdram verilog 代码
- GNOME-Dia-Diagram-Editor-0.97.1-1-Win32-Zip-2010-02-07.tar.gz
- 80删除有序数组中的重复项 II.zip
- 79单词搜索.zip(算法)
- GNOME-Dia-Diagram-Editor-Shapes-Repository-20130624.tar.gz
- GNOME-Dia-Diagram-Editor-0.97.3-13.1-Linux(rpm)-2024-09-13.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈