一、要求
画出MSK信号产生的信息、I路、Q路信号对比图以及接收端解调的信息恢复的对比图。
二、设计
1.MSK调制
2.MSK解调
三、代码
clear all;clc;
N=20;
T=1;
fc=10;
Fs=100;
bitstream=randi([0,1],1,N);
bitstream1=2*bitstream-1;
b0=1;
for i=1:N
encode_output(i)=b0*bitstream1(i);
b0=encode_output(i);
end
I=[];Q=[];
for i=1:N
if mod(i,2)~=0
I=[I,encode_output(i)];
else
Q=[Q,encode_output(i)];
end
end
bit_data=[];
for i=1:N
bit_data=[bit_data,encode_output(i)*ones(1,T*Fs)];
end
I_data=[];Q_data=[];base_wave=-T:1/Fs:T-1/Fs;
for i=1:N/2
I_data=[I_data,I(i)*cos(pi*base_wave/(2*T))];
Q_data=[Q_data,Q(i)*cos(pi*base_wave/(2*T))];
end
% Q delay
number_delay=length(base_wave)/2;
Q_data1=[zeros(1,number_delay),Q_data(1:length(Q_data)-number_delay)];
% plot
figure();
t=0:1/Fs:N*T-1/Fs;
subplot(3,1,1)
plot(t,bit_data);legend('Bitstream')
subplot(3,1,2)
plot(t,I_data);legend('I Bitstream')
subplot(3,1,3)
plot(t,Q_data1);legend('Q Bitstream')
% carrier signal
bit_t=0:1/Fs:N*T-1/Fs;
I_carrier=cos(2*pi*fc*bit_t);
Q_carrier=cos(2*pi*fc*bit_t+pi/2);
% transmit signal
MSK_signal=I_data.*I_carrier+Q_data1.*Q_carrier;
snr=1;
MSK_receive=awgn(MSK_signal,snr);
% demodulate
I_output=MSK_receive.*I_carrier;
Hd=myfilter;
I_filter_ouput=filter(Hd,I_output);
Q_output=MSK_receive.*Q_carrier;
Q_filter_ouput=filter(Hd,Q_output);
for i=1:N/2
if I_filter_ouput((2*i-1)*number_delay)>0
I_recover(i)=1;
else
I_recover(i)=-1;
end
if Q_filter_ouput(2*i*number_delay)>0
Q_recover(i)=1;
else
Q_recover(i)=-1;
end
end
bit_recover=[];
for i=1:N
if mod(i,2)~=0
bit_recover=[bit_recover,I_recover((i-1)/2+1)];
else
bit_recover=[bit_recover,Q_recover(i/2)];
end
end
% decode
for i=1:N
if i==1
bit_recover1(i)=bit_recover(i);
else
bit_recover1(i)=bit_recover(i)*bit_recover(i-1);
end
end
recover_data=[];
for i=1:N
recover_data=[recover_data,bit_recover1(i)*ones(1,T*Fs)];
end
% plot
figure();
t=0:1/Fs:N*T-1/Fs;
bit_stream=[];
for i=1:N
bit_stream=[bit_stream,bitstream1(i)*ones(1,T*Fs)];
end
subplot(2,1,2)
plot(t,bit_stream);legend('original Bitstream')
subplot(2,1,1)
plot(t,recover_data);legend('recover Bitstream')
四、结果
myfilter是通过matlab命令行调用filter designer设计生成的函数
五、结论
在MSK的调制与解调中,产生和接收到的信号能够进行还原,即调制产生的I、Q以及MSK信号在经过解调之后能够还原出原来的信号。尽管过滤器设计不同,但是仍然不影响最后的结果。