www.pudn.com > gaijin_signal_generator.rar > gaijin_signal_generator.m, change:2010-11-21,size:9099b


 
function signal_noise=gaijin_signal_generator(modulation_mode) 
% clc;clear;close all; 
Fc=100;%载波频率 
Fd=10;%数字传输频率 
Fs=1000;%采样频率 
K=1;%The legth of message signal 
signal_noise=[]; 
if modulation_mode==1 
%2ASK调制信号的产生 
amp_2ask=randint(1,K*100);%产生信息信号 
amp_2ask_mod=zeros(1,100*length(amp_2ask)); 
for i=1:length(amp_2ask) 
    amp_2ask_mod(:,((i*100)-99):i*100)=amp_2ask(i)*ones(1,100); 
end 
fre_2ask_mod=zeros(1,100*length(amp_2ask)); 
for i=1:length(fre_2ask_mod) 
    fre_2ask_mod(i)=2*pi*Fc*i/Fs; 
end 
car_2ask_mod=cos(fre_2ask_mod); 
signal_2ask=amp_2ask_mod.*car_2ask_mod; 
std_value_db=(0:2:20); 
std_value=10.^(-std_value_db/20); 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_2ask_noise1=signal_2ask+randn(1,length(signal_2ask))*std_value1;%产生信噪比为10db的有噪信号 
signal_2ask_noise2=signal_2ask+randn(1,length(signal_2ask))*std_value2;%产生信噪比为0db的有噪信号 
% figure(1); 
% subplot(2,2,1); 
% plot(signal_2ask); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_2ask_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_2ask_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
signal_2ask_noise=zeros(length(std_value),length(signal_2ask)); 
for i=1:length(std_value) 
    signal_2ask_noise(i,:)=signal_2ask+randn(1,length(signal_2ask))*std_value(i); 
end 
signal_noise=signal_2ask_noise; 
 
elseif modulation_mode==2 
%4ASK调制信号的产生 
amp_4ask=1/3*(randint(1,K*100,4));%产生信息信号 
amp_4ask_mod=zeros(1,100*length(amp_4ask)); 
for i=1:length(amp_4ask) 
    amp_4ask_mod(:,((i*100)-99):i*100)=amp_4ask(i)*ones(1,100); 
end 
fre_4ask_mod=zeros(1,100*length(amp_4ask)); 
for i=1:length(fre_4ask_mod) 
    fre_4ask_mod(i)=2*pi*Fc*i/Fs; 
end 
car_4ask_mod=cos(fre_4ask_mod); 
signal_4ask=amp_4ask_mod.*car_4ask_mod; 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_4ask_noise1=signal_4ask+randn(1,length(signal_4ask))*std_value1;%产生信噪比为10db的有噪信号 
signal_4ask_noise2=signal_4ask+randn(1,length(signal_4ask))*std_value2;%产生信噪比为0db的有噪信号 
% figure(2); 
% subplot(2,2,1); 
% plot(signal_4ask); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_4ask_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_4ask_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
 
signal_4ask_noise=zeros(length(std_value),length(signal_4ask)); 
for i=1:length(std_value) 
    signal_4ask_noise(i,:)=signal_4ask+randn(1,length(signal_4ask))*std_value(i); 
end 
signal_noise=signal_4ask_noise; 
 
elseif modulation_mode==3 
%2FSK调制信号的产生 
rb=50;%fsk偏移频率 
amp_2fsk=ones(1,K*100);%产生信息信号 
amp_2fsk_mod=ones(1,100*length(amp_2fsk)); 
fre_2fsk_bias=randint(1,K*100); 
fre_2fsk_bias1_mod=zeros(1,100*length(fre_2fsk_bias)); 
for i=1:length(fre_2fsk_bias) 
    fre_2fsk_bias1_mod(:,((i*100)-99):i*100)=fre_2fsk_bias(i)*ones(1,100); 
end 
fre_2fsk_mod=2*pi*(Fc-rb/2-fre_2fsk_bias1_mod*rb)/Fs; 
car_2fsk_mod=zeros(1,length(fre_2fsk_mod)); 
for i=1:length(fre_2fsk_mod) 
    car_2fsk_mod(i)=cos(i*fre_2fsk_mod(i)); 
end 
signal_2fsk=amp_2fsk_mod.*car_2fsk_mod; 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_2fsk_noise1=signal_2fsk+randn(1,length(signal_2fsk))*std_value1;%产生信噪比为10db的有噪信号 
signal_2fsk_noise2=signal_2fsk+randn(1,length(signal_2fsk))*std_value2;%产生信噪比为0db的有噪信号 
% figure(3); 
% subplot(2,2,1); 
% plot(signal_2fsk); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_2fsk_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_2fsk_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
signal_2fsk_noise=zeros(length(std_value),length(signal_2fsk)); 
for i=1:length(std_value) 
    signal_2fsk_noise(i,:)=signal_2fsk+randn(1,length(signal_2fsk))*std_value(i); 
end 
signal_noise=signal_2fsk_noise; 
 
 
elseif modulation_mode==4 
%4FSK调制信号的产生 
rb=50;%fsk偏移频率 
amp_4fsk=ones(1,K*100);%产生信息信号 
amp_4fsk_mod=ones(1,100*length(amp_4fsk)); 
fre_4fsk_bias=randint(1,K*100,4); 
fre_4fsk_bias1_mod=zeros(1,100*length(fre_4fsk_bias)); 
for i=1:length(fre_4fsk_bias) 
    fre_4fsk_bias1_mod(:,((i*100)-99):i*100)=fre_4fsk_bias(i)*ones(1,100); 
end 
fre_4fsk_mod=2*pi*(Fc-3*rb/2-fre_4fsk_bias1_mod*rb)/Fs; 
car_4fsk_mod=zeros(1,length(fre_4fsk_mod)); 
for i=1:length(fre_4fsk_mod) 
    car_4fsk_mod(i)=cos(i*fre_4fsk_mod(i)); 
end 
signal_4fsk=amp_4fsk_mod.*car_4fsk_mod; 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_4fsk_noise1=signal_4fsk+randn(1,length(signal_4fsk))*std_value1;%产生信噪比为10db的有噪信号 
signal_4fsk_noise2=signal_4fsk+randn(1,length(signal_4fsk))*std_value2;%产生信噪比为0db的有噪信号 
% figure(4); 
% subplot(2,2,1); 
% plot(signal_4fsk); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_4fsk_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_4fsk_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
signal_4fsk_noise=zeros(length(std_value),length(signal_4fsk)); 
for i=1:length(std_value) 
    signal_4fsk_noise(i,:)=signal_4fsk+randn(1,length(signal_4fsk))*std_value(i); 
end 
signal_noise=signal_4fsk_noise; 
 
elseif modulation_mode==5 
%2PSK调制信号的产生 
amp_2psk=ones(1,K*100);%产生信息信号 
amp_2psk_mod=ones(1,100*length(amp_2psk)); 
pha_2psk_bias=randint(1,K*100); 
pha_2psk_bias1_mod=zeros(1,100*length(pha_2psk_bias)); 
for i=1:length(pha_2psk_bias) 
    pha_2psk_bias1_mod(:,((i*100)-99):i*100)=pha_2psk_bias(i)*ones(1,100); 
end 
car_2psk_mod=zeros(1,length(pha_2psk_bias1_mod)); 
for i=1:length(pha_2psk_bias1_mod) 
    car_2psk_mod(i)=cos(i*2*pi*Fc/Fs-pi/2+pi*pha_2psk_bias1_mod(i)); 
end 
signal_2psk=amp_2psk_mod.*car_2psk_mod; 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_2psk_noise1=signal_2psk+randn(1,length(signal_2psk))*std_value1;%产生信噪比为10db的有噪信号 
signal_2psk_noise2=signal_2psk+randn(1,length(signal_2psk))*std_value2;%产生信噪比为0db的有噪信号 
% figure(5); 
% subplot(2,2,1); 
% plot(signal_2psk); 
% axis([0 300 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_2psk_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_2psk_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
 
signal_2psk_noise=zeros(length(std_value),length(signal_2psk)); 
for i=1:length(std_value) 
    signal_2psk_noise(i,:)=signal_2psk+randn(1,length(signal_2psk))*std_value(i); 
end 
signal_noise=signal_2psk_noise; 
 
elseif modulation_mode==6 
%4PSK调制信号的产生 
amp_4psk=ones(1,K*100);%产生信息信号 
amp_4psk_mod=ones(1,100*length(amp_4psk)); 
pha_4psk_bias=randint(1,K*100,4); 
pha_4psk_bias1_mod=zeros(1,100*length(pha_4psk_bias)); 
for i=1:length(pha_4psk_bias) 
    pha_4psk_bias1_mod(:,((i*100)-99):i*100)=pha_4psk_bias(i)*ones(1,100); 
end 
car_4psk_mod=zeros(1,length(pha_4psk_bias1_mod)); 
for i=1:length(pha_4psk_bias1_mod) 
    car_4psk_mod(i)=cos(i*2*pi*Fc/Fs-3*pi/4+pi*pha_4psk_bias1_mod(i)/2); 
end 
signal_4psk=amp_4psk_mod.*car_4psk_mod; 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_4psk_noise1=signal_4psk+randn(1,length(signal_4psk))*std_value1;%产生信噪比为10db的有噪信号 
signal_4psk_noise2=signal_4psk+randn(1,length(signal_4psk))*std_value2;%产生信噪比为0db的有噪信号 
% figure(6); 
% subplot(2,2,1); 
% plot(signal_4psk); 
% axis([0 300 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_4psk_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_4psk_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
 
signal_4psk_noise=zeros(length(std_value),length(signal_4psk)); 
for i=1:length(std_value) 
    signal_4psk_noise(i,:)=signal_4psk+randn(1,length(signal_4psk))*std_value(i); 
end 
signal_noise=signal_4psk_noise; 
 
 
elseif modulation_mode==7 
%16QAM调制信号的产生 
d=sqrt(2)/3; 
amp_qam_I=randint(1,K*100,4);%产生信息信号 
amp_qam_Q=randint(1,K*100,4); 
amp_qam_mod_I=zeros(1,100*length(amp_qam_I)); 
amp_qam_mod_Q=zeros(1,100*length(amp_qam_Q)); 
for i=1:length(amp_qam_I) 
    amp_qam_mod_I(:,((i*100)-99):i*100)=amp_qam_I(i)*ones(1,100)*d-d*3/2; 
    amp_qam_mod_Q(:,((i*100)-99):i*100)=amp_qam_Q(i)*ones(1,100)*d-d*3/2; 
end 
fre_qam_mod=zeros(1,100*length(amp_qam_I)); 
for i=1:length(fre_qam_mod) 
    fre_qam_mod(i)=2*pi*Fc*i/Fs; 
end 
car_qam_mod_I=cos(fre_qam_mod); 
car_qam_mod_Q=sin(fre_qam_mod); 
signal_qam=amp_qam_mod_I.*car_qam_mod_I+amp_qam_mod_Q.*car_qam_mod_Q; 
std_value1=0.3162;%加性高斯白噪声的方差是0.1,S/N=10db 
std_value2=1;%S/R=0db  
signal_qam_noise1=signal_qam+randn(1,length(signal_qam))*std_value1;%产生信噪比为10db的有噪信号 
signal_qam_noise2=signal_qam+randn(1,length(signal_qam))*std_value2;%产生信噪比为0db的有噪信号 
% figure(7); 
% subplot(2,2,1); 
% plot(signal_qam); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,2); 
% plot(signal_qam_noise1); 
% axis([0 1000 -1.5 1.5]); 
% subplot(2,2,3); 
% plot(signal_qam_noise2); 
% axis([0 1000 -1.5 1.5]); 
 
 
signal_qam_noise=zeros(length(std_value),length(signal_qam)); 
for i=1:length(std_value) 
    signal_qam_noise(i,:)=signal_qam+randn(1,length(signal_qam))*std_value(i); 
end 
signal_noise=signal_qam_noise; 
end