《QPSK调制解调完整程序(配有自己的注释)(共6页).doc》由会员分享,可在线阅读,更多相关《QPSK调制解调完整程序(配有自己的注释)(共6页).doc(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上QPSK调制解调完整程序(配有注释)clc;clear all;%假定接收端已经实现载波同步,位同步(盲信号解调重点要解决的问题:载波同步(costas环(未见到相关代码),位同步(Gardner算法(未见相关代码),帧同步)% carrier frequencyfor modulation and demodulationfc=5e6;%QPSK transmitterdata=5000; %码数率为5MHZ %原码个数rand_data=randn(1,5000);fori=1:data if rand_data(i)=0.5 rand_data(i)=1; el
2、se rand_data(i)=0; endend%seriel to parallel %同时单极性码转为双极性码fori=1:data if rem(i,2)=1 ifrand_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 endend% zero insertion ,此过程称为成形。成形的意思就是实现由消息到波形的转换,以便发射,脉冲成形应该是在基带调制之后。zero=5; %sa
3、mplingrate25M HZ,明白了,zero为过采样率。它等于 采样率fs/码速率。fori=1:zero*data % 采样点数目=过采样率*原码数目 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; endend%pulse shape filter, 接着,将进行低通滤波,因为 随着传输速率的增大,基带脉冲的频谱将变宽%如果不滤波(如升余弦滤波)进行低通滤波,后面加载频的时候可能会出现困难。%平方根升余弦滤波器% psf=
4、rcosfir(rf,n_t,rate,fs,sqrt) rate:过采样率,rf:滚降因子,n_t:滤波器阶数,fs:采样率%用在调制或发送之前,用在解调或接受之后,用来降低过采样符号流带宽并不引发ISI(码间串扰)NT=50;N=2*zero*NT; % =500fs=25e6;rf=0.1;psf=rcosfir(rf,NT,zero,fs,sqrt);% psf大小为500Ipulse=conv(Izero,psf);Qpulse=conv(Qzero,psf);%为什么数字信号传输也要过采样,成形滤波?%答:过采样的数字信号处理起来对低通滤波器的要求相对较低,如果不过采样,滤波的时候
5、滤波器需要很陡峭,指标会很严格%成形滤波的作用是保证采样点不失真。如果没有它,那信号在经过带限信道后,眼图张不开,ISI非常严重。成形滤波的位置在基带调制之后。%因为经成形滤波后,信号的信息已经有所损失,这也是为避免ISI付出的代价。换句话说,成形滤波的位置在载波调制之前,仅挨着载波调制。%即:(发送端)插值(采样)-成形-滤波(LPF)-加载频(载波调制)-加噪声至(接收端)乘本振-低通-定时抽取-判决。%modulationfor i=1:zero*data+N %采样点数目改变 (因为卷积的缘故) t(i)=(i-1)/(fs);%这里因为假设载频与码速率大小相等,所以用载频fc乘以过采
6、样率=采样率。 Imod(i)=Ipulse(i)*sqrt(2)*cos(2*pi*fc*t(i); Qmod(i)=Qpulse(i)*(-sqrt(2)*sin(2*pi*fc*t(i);endsum=Imod+Qmod;%QPSKreceiver%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 %matchedfilter mtf=rcosfir(rf,NT,zero,fs,sqrt); Ima
7、t=conv(Idem,mtf); Qmat=conv(Qdem,mtf); %data selection fori=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 %decisionthreshold threshold=0.2; fori=1:data if Isam(i)=threshold Ifinal(i)=1; else Ifinal(i)=-1; e
8、nd 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 ifQfinal(i)=1 final(i)=1; else final(i)=0; end end end % 绘图 figure(1) plot(20*log(abs(fft(rand_data); axis(0data-40100); grid on; title
9、(spectrumof input binary data); figure(2) subplot(221); plot(20*log(abs(fft(I); axis(0 data -40 140); gridon; title(spectrum of I-channel data); subplot(222); plot(20*log(abs(fft(Q); axis(0data -40140); gridon; title(spectrum of Q-channel data); subplot(223); plot(20*log(abs(fft(Izero); axis(0 zero*
10、data-20140); gridon; title(spectrum of I-channel after zero insertion); subplot(224); plot(20*log(abs(fft(Qzero); axis(0zero*data -20 140); gridon; 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 shapi
11、ng filter); gridon; subplot(222); plot(20*log(abs(fft(psf); axis(0N -350 50); grid on; title(transferfunctionof pulseshaping filter); subplot(223); plot(20*log(abs(fft(Ipulse); axis(0zero*data+N-250 150); grid on; title(spectrum of I-channel afterimpulse shaping filter); subplot(224); plot(20*log(ab
12、s(fft(Qpulse); axis(0zero*data+N -250150); gridon; title(spectrum of Q-channelafter pluse shapingfilter); figure(4) subplot(211); plot(20*log(abs(fft(Imod); axis(0zero*data+N-250 150); gridon ; title(spectrum of I-channelafter modulation); subplot(212); plot(20*log(abs(fft(Qmod); axis(0zero*data+N-2
13、50 150); gridon; title(spectrumofQ-channel after modulation); figure(5) subplot(221); plot(20*log(abs(fft(Idem); axis(0 zero*data-200150); grid on; title(spectrumof I-channel afterdemodulation); subplot(222); plot(20*log(abs(fft(Qdem); axis(0zero*data+N-200150 ); gridon; title(spectrum of Q-channel
14、after demodulation); subplot(223); plot(20*log(abs(fft(Imat); axis(0zero*data-400200); gridon; title(spectrumof I-channelaftermatched filter); subplot(224); plot(20*log(abs(fft(Qmat); axis(0zero*data-400200); gridon; title(spectrum ofQ-channel after matched filter); figure(6) subplot(221); plot(20*l
15、og(abs(fft(Isam); axis(0 data-40150); gridon; title(spectrum of I-channel after sampler); subplot(222); plot(20*log(abs(fft(Qsam); axis(0data -40150 ); gridon; title(spectrum of Q-channel aftersampler); subplot(223); plot(20*log(abs(fft(Ifinal); axis(0 data-40150); grid on; title(spectrum ofI-channe
16、l afterdecision threshold); subplot(224); plot(20*log(abs(fft(Qfinal); axis(0 data-40150); grid on; title(spectrum ofQ-channel afterdecision threshold); figure(7) plot(Isel,Qsel); axis(-1.6 1.6-1.61.6); gridon; title(constellationofmatchedfilteroutput); figure(8) plot(Isam,Qsam,X); axis(-1.21.2 -1.21.2); grid on; title(constellationofsampler); figure(9) plot(20*log(abs(fft(final); axis(0data0100); gridon; title(aspectrumoffinalreceivedbinarydata);专心-专注-专业