Matlab实现 psk Dqpsk Qpsk 仿真程序

Matlab实现 psk Dqpsk Qpsk 仿真程序,第1张

% file c10_MCQPSKrun.m

%

%

function BER_MC=c10_MCQPSKrun(N,Eb,No,ChanAtt,...

TimingBias,TimingJitter,PhaseBias,PhaseJitter)

fs = 1e+6

% sampling Rate (samples/second)

SymRate = 1e+5

% symbol rate (symbols/second)

Ts = 1/fs

% sampling period

TSym = 1/SymRate

% symbol period

SymToSend = 100%N

% symbols to be transmitted

ChanBW = 4.99e+5

% bandwidth of channel (Hz)

MeanCarrierPhaseError = PhaseBias

% mean of carrier phase

StdCarrierPhaseError = PhaseJitter

% stdev of phese error

MeanSymbolSyncError = TimingBias

% mean of symbol sync error

StdSymbolSyncError = TimingJitter

% stdev of symbol sync error

ChanGain = 10^(-ChanAtt/20)

% channel gain (linear units)

TxBitClock = Ts/2

% transmitter bit clock

RxBitClock = Ts/2

% reciever bit clock

%

%

Standard deviation of noise and signal amplitude at receiver input.

%

RxNoiseStd = sqrt((10^((No-30)/10))*(fs/2))

% stdev of noise

TxSigAmp = sqrt(10^((Eb-30)/10)*SymRate)

% signal amplitude

%

% Allocate some memory for probes.

%

SampPerSym = fs/SymRate

probe1 = zeros((SymToSend+1)*SampPerSym,1)

probe1counter = 1

probe2 = zeros((SymToSend+1)*SampPerSym,1)

probe2counter = 1

%

% Counters to keep track of how many symbols have have been sent.

%

TxSymSent = 1

RxSymDemod = 0

%

% Buffers that contain the transmitted and received data.

%

[unused,SourceBitsI] = random_binary(SymToSend,1)

[unused,SourceBitsQ] = random_binary(SymToSend,1)

%

% Differentially encode the transmitted data.

%

TxBitsI = SourceBitsI*0

TxBitsQ = SourceBitsQ*0

for k=2:length(TxBitsI)

TxBitsI(k) = or(and(not(xor(SourceBitsI(k),SourceBitsQ(k))),...

xor(SourceBitsI(k),TxBitsI(k-1))), ...

and(xor(SourceBitsI(k),SourceBitsQ(k)),...

xor(SourceBitsQ(k),TxBitsQ(k-1))))

TxBitsQ(k) = or(and(not(xor(SourceBitsI(k),SourceBitsQ(k))),...

xor(SourceBitsQ(k),TxBitsQ(k-1))), ...

and(xor(SourceBitsI(k),SourceBitsQ(k)),...

xor(SourceBitsI(k),TxBitsI(k-1))))

end

%

% Make a complex data stream of the I and Q bits.

%

TxBits = ((TxBitsI*2)-1)+(sqrt(-1)*((TxBitsQ*2)-1))

%

RxIntegrator = 0

% initialize receiver integrator

TxBitClock = 2*TSym

% initialize transmitter

%

% Design the channel filter, and create the filter state array.

%

[b,a] = butter(2,ChanBW/(fs/2))

b=[1]a=[1]

% filter bypassed

[junk,FilterState]=filter(b,a,0)

%

% Begin simulation loop.

%

while TxSymSent <SymToSend

%

% Update the transmitter's clock, and see

% if it is time to get new data bits

%

TxBitClock=TxBitClock+Ts

if TxBitClock >TSym

%

% Time to get new bits

%

TxSymSent=TxSymSent+1

%

% We don't want the clock to increase off

% to infinity, so subtract off an integer number

% of Tb seconds

%

function output_frame = demodulation(input_modu, index)

% demodulation for IEEE802.11a

% Input:input_modu, complex values representing constellation points

% index

% Output: output_frame, output bit stream (data unit is one bit)

% In this version, increase the quatilization levels into 8.

% note: Matlab index starts from 1

Q_length=length(input_modu)

QAM_input_I = real(input_modu)

QAM_input_Q = imag(input_modu)

output_frame = zeros(1,length(input_modu)*index)

switch index

case 1,

BPSK_Demodu_I = [0 1] %f(m)=(m+1)/2 + 1, so I=-1 --->1, I=1 --->2

idx = find(QAM_input_I>1)

QAM_input_I(idx) = 1

idx = find(QAM_input_I<-1)

QAM_input_I(idx) = -1

output_frame = BPSK_Demodu_I(round((QAM_input_I+1)/2) + 1)

case 2,

QPSK_Demodu_IQ = [0 1]%f(m)=(m+1)/2 + 1, so I=-1 --->1, I=1 --->2

idx = find(QAM_input_I>派租告尘明1)

QAM_input_I(idx) = 1

idx = find(QAM_input_I<-1)

QAM_input_I(idx) = -1

idx = find(QAM_input_Q>1)

QAM_input_Q(idx) = 1

idx = find(QAM_input_Q<-1)

QAM_input_Q(idx) = -1

output_frame(1:2:end) = QPSK_Demodu_IQ(round((QAM_input_I+1)/2) + 1)

output_frame(2:2:end) = QPSK_Demodu_IQ(round((QAM_input_Q+1)/2) + 1)

case 3,

remapping=[0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1].'

for i=1:Q_length

phase_det=[2<QAM_input_I(i)&0<QAM_input_Q(i) 0<型中QAM_input_I(i)&QAM_input_I(i)<2&0<QAM_input_Q(i) QAM_input_I(i)<-2&0<QAM_input_Q(i) -2<QAM_input_I(i)&QAM_input_I(i)<0&0<QAM_input_Q(i) QAM_input_I(i)<-2&QAM_input_Q(i)<0 QAM_input_I(i)<0&-2<QAM_input_I(i)&QAM_input_Q(i)<0 2<QAM_input_I(i)&QAM_input_Q(i)<0 0<QAM_input_I(i)&QAM_input_I(i)<2&QAM_input_Q(i)<0]

a=find(phase_det)

output_frame((1+(i-1)*3):(3+(i-1)*3))=remapping((1+(a-1)*3):(3+(a-1)*3))

end

case 4,

QAM_16_Demodu_IQ = [0 1 3 2] %f(m)=(m+3)/2 + 1, so I=-3 --->1, I=1 --->3

idx = find(QAM_input_I>3)

QAM_input_I(idx) = 3

idx = find(QAM_input_I<-3)

QAM_input_I(idx) = -3

idx = find(QAM_input_Q>3)

QAM_input_Q(idx) = 3

idx = find(QAM_input_Q<-3)

QAM_input_Q(idx) = -3

tmp = round((QAM_input_I+3)/2) + 1

output_frame(1:4:end) = bitget(QAM_16_Demodu_IQ(tmp),2)

output_frame(2:4:end) = bitget(QAM_16_Demodu_IQ(tmp),1)

tmp = round((QAM_input_Q+3)/2) + 1

output_frame(3:4:end) = bitget(QAM_16_Demodu_IQ(tmp),2)

output_frame(4:4:end) = bitget(QAM_16_Demodu_IQ(tmp),1)

case 5,

remapping=[0 0 0 0 00 0 0 0 10 0 0 1 00 0 0 1 10 0 1 0 00 0 1 0 10 0 1 1 00 0 1 1 1

0 1 0 0 00 1 0 0 10 1 0 1 00 1 0 1 10 1 1 0 00 1 1 0 10 1 1 1 00 1 1 1 1

1 0 0 0 01 0 0 0 11 0 0 1 01 0 0 1 11 0 1 0 01 0 1 0 11 0 1 1 01 0 1 1 1

1 1 0 0 01 1 0 0 11 1 0 1 01 1 0 1 11 1 1 0 01 1 1 0 11 1 1 1 01 1 1 1 1].'

for i=1:Q_length

phase_det=[4<QAM_input_I(i)&0<QAM_input_Q(i)&QAM_input_Q(i)<22<QAM_input_I(i)&QAM_input_I(i)<4&0<QAM_input_Q(i)&QAM_input_Q(i)<20<QAM_input_I(i)&QAM_input_I(i)<2&0<QAM_input_Q(i)&QAM_input_Q(i)<24<QAM_input_I(i)&2<QAM_input_Q(i)&QAM_input_Q(i)<4

2<QAM_input_I(i)&QAM_input_I(i)<4&2<QAM_input_Q(i)&QAM_input_Q(i)<40<QAM_input_I(i)&QAM_input_I(i)<2&2<QAM_input_Q(i)&QAM_input_Q(i)<42<QAM_input_I(i)&QAM_input_I(i)<4&4<QAM_input_Q(i)0<QAM_input_I(i)&QAM_input_I(i)<2&4<QAM_input_Q(i)

QAM_input_I(i)<-4&0<QAM_input_Q(i)&QAM_input_Q(i)<2-4<QAM_input_I(i)&QAM_input_I(i)<-2&0<QAM_input_Q(i)&QAM_input_Q(i)<2-2<QAM_input_I(i)&QAM_input_I(i)<0&0<QAM_input_Q(i)&QAM_input_Q(i)<2QAM_input_I(i)<-4&2<QAM_input_Q(i)&QAM_input_Q(i)<4

-4<QAM_input_I(i)&QAM_input_I(i)<-2&2<QAM_input_Q(i)&QAM_input_Q(i)<4-2<QAM_input_I(i)&QAM_input_I(i)<0&2<QAM_input_Q(i)&QAM_input_Q(i)<4-4<QAM_input_I(i)&QAM_input_I(i)<-2&4<QAM_input_Q(i)-2<QAM_input_I(i)&QAM_input_I(i)<0&4<QAM_input_Q(i)

QAM_input_I(i)<-4&-2<QAM_input_Q(i)&QAM_input_Q(i)<0-4<QAM_input_I(i)&QAM_input_I(i)<-2&-2<QAM_input_Q(i)&QAM_input_Q(i)<0-2<QAM_input_I(i)&QAM_input_I(i)<0&0<QAM_input_Q(i)&QAM_input_Q(i)<0QAM_input_I(i)<-4&-4<QAM_input_Q(i)&QAM_input_Q(i)<-2

-4<QAM_input_I(i)&QAM_input_I(i)<-2&-4<QAM_input_Q(i)&QAM_input_Q(i)<-2-2<QAM_input_I(i)&QAM_input_I(i)<0&-4<QAM_input_Q(i)&QAM_input_Q(i)<-2-4<QAM_input_I(i)&QAM_input_I(i)<-2&QAM_input_Q(i)<-4-2<QAM_input_I(i)&QAM_input_I(i)<0&QAM_input_Q(i)<-4

4<QAM_input_I(i)&-2<QAM_input_Q(i)&QAM_input_Q(i)<02<QAM_input_I(i)&QAM_input_I(i)<4&-2<QAM_input_Q(i)&QAM_input_Q(i)<00<QAM_input_I(i)&QAM_input_I(i)<2&0<QAM_input_Q(i)&QAM_input_Q(i)<04<QAM_input_I(i)&-4<QAM_input_Q(i)&QAM_input_Q(i)<-2

2<QAM_input_I(i)&QAM_input_I(i)<4&-4<QAM_input_Q(i)&QAM_input_Q(i)<-20<QAM_input_I(i)&QAM_input_I(i)<2&-4<QAM_input_Q(i)&QAM_input_Q(i)<-22<QAM_input_I(i)&QAM_input_I(i)<4&QAM_input_Q(i)<-40<QAM_input_I(i)&QAM_input_I(i)<2&QAM_input_Q(i)<-4]

a=find(phase_det)

output_frame((1+(i-1)*5):(5+(i-1)*5))=remapping((1+(a-1)*5):(5+(a-1)*5))

end%5+i 3+i 1+i 5+3*i 3+3*i 1+3*i 3+5*i 1+5*i -5+i -3+i -1+i -5+3*i -3+3*i -1+3*i -3+5*i -1+5*i -5-i -3-i -1-i -5-3*i -3-3*i -1-3*i -3-5*i -1-5*i 5-i 3-i 1-i 5-3*i 3-3*i 1-3*i 3-5*i 1-5*i

case 6,

QAM_64_Demodu_IQ = [0 1 3 2 6 7 5 4] %f(m)=(m+7)/2 + 1, so I=-7 --->1, I=1 --->5

idx = find(QAM_input_I>7)

QAM_input_I(idx) = 7

idx = find(QAM_input_I<-7)

QAM_input_I(idx) = -7

idx = find(QAM_input_Q>7)

QAM_input_Q(idx) = 7

idx = find(QAM_input_Q<-7)

QAM_input_Q(idx) = -7

tmp = round((QAM_input_I+7)/2) + 1

output_frame(1:6:end) = bitget(QAM_64_Demodu_IQ(tmp),3)

output_frame(2:6:end) = bitget(QAM_64_Demodu_IQ(tmp),2)

output_frame(3:6:end) = bitget(QAM_64_Demodu_IQ(tmp),1)

tmp = round((QAM_input_Q+7)/2) + 1

output_frame(4:6:end) = bitget(QAM_64_Demodu_IQ(tmp),3)

output_frame(5:6:end) = bitget(QAM_64_Demodu_IQ(tmp),2)

output_frame(6:6:end) = bitget(QAM_64_Demodu_IQ(tmp),1)

end

您好,您这样:

clc

clear

fc=4800fs=12000fb=2400

%要调制的数字信号

a=randint(1,12,2)%随机产生12个“0”,“1”

s=zeros(1,60)

for i=1:12

for j=1:5

if(a(i)==0)

 斗裤谈 s(j+(i-1)*5)=0

else

s(j+(i-1)*5)=1

end

end

end

plot(s)xlabel('基带信号')

figure

pwelch(s)%功率谱

figure

%波形成形滤波器(平方根升余弦滚降)

h=firrcos(14,1200,1200,4800,'sqrt')

figure

stem(h)xlabel('成形滤波器的单位冲击响应')

[H,W]=freqz(h,1)

H=abs(H)

figure

plot(H)xlabel('成形滤波器的频率响应')

s=fftfilt(h,s)

figure

plot(s)xlabel('通过成形滤波器后的基带信号')

figure

pwelch(s)%经波形成形滤波器后的功率谱

%已调信号

e=dmod(a,4800,2400,12000,'空碰psk',2)%调制

figure

plot(e)xlabel('已调信号')

enoise=e+randn(1,60)%enoise=e+.1*randn(1,60)不同功率的高斯白噪声

aa=ddemod(enoise,4800,2400,12000,'psk',2)%解调

figure

stem(aa)xlabel('解调后的数字信号')%解调后的数字信号

p=symerr(a,aa)/12 %误码率

%误码率曲线

figure

r=-6:3:12

rr=10.^(r/10)

pe1=1/2*exp(-rr)%相干解调的误码率曲线

hold on

plot(r,pe1,'r')grid on

pe2=(1-1/2*erfc(sqrt(rr))).*erfc(sqrt(rr))%差分相干解调的误码纯租率曲线

plot(r,pe2,'b')xlabel('bpsk,dpsk误码率曲线')

set(gca,'XTick',-6:3:18)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12559049.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存