📄 receiver_mainst.asv
字号:
clear all
clc
global nTx nRx Npart Mary Smap DS epsilon kappa
%Notes.
%Depending on the speed of your computer and the paramets set the algorithm
%may take a few minutes to a few hours.
%This code uses the Alamouit STBC algoritm. Number of transmitters is
%fixed at 2 but can really put any number of receivers.
%
%USER PARAMETERS%%%%%%%%%%%%%%%%%%%%%%%%%%
%You only need to edit these parameters, default parameters are set in []
Mary = 4; %M-PSK Constellation size (how many symbols in the set) [8]
nRx = 2; %Number of receive antennas to use can be 1-4 [2]
Nsymb = 1e4; %Number of symbols to use [1e4]
Lsnr=12; %Lower SNR bound in dB [12]
Usnr=16; %Upper SNR bound in dB [16]
DS = 0.01; %Normalized fading rate of the channel default [0.01]
Npart = 100; %Number of particles to use [200]
grad = 1; %Do gradient method enter [1], or don't do gradient enter 0
%For reference on gradient method: S.Hayking, K.Huber,
%and Z.Chen, "Bayesian Sequential State Estimation for
%MIMO Wireless Communiations", Proceedings of the IEEE,
%Vol.92, no.3, pp. 439, March 2004.
ratio = [1 10]; %ratio(1) = #training blocks, ratio(2) = total blocks;
%So for a ratio=[1 10] you are using 10% of your data
%for training sequences, and 90% (what's remaining) for
%transmitting data.
%Note that the PF does need training, if you set it to
%zero training, it may diverge if the fading rate is
%high enough or the snr is low enough.
%How treat the Training Block. Training assumes Pilot Assisted
%Transmission and uses ML estimation to get the initial channel estimate.
%OR you can assume perfect training.
TrainKind = 'PF'; %[PF perfect]
% PF - run in PF tracking mode
% perfect - assume perfect estimate always% true (assume traing is perfect), false (it is not)
%How to perfrom the channel tracking.
FilterKind = 'PF'; % [PF static perfect]
% PF - run in PF tracking mode (default mode of operation)
% static - no continous tracking only update estimate with each
% training block. This would be the performance of a conventional
% receiver that assumes a quasi-static channel. Set TrainKink =
% 'pefect'
% perfect - assume perfect estimate always. This just tells you how
% well you could do if you knew the channel perfectly.
%
%Noise distribution to use.
%Can use either Gaussian noise or mixture Gaussian noise. Note that if
%epsilon is set to zero then it does not matter what kappa is set to.
%Reference for non-Gaussian model, see Book by : Saleem A. Kassam, "Signal Detection in
%Non-Gaussian Noise", Springer-Verlag, pg.84
%Noise Distribution = (1-epsilon)*CN(0,sigma1) + epsilon*CN(0,kappa*sigma2)
%Noise Power = (1-epsilon)*sigma1 + epsilon*kappa*sigma2
epsilon = 0.00; % set = 0 for pure gaussian noise
kappa = 100; % if epsilon = 0, this parameter is redundant
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plotopt = 'b*'; %Plot parameters
nTx = 2; %Always using G2
drive = 'd1.mat'; %Drive number
datakind = 'simulated'; %simulated OR lucent
model = 'AR'; %Type of prediction used [AR DAR]
%Naming Convention
switch FilterKind,
case 'perfect'
Npart = 1; ratio(1) = 0;
end
part0 = sprintf('ST%d%d',nTx,nRx);
part1=sprintf('%dP',Npart);
if grad,
part2 = sprintf('G%s',FilterKind);
else
part2 = FilterKind;
end
part3 = sprintf('%dPSK',Mary);
part4 = num2str(DS); part4(1:2)=[];
Epchr = num2str(epsilon); if epsilon==0,Epchr='0'; else Epchr(1:2)=[]; end;
Kpchr = num2str(kappa); if epsilon==0,Kpchr='0'; end;
fname = sprintf('%s_%s_%s_%s_%sDS_%sEp%sKp_ratio%d-%d',part0,part1,part2,part3,part4,Epchr,Kpchr,ratio(1),ratio(2));
if nargin==0, fname = '0testing'; end
%Save File
fid = fopen([fname '.txt'],'w');
fprintf(fid,'Starting receiver simulation \n');
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%GLOBAL INITIALIZATIONS%%%%%%%%%%%%%%%%%%%%%%%%%%%
%For STBC G2
delay = 2;
symbperblock = 2;
%1 block is defined as the smallest unit of transmitted data that can be
%decoded
nblocks = floor(Nsymb / symbperblock);
%1 frame is defined as #training blocks + #testing blocks.
nframe = floor(nblocks/ratio(2));
%How many samples of the channel do I need?
ntimeinstant = nblocks*delay;
[junk,Smap]=psk_gen(Mary,1);
snrrange = Lsnr:Usnr;
MSE = ones(length(snrrange),1);
SER = ones(length(snrrange),1);
nch = nTx*nRx; %nTx * nRx
lambda = bessel(0,2*pi*DS);
[HH] = getchanneldata(DS,ntimeinstant,drive,datakind);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%file name: qpsk.m
%Written by Dr. James S. Kang, Cal Poly Pomona.
%Plot of QPSK waveform and spectrum.
%d = input data such as [1 1 0 0 1 0 0 1 1 1].
%fb = data rate in bps.
%fc = carrier frequency.
%Ac = Amplitude of the carrier.
%fstart = start frequency for spectrum plot.
%fend = end frequency for spectrum plot.
%To run the program, try
%qpsk([1 1 0 0 1 0 1 0 1 1],500,1000,1,0,4000)
d=[1 1 0 0 1 0 1 0 1 1];fb=500;fc=1000;Ac=1;fstart=0;fend=4000;
N=size(d,2); %N = number of data bits.
if rem(N,2) == 1
N=N+1
d(N)=0
end
N2=N/2;
M=32; %M = number of samples per bit duration.
tb=1/fb;tc=1/fc;
Nc=floor(M*tc/tb); %Nc = number of samples per period of carrier.
step=tb/M; %step = sampling interval.
for j = 1:N
if d(j) == 1
for i = 1:M
m((j-1)*M+i)=1;
end
else
for i = 1:M
m((j-1)*M+i)=-1;
end
end
end
for j = 1:N2
if d(j*2-1) == 1
for i = 1:2*M
mi((j-1)*2*M+i)=1;
si((j-1)*2*M+i)=Ac*cos(2*pi*(i-1)/Nc);
end
else
for i = 1:2*M
mi((j-1)*2*M+i)=-1;
si((j-1)*2*M+i)=Ac*cos(2*pi*(i-1)/Nc+pi);
end
end
if d(j*2) == 1
for i = 1:2*M
mq((j-1)*2*M+i)=1;
sq((j-1)*2*M+i)=Ac*sin(2*pi*(i-1)/Nc);
end
else
for i = 1:2*M
mq((j-1)*2*M+i)=-1;
sq((j-1)*2*M+i)=Ac*sin(2*pi*(i-1)/Nc+pi);
end
end
end
for k=1:M*N
t(k)=(k-1)*step;
s(k)=si(k)+sq(k);
end
figure(1)
subplot(3,1,1)
plot(t,m)
grid
%xlabel('Time')
ylabel('Amplitude')
title('Input Waveform')
subplot(3,1,2)
plot(t,mi)
grid
%xlabel('Time')
ylabel('Amplitude')
title('I Channel Waveform')
subplot(3,1,3)
plot(t,mq)
grid
xlabel('Time')
ylabel('Amplitude')
title('Q Channel Waveform')
figure(2)
subplot(3,1,1)
plot(t,si)
grid
%xlabel('Time')
ylabel('Amplitude')
title('I Channel Modulated Waveform')
subplot(3,1,2)
plot(t,sq)
grid
%xlabel('Time')
ylabel('Amplitude')
title('Q Channel Modulated Waveform')
subplot(3,1,3)
plot(t,s)
grid
xlabel('Time')
ylabel('Amplitude')
title('QPSK Waveform')
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -