close all
fs=8e5 %抽样频率
fm=20e3 %基带频率
n=2*(6*fs/fm)
final=(1/fs)*(n-1)
fc=2e5 % 载波频率
t=0:1/fs:(final)
Fn=fs/2 %耐奎斯特频率
%用正弦波产生方波
twopi_fc_t=2*pi*fm*t
A=1
phi=0
x = A * cos(twopi_fc_t + phi)
% 方波
am=1
x(x>0)=am
x(x<0)=-1
figure(1)
plot(t,x)
axis([0 2e-4 -2 2])
title('等概二进制信源')
grid on
car=sin(2*pi*fc*t) %载波
psk=x.*car %载波调制
figure(2)
plot(t,psk)
axis([0 200e-6 -2 2])
title('2PSK信号')
grid on
figure(3)
plot(abs(fft(psk)))%产生2psk信号的频谱
grid on
title('2psk信号频谱')xlabel('f')
% 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
%
clcclear
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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)