function Q1_2
%该程序用于产生单位采样序列,输入延时量即可得到带时延的单位采样序列
N=41;
X1=zeros(1,N);
X1(21)=1;
t=-20:N-21;
figure(1),
subplot(5,2,1),stem(t,X1),axis([-21 21 0 2]),title('单位采样序列X1');
xlabel('t');ylabel('X1');
deltt=input('请输入延时量deltt=');
subplot(5,2,2),stem(t+deltt,X1),axis([-20-deltt 20-deltt 0 2]),title('带时延的单位采样序列Y1');
xlabel('t');ylabel('Y1');
%该程序用于产生单位阶跃序列,输入延时量即可得到带有延时的单位阶跃序列
N=21;
X2=ones(1,N);
t=0:N-1;
subplot(5,2,3),stem(t,X2),axis([-5,22,0,2]),title('单位阶跃序列X2');
xlabel('t');ylabel('X2');
deltt=input('请输入延时量deltt=');
subplot(5,2,4),stem(t+deltt,X2),axis([-5,22,0,2]),title('带有时延的单位阶跃序列Y2');
xlabel('t');ylabel('Y2');
%改程序用于产生正弦序列
n=0:100;
X3=sin(pi*n/16);
X4=sin(n/2);
X5=cos(pi*n/12)+cos(3*pi*n/8);
subplot(5,2,5),plot(n,X3)
xlabel('n');
ylabel('正弦序列X3 ');
title('X3');
subplot(5,2,6),plot(n,X4)
xlabel('n');
ylabel('正弦序列X4');
title('X4');
subplot(5,2,7),plot(n,X5)
xlabel('n');
ylabel('正弦序列X5');
title('X5');
%该程序用于产生指数序列
n=0:30;
X6n=0.2.*(0.8.^n);X6n1=0.2.*(1.2.^n);X6n2=0.2.*((-0.8).^n);
X7n=exp((-1/12+j*pi)*n);
figure(5)
subplot(5,2,1),plot(n,X6n);title('X6n---0.8');
xlabel('n');ylabel('X6n');
subplot(5,2,2),plot(n,X6n1);title('X6n1----1.2');
xlabel('n');ylabel('X6n1');
subplot(5,2,3),plot(n,X6n2),title('X6n2------0.8');
xlabel('n');ylabel('X6n2');
subplot(5,2,4),plot(n,real(X7n)),title('X7nreal');
xlabel('n');ylabel('X7nreal');
subplot(5,2,5),plot(n,imag(X7n)),title('X7nimag');
xlabel('n');ylabel('X7nimag');
subplot(5,2,6),plot(n,abs(X7n)),title('X7nabs');
xlabel('n');ylabel('X7nabs');
subplot(5,2,7),plot(n,angle(X7n)),title('X7nangle');
xlabel('n');ylabel('X7nangle');
%2、基本数字调制信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%2ASK二进制启闭键控系统的实现%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rs=300; % Symbol rate
fc=500; %frequency of cos
Ts=1/Rs; % Symbol interval
T=50; % oversample rate = number of samples in a symbol
fs=Rs*T; % sampling rate 20Hz
ts=1/fs;
N=10; % Length of the seq.
% N=500; % for eyediagram.
n_range=(0:N*T-1);
t=n_range*ts;
bnOri=unifrnd(-1,+1,1,N)>0; %产生随机的二进制序列
bnOri %显示随机产生的二进制序列
gTpulse=ones(1,T); % NRZ
n_dly=n_range+T/2+1;
%%%%%得到方波%%%%%
OriImpulses=upsample(bnOri,T,T/2); % build the impluse train
mOri=conv(OriImpulses,gTpulse); % generate baseband (PAM) signal
mOri=mOri(n_dly);
sOri1=mOri.*cos(2*pi*fc*t); %2ASK
figure(2),sRng=[0,N*(T-1)*ts, -1.5,+1.5];
subplot(4,1,1),plot(t,mOri),axis([sRng]),title('baseband signal');
subplot(4,1,2),plot(t,cos(2*pi*fc*t)),axis([sRng]),title('载波信号');
subplot(4,1,3),plot(t,mOri,'r',t,sOri1,'b'),axis([sRng]),title('2ASK');
%该程序用于实现2FSK二进制频移键控的系统实现
Rs=300;
fc=500; %frequency of cos
Ts=1/Rs; % Symbol interval
T=50; % oversample rate = number of samples in a symbol
fs=Rs*T; % sampling rate 20Hz
ts=1/fs;
N=10; % Length of the seq.
n_range=(0:N*T-1);
t=n_range*ts;
bnOri=unifrnd(-1,+1,1,N)>0;
bnOri
gTpulse=ones(1,T);
n_dly=n_range+T/2+1;
%%%%%得到方波%%%%%
OriImpulses=upsample(bnOri,T,T/2);
mOri=conv(OriImpulses,gTpulse);
mOri=mOri(n_dly);
%%%%%调制2FSK%%%%%
f1=1270; f2=500;
sOri1=mOri.*cos(2*pi*f1*t);
sOri2=(1-mOri).*cos(2*pi*f2*t);
sOri=sOri1+sOri2;
% plot ---
sRng=[0,N*(T-1)*ts, -1.5,+1.5];
figure(3);
subplot(4,1,1),plot(t,cos(2*pi*f1*t));axis(sRng),title('2FSK');
subplot(4,1,2),plot(t,cos(2*pi*f2*t));axis(sRng);
subplot(4,1,3),plot(t,mOri,'r',t,sOri,'b'); axis(sRng);
subplot(4,1,4),plot(t,sOri1,'r',t,sOri2,'g'); axis(sRng);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2PSK二进制相移键控的系统实现%%%%%%%%%%%%%%%%%%
Rs=300;
fc=500;
Ts=1/Rs;
T=50;
fs=Rs*T;
ts=1/fs;
N=10;
n_range=(0:N*T-1);
t=n_range*ts;
bnOri=unifrnd(-1,+1,1,N)>0;
bnOri
gTpulse=ones(1,T);
n_dly=n_range+T/2+1;
%%%%%得到方波%%%%%
OriImpulses=upsample(bnOri,T,T/2);
mOri=conv(OriImpulses,gTpulse);
mOri=mOri(n_dly);
%%%%%2PSK调制%%%%%
mOri=mOri*2-1;
sOri1=mOri.*cos(2*pi*fc*t); %2PSK
figure(4),sRng=[0,N*(T-1)*ts, -1.5,+1.5];
subplot(4,1,1),plot(t,mOri),axis([sRng]),title('baseband signal');
subplot(4,1,2),plot(t,cos(2*pi*fc*t)),axis([sRng]),title('载波信号');
subplot(4,1,3),plot(t,mOri,'r',t,sOri1,'b'),axis([sRng]),title('2PSK');