QPSK信号的调制和解调

1 %% ----------------QPSK----------------------------------
2 clc;
3 clear all;
4 %假定接收端已经实现载波同步,位同步(盲信号解调重点要解决的问题:载波同步(costas环(未见到相关代码)),位同步(Gardner算法(未见相关代码)),帧同步)
5 % carrier frequency for modulation and demodulation
6 fc=5e6;
7 %QPSK transmitter
8 data=100 ; %码数率为5MHZ %原码个数
9 rand_data=randn(1,data);
10 for i=1:data
11 if rand_data(i)>=0.5
12 rand_data(i)=1;
13 else
14 rand_data(i)=0;
15 end
16 end
17 figure(1)
18 subplot(211)
19 stem(rand_data);
20 axis([0 data -2 2]);
21 grid on;
22 title('input binary code');
23 subplot(212)
24 plot(20*log(abs(fft(rand_data))));
25 axis([0 data -40 100]);
26 grid on;
27 title('spectrum of input binary code');

 

 

 

 

1 %% seriel to parallel %同时单极性码转为双极性码
2 for i=1:data
3 if rem(i,2)==1
4 if rand_data(i)==1
5 I(i)=1;
6 I(i+1)=1;
7 else
8 I(i)=-1;
9 I(i+1)=-1;
10 end
11 else
12 if rand_data(i)==1
13 Q(i-1)=1;
14 Q(i)=1;
15 else
16 Q(i-1)=-1;
17 Q(i)=-1;
18 end
19 end
20 end
21 figure(2)
22 subplot(221);
23 plot(20*log(abs(fft(I))));
24 axis([0 data -40 140]);
25 grid on;
26 title('spectrum of I-channel data');
27 subplot(222);
28 plot(20*log(abs(fft(Q))));
29 axis([0 data -40 140]);
30 grid on;
31 title('spectrum of Q-channel data');
32 %% zero insertion ,此过程称为成形。成形的意思就是实现由消息到波形的转换,以便发射,脉冲成形应该是在基带调制之后。
33 zero=5; %sampling rate 25M HZ ,明白了,zero为过采样率。它等于 采样率fs/码速率。
34 for i=1:zero*data % 采样点数目=过采样率*原码数目
35 if rem(i,zero)==1
36 Izero(i)=I(fix((i-1)/zero)+1);
37 Qzero(i)=Q(fix((i-1)/zero)+1);
38 else
39 Izero(i)=0;
40 Qzero(i)=0;
41 end
42 end
43 subplot(223);
44 plot(20*log(abs(fft(Izero))));
45 axis([0 zero*data -20 140]);
46 grid on;
47 title('spectrum of I-channel after zero insertion');
48 subplot(224);
49 plot(20*log(abs(fft(Qzero))));
50 axis([0 zero*data -20 140]);
51 grid on;
52 title('spectrum of Q-channel after zero insertion');
53 %pulse shape filter, 接着,将进行低通滤波,因为 随着传输速率的增大,基带脉冲的频谱将变宽
54 %如果不滤波(如升余弦滤波)进行低通滤波,后面加载频的时候可能会出现困难。
55 %% 平方根升余弦滤波器
56 % psf=rcosfir(rf,n_t,rate,fs,'sqrt') rate:过采样率,rf:滚降因子,n_t:滤波器阶数,fs:采样率
57 %用在调制或发送之前,用在解调或接受之后,用来降低过采样符号流带宽并不引发ISI(码间串扰)
58
59 NT=50;
60 N=2*zero*NT; % =500
61 fs=25e6;
62 rf=0.1;
63 psf=rcosfir(rf,NT,zero,fs,'sqrt');% psf大小为500
64 figure(3);
65 subplot(221);
66 plot(psf);
67 axis([200 300 -0.2 0.6]);
68 title('time domain response of pulse shaping filter');
69 grid on;
70 subplot(222);
71 plot(20*log(abs(fft(psf))));
72 axis([0 N -350 50]);
73 grid on;
74 title('transfer function of pulse shaping filter');
75
76 Ipulse=conv(Izero,psf);
77 Qpulse=conv(Qzero,psf);
78 subplot(223);
79 plot(20*log(abs(fft(Ipulse))));
80 axis([0 zero*data+N -250 150]);
81 grid on;
82 title('spectrum of I-channel after impulse shaping filter');
83 subplot(224);
84 plot(20*log(abs(fft(Qpulse))));
85 axis([0 zero*data+N -250 150]);
86 grid on;
87 title('spectrum of Q-channel after pluse shaping filter');
88 %为什么数字信号传输也要过采样,成形滤波?
89 %答:过采样的数字信号处理起来对低通滤波器的要求相对较低,如果不过采样,滤波的时候滤波器需要很陡峭,指标会很严格
90 %成形滤波的作用是保证采样点不失真。如果没有它,那信号在经过带限信道后,眼图张不开,ISI非常严重。成形滤波的位置在基带调制之后。
91 %因为经成形滤波后,信号的信息已经有所损失,这也是为避免ISI付出的代价。换句话说,成形滤波的位置在载波调制之前,仅挨着载波调制。
92 %即:(发送端)插值(采样)-成形-滤波(LPF)-加载频(载波调制)-加噪声至(接收端)乘本振-低通-定时抽取-判决。

 

 

 

1 %% 平方根升余弦滤波器
2 % psf=rcosfir(rf,n_t,rate,fs,'sqrt') rate:过采样率,rf:滚降因子,n_t:滤波器阶数,fs:采样率
3 %用在调制或发送之前,用在解调或接受之后,用来降低过采样符号流带宽并不引发ISI(码间串扰)
4
5 NT=50;
6 N=2*zero*NT; % =500
7 fs=25e6;
8 rf=0.1;
9 psf=rcosfir(rf,NT,zero,fs,'sqrt');% psf大小为500
10 figure(3);
11 subplot(221);
12 plot(psf);
13 axis([200 300 -0.2 0.6]);
14 title('time domain response of pulse shaping filter');
15 grid on;
16 subplot(222);
17 plot(20*log(abs(fft(psf))));
18 axis([0 N -350 50]);
19 grid on;
20 title('transfer function of pulse shaping filter');
21
22 Ipulse=conv(Izero,psf);
23 Qpulse=conv(Qzero,psf);
24 subplot(223);
25 plot(20*log(abs(fft(Ipulse))));
26 axis([0 zero*data+N -250 150]);
27 grid on;
28 title('spectrum of I-channel after impulse shaping filter');
29 subplot(224);
30 plot(20*log(abs(fft(Qpulse))));
31 axis([0 zero*data+N -250 150]);
32 grid on;
33 title('spectrum of Q-channel after pluse shaping filter');
34 %为什么数字信号传输也要过采样,成形滤波?
35 %答:过采样的数字信号处理起来对低通滤波器的要求相对较低,如果不过采样,滤波的时候滤波器需要很陡峭,指标会很严格
36 %成形滤波的作用是保证采样点不失真。如果没有它,那信号在经过带限信道后,眼图张不开,ISI非常严重。成形滤波的位置在基带调制之后。
37 %因为经成形滤波后,信号的信息已经有所损失,这也是为避免ISI付出的代价。换句话说,成形滤波的位置在载波调制之前,仅挨着载波调制。
38 %即:(发送端)插值(采样)-成形-滤波(LPF)-加载频(载波调制)-加噪声至(接收端)乘本振-低通-定时抽取-判决。

 

 

 

1 %% modulation
2 for i=1:zero*data+N %采样点数目改变 (因为卷积的 缘故)
3 t(i)=(i-1)/(fs); %这里因为假设载频与码速率大小相等,所以用载频fc乘以过采样率=采样率。
4 Imod(i)=Ipulse(i)*sqrt(2)*cos(2*pi*fc*t(i));
5 Qmod(i)=Qpulse(i)*(-sqrt(2)*sin(2*pi*fc*t(i)));
6 end
7 sum=Imod+Qmod;
8 figure(4)
9 subplot(221);
10 plot(20*log(abs(fft(Imod))));
11 axis([0 zero*data+N -250 150]);
12 grid on ;
13 title('spectrum of I-channel after modulation');
14 subplot(222);
15 plot(20*log(abs(fft(Qmod))));
16 axis([0 zero*data+N -250 150]);
17 grid on;
18 title('spectrum of Q-channel after modulation');
19 subplot(223)
20 plot(20*log(abs(fft(sum))));
21 axis([0 zero*data+N -250 150]);
22 grid on;
23 title('spectrum of sum after modulation');
24 subplot(224)
25 plot(I,Q,'*');
26 axis([-1.2 1.2 -1.2 1.2]);
27 grid on;
28 title('parallel constellation of sampler I and Q');

 

 

1 %% ---------------------------------------------------------------------------------------------------------------------------------------------------------
2 %QPSK receiver
3 %demodulation
4 for i=1:zero*data+N
5 Idem(i)=sum(i)*sqrt(2)*cos(2*pi*fc*t(i));
6 Qdem(i)=sum(i)*(-sqrt(2)*sin(2*pi*fc*t(i)));
7 end
8 %matched filter
9 mtf=rcosfir(rf,NT,zero,fs,'sqrt');
10 Imat=conv(Idem,mtf);
11 Qmat=conv(Qdem,mtf);
12 %data selection
13 for i=1:zero*data
14 Isel(i)=Imat(i+N);
15 Qsel(i)=Qmat(i+N);
16 end
17 %sampler %提取码元
18 for i=1:data
19 Isam(i)=Isel((i-1)*zero+1);
20 Qsam(i)=Qsel((i-1)*zero+1);
21 end
22 %decision threshold
23 threshold=0.2;
24 for i=1:data
25 if Isam(i)>=threshold
26 Ifinal(i)=1;
27 else
28 Ifinal(i)=-1;
29 end
30 if Qsam(i)>=threshold
31 Qfinal(i)=1;
32 else
33 Qfinal(i)=-1;
34 end
35 end
36 %parallel to serial
37 for i=1:data
38 if rem (i,2)==1
39 if Ifinal(i)==1
40 final(i)=1;
41 else
42 final(i)=0;
43 end
44 else
45 if Qfinal(i)==1
46 final(i)=1;
47 else
48 final(i)=0;
49 end
50 end
51 end
52 %% -----------------------------------------------------------------------------------------------------绘图
53 figure(5)
54 subplot(221);
55 plot(20*log(abs(fft(Idem))));
56 axis([0 zero*data -200 150]);
57 grid on;
58 title('spectrum of I-channel after demodulation');
59 subplot(222);
60 plot(20*log(abs(fft(Qdem))));
61 axis([0 zero*data+N -200 150 ]);
62 grid on;
63 title('spectrum of Q-channel after demodulation');
64 subplot(223);
65 plot(20*log(abs(fft(Imat))));
66 axis([0 zero*data -400 200]);
67 grid on;
68 title('spectrum of I-channel after matched filter');
69 subplot(224);
70 plot(20*log(abs(fft(Qmat))));
71 axis([0 zero*data -400 200]);
72 grid on;
73 title('spectrum of Q-channel after matched filter');
74 figure(6)
75 subplot(221);
76 plot(20*log(abs(fft(Isam))));
77 axis([0 data -40 150]);
78 grid on;
79 title('spectrum of I-channel after sampler');
80 subplot(222);
81 plot(20*log(abs(fft(Qsam))));
82 axis([0 data -40 150 ]);
83 grid on;
84 title('spectrum of Q-channel after sampler');
85 subplot(223);
86 plot(20*log(abs(fft(Ifinal))));
87 axis([0 data -40 150]);
88 grid on;
89 title('spectrum of I-channel after decision threshold');
90 subplot(224);
91 plot(20*log(abs(fft(Qfinal))));
92 axis([0 data -40 150]);
93 grid on;
94 title('spectrum of Q-channel after decision threshold');
95 figure(7)
96 plot(Isel,Qsel);
97 axis([-1.6 1.6 -1.6 1.6]);
98 grid on;
99 title('constellation of matched filter output');
100 figure(8)
101 plot(Isam,Qsam,'X');
102 axis([-1.2 1.2 -1.2 1.2]);
103 grid on;
104 title('constellation of sampler');
105 figure(9)
106 subplot(211)
107 stem(final);
108 axis([0 data -2 2]);
109 grid on;
110 title('final received binary data');
111 subplot(212)
112 plot(20*log(abs(fft(final))));
113 axis([0 data 0 100]);
114 grid on;
115 title('aspectrum of final received binary data');

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2010-11-02 10:20  齐威王  阅读(16019)  评论(0编辑  收藏  举报

导航