matlab qpsk调制程序,QPSK调制解调完整程序(配有自己的注释)
clc;
clear all;
%假定接收端已經(jīng)實(shí)現(xiàn)載波同步,位同步(盲信號(hào)解調(diào)重點(diǎn)要解決的問(wèn)題:載波同步(costas環(huán)(未見(jiàn)到相關(guān)代碼)),位同步(Gardner算法(未見(jiàn)相關(guān)代碼)),幀同步)
% carrier frequency??for modulation and demodulation
fc=5e6;
%QPSK transmitter
data=5000??;? ?%碼數(shù)率為5MHZ? ???%原碼個(gè)數(shù)
rand_data=randn(1,5000);
for??i=1:data
if rand_data(i)>=0.5
rand_data(i)=1;
else
rand_data(i)=0;
end
end
%seriel to parallel? ?? ???%同時(shí)單極性碼轉(zhuǎn)為雙極性碼
for??i=1:data
if rem(i,2)==1
if??rand_data(i)==1
I(i)=1;
I(i+1)=1;
else
I(i)=-1;
I(i+1)=-1;
end
else
if rand_data(i)==1
Q(i-1)=1;
Q(i)=1;
else
Q(i-1)=-1;
Q(i)=-1;
end
end
end
% zero insertion? ?,此過(guò)程稱(chēng)為成形。成形的意思就是實(shí)現(xiàn)由消息到波形的轉(zhuǎn)換,以便發(fā)射,脈沖成形應(yīng)該是在基帶調(diào)制之后。
zero=5;? ?? ?? ?%sampling??rate??25M HZ??,明白了,zero為過(guò)采樣率。它等于 采樣率fs/碼速率。
for??i=1:zero*data? ???% 采樣點(diǎn)數(shù)目=過(guò)采樣率*原碼數(shù)目
if rem(i,zero)==1
Izero(i)=I(fix((i-1)/zero)+1);
Qzero(i)=Q(fix((i-1)/zero)+1);
else
Izero(i)=0;
Qzero(i)=0;
end
end
%pulse shape filter, 接著,將進(jìn)行低通濾波,因?yàn)?隨著傳輸速率的增大,基帶脈沖的頻譜將變寬
%如果不濾波(如升余弦濾波)進(jìn)行低通濾波,后面加載頻的時(shí)候可能會(huì)出現(xiàn)困難。
%平方根升余弦濾波器
% psf=rcosfir(rf,n_t,rate,fs,'sqrt')? ?rate:過(guò)采樣率,rf:滾降因子,n_t:濾波器階數(shù),fs:采樣率
%用在調(diào)制或發(fā)送之前,用在解調(diào)或接受之后,用來(lái)降低過(guò)采樣符號(hào)流帶寬并不引發(fā)ISI(碼間串?dāng)_)
NT=50;
N=2*zero*NT;? ? % =500
fs=25e6;
rf=0.1;
psf=rcosfir(rf,NT,zero,fs,'sqrt');% psf大小為500
Ipulse=conv(Izero,psf);
Qpulse=conv(Qzero,psf);
%為什么數(shù)字信號(hào)傳輸也要過(guò)采樣,成形濾波?
%答:過(guò)采樣的數(shù)字信號(hào)處理起來(lái)對(duì)低通濾波器的要求相對(duì)較低,如果不過(guò)采樣,濾波的時(shí)候?yàn)V波器需要很陡峭,指標(biāo)會(huì)很?chē)?yán)格
%成形濾波的作用是保證采樣點(diǎn)不失真。如果沒(méi)有它,那信號(hào)在經(jīng)過(guò)帶限信道后,眼圖張不開(kāi),ISI非常嚴(yán)重。成形濾波的位置在基帶調(diào)制之后。
%因?yàn)榻?jīng)成形濾波后,信號(hào)的信息已經(jīng)有所損失,這也是為避免ISI付出的代價(jià)。換句話說(shuō),成形濾波的位置在載波調(diào)制之前,僅挨著載波調(diào)制。
%即:(發(fā)送端)插值(采樣)-成形-濾波(LPF)-加載頻(載波調(diào)制)-加噪聲至(接收端)乘本振-低通-定時(shí)抽取-判決。
%modulation
for i=1:zero*data+N? ?%采樣點(diǎn)數(shù)目改變 (因?yàn)榫矸e的緣故)
t(i)=(i-1)/(fs);??%這里因?yàn)榧僭O(shè)載頻與碼速率大小相等,所以用載頻fc乘以過(guò)采樣率=采樣率。
Imod(i)=Ipulse(i)*sqrt(2)*cos(2*pi*fc*t(i));
Qmod(i)=Qpulse(i)*(-sqrt(2)*sin(2*pi*fc*t(i)));
end
sum=Imod+Qmod;
%QPSK??receiver
%demodulation
for i=1:zero*data+N
Idem(i)=sum(i)*sqrt(2)*cos(2*pi*fc*t(i));
Qdem(i)=sum(i)*(-sqrt(2)*sin(2*pi*fc*t(i)));
end
%matched??filter
mtf=rcosfir(rf,NT,zero,fs,'sqrt');
Imat=conv(Idem,mtf);
Qmat=conv(Qdem,mtf);
%data selection
for??i=1:zero*data
Isel(i)=Imat(i+N);
Qsel(i)=Qmat(i+N);
end
%sampler? ?? ???%提取碼元
for i=1:data
Isam(i)=Isel((i-1)*zero+1);
Qsam(i)=Qsel((i-1)*zero+1);
end
%decision??threshold
threshold=0.2;
for??i=1:data
if Isam(i)>=threshold
Ifinal(i)=1;
else
Ifinal(i)=-1;
end
if Qsam(i)>=threshold
Qfinal(i)=1;
else
Qfinal(i)=-1;
end
end
%parallel to serial
for i=1:data
if rem (i,2)==1
if Ifinal(i)==1
final(i)=1;
else
final(i)=0;
end
else
if??Qfinal(i)==1
final(i)=1;
else
final(i)=0;
end
end
end
% 繪圖
figure(1)
plot(20*log(abs(fft(rand_data))));
axis([0??data??-40??100]);
grid on;
title('spectrum??of input binary data');
figure(2)
subplot(221);
plot(20*log(abs(fft(I))));
axis([0 data -40 140]);
grid??on;
title('spectrum of I-channel data');
subplot(222);
plot(20*log(abs(fft(Q))));
axis([0??data? ?-40??140]);
grid??on;
title('spectrum of Q-channel data');
subplot(223);
plot(20*log(abs(fft(Izero))));
axis([0 zero*data??-20??140]);
grid??on;
title('spectrum of I-channel after zero insertion');
subplot(224);
plot(20*log(abs(fft(Qzero))));
axis([0??zero*data? ?-20 140]);
grid??on;
title('spectrum of Q-channel after zero insertion');
figure(3);
subplot(221);
plot(psf);
axis([200? ? 300? ???-0.2? ? 0.6]);
title('time domain response of pulse shaping filter');
grid??on;
subplot(222);
plot(20*log(abs(fft(psf))));
axis([0??N? ?-350 50]);
grid on;
title('transfer??function??of pulse??shaping filter');
subplot(223);
plot(20*log(abs(fft(Ipulse))));
axis([0??zero*data+N??-250 150]);
grid on;
title('spectrum of I-channel after??impulse shaping filter');
subplot(224);
plot(20*log(abs(fft(Qpulse))));
axis([0??zero*data+N -250??150]);
grid??on;
title('spectrum of Q-channel??after pluse shaping??filter');
figure(4)
subplot(211);
plot(20*log(abs(fft(Imod))));
axis([0??zero*data+N??-250 150]);
grid??on ;
title('spectrum of I-channel??after modulation');
subplot(212);
plot(20*log(abs(fft(Qmod))));
axis([0??zero*data+N??-250 150]);
grid??on;
title('spectrum??of??Q-channel after modulation');
figure(5)
subplot(221);
plot(20*log(abs(fft(Idem))));
axis([0 zero*data??-200??150]);
grid on;
title('spectrum??of I-channel after??demodulation');
subplot(222);
plot(20*log(abs(fft(Qdem))));
axis([0??zero*data+N??-200??150 ]);
grid??on;
title('spectrum of Q-channel after demodulation');
subplot(223);
plot(20*log(abs(fft(Imat))));
axis([0??zero*data??-400??200]);
grid??on;
title('spectrum??of I-channel??after??matched filter');
subplot(224);
plot(20*log(abs(fft(Qmat))));
axis([0??zero*data??-400??200]);
grid??on;
title('spectrum of??Q-channel after matched filter');
figure(6)
subplot(221);
plot(20*log(abs(fft(Isam))));
axis([0 data??-40??150]);
grid??on;
title('spectrum of I-channel after sampler');
subplot(222);
plot(20*log(abs(fft(Qsam))));
axis([0??data -40??150 ]);
grid??on;
title('spectrum of Q-channel after??sampler');
subplot(223);
plot(20*log(abs(fft(Ifinal))));
axis([0 data??-40??150]);
grid on;
title('spectrum of??I-channel after??decision threshold');
subplot(224);
plot(20*log(abs(fft(Qfinal))));
axis([0 data??-40??150]);
grid on;
title('spectrum of??Q-channel after??decision threshold');
figure(7)
plot(Isel,Qsel);
axis([-1.6 1.6??-1.6??1.6]);
grid??on;
title('constellation??of??matched??filter??output');
figure(8)
plot(Isam,Qsam,'X');
axis([-1.2??1.2? ?-1.2??1.2]);
grid on;
title('constellation??of??sampler');
figure(9)
plot(20*log(abs(fft(final))));
axis([0??data??0??100]);
grid??on;
title('aspectrum??of??final??received??binary??data');
總結(jié)
以上是生活随笔為你收集整理的matlab qpsk调制程序,QPSK调制解调完整程序(配有自己的注释)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: yii+php+当前目录,Yii常用路径
- 下一篇: python里pip是什么意思_pyth