function main_1=final_qpsk()
%%%DSSS parameters
clc
close all
M=4;%Size of signal constellation
k = log2(M); % Number of bits per symbol
num = 10e0; % Number of bits to process
nsamp = 8; % Oversampling rate
brate = 9.6e3; % bit rate
degri=6;
code_size=(2^degri)-1;
rchip = brate*code_size; % Chip rate,Tc=1/rchip
sym_rate=(rchip/2);
fchip=1/rchip;
fs=(sym_rate*nsamp);
fc=fs/4;
Tsym=1/sym_rate;
Tsamp=Tsym/nsamp;
SNR=10;%[-15:5];
thershold=[.1:.1:1];
iterate=1;
final_prob=zeros(1,iterate);
thershold=30;
%% data generation
% Create a binary data stream as a column vector.
for q_snr=SNR
for z=1:iterate
close all
inp_data=randint(1,2*num);
temp=reshape(inp_data,2,num);
rdata_I=temp(1,:);
rdata_Q=temp(2,:);
[m n]=size(rdata_I);
%% bit-to-Symbol Mapping
% Convert the chips in spread_I(Q) into k-bit symbols
mat_bin=[2 1];
modulate1=mat_bin*[rdata_I;rdata_Q];
%% gray coding
% C. Map from binary coding to Gray coding.
mapping = [0 1 3 2];
modulate_gray = mapping(modulate1+1);
%% diffrential encoding
diff_modulate1=[];
diff_modulate1(1)=modulate_gray(1);
for k=2:length(modulate_gray)
diff_modulate1(k)=mod(modulate_gray(k)+diff_modulate1(k-1),4);
end
%% base band modulation
[m3 n3]=size(diff_modulate1);
gray_diff_modulate=zeros(size(diff_modulate1));
gray_diff_modulate(diff_modulate1==0)=sqrt(2)/2*(1+j);
gray_diff_modulate(diff_modulate1==1)=sqrt(2)/2*(-1+j);
gray_diff_modulate(diff_modulate1==2)=sqrt(2)/2*(-1-j);
gray_diff_modulate(diff_modulate1==3)=sqrt(2)/2*(1-j);
% gray_diff_modulate = modulate(modem.qammod(M),diff_modulate1);
gray_diff_modulated_I=real(gray_diff_modulate);
gray_diff_modulated_Q=imag(gray_diff_modulate);
%% scater Plot of Symbols
% Plot first 10 symbols in a stem plot.
if z==iterate
temp2=[gray_diff_modulate];
scatterplot(temp2',nsamp,0,'rx');%rcv_a,N,0,'bx'
end
%% Filter Definition
% Define filter-related parameters.
filtorder = 40; % Filter order
delay = filtorder/(nsamp); % Group delay (# of input samples)
cutoff= (sym_rate)/2;%(symbol rate)/2
rolloff = 0.25; % Rolloff factor of filter
rrcfilter = rcosine(1,nsamp,'fir/sqrt',rolloff,delay);
% [b1 a1] = firrcos(filtorder,cutoff,rolloff,fs,'rolloff');
if z==iterate
figure(2); impz(rrcfilter,1);
figure(3); freqz(rrcfilter,1);
end
%% data spereder
[spreader_cod_I spreader_cod_Q]=g_bitstream(code_size);%code_generator function generate m-sequence code
temp=xcorr(spreader_cod_Q);
if z==iterate
figure(6)
stem(temp)
end
[m4 n4]=size(gray_diff_modulated_I);
if z==iterate
figure(7)
y=xcorr(spreader_cod_Q);
stem(y)
end
for l=1:n4
spread_I1(l,:)=(spreader_cod_I.*gray_diff_modulated_I(l));
spread_Q1(l,:)=(spreader_cod_Q.*gray_diff_modulated_Q(l));
end
[m1 n1]=size(spread_I1);
spread_I=reshape(spread_I1',1,(m1*n1));
spread_Q=reshape(spread_Q1',1,(m1*n1));
%% Transmitted Signal after spreading
% Upsample and apply square root raised cosine filter.
% trans_up_I=rectpulse(spread_I,nsamp);
% trans_up_Q=rectpulse(spread_Q,nsamp);
% trans_sig_I = filter(b1,a1,trans_up_I);
% trans_sig_Q = filter(b1,a1,trans_up_Q);
trans_sig_I = rcosflt(spread_I,1,nsamp,'filter',rrcfilter);
trans_sig_Q = rcosflt(spread_Q,1,nsamp,'filter',rrcfilter);
trans_sig=trans_sig_I+j*trans_sig_Q;
%% Create eye diagram for part of filtered signal.
% ploteye(trans_I(filtorder/2:2000), nsamp);
%% plot spectrum after spreading
%I branch spectrum
if z==iterate
figure(8)
L1=length(trans_sig_I);%length(symbol);
NFFT = 2^nextpow2(L1); % Next power of 2 from length of y
Y1 = fft(trans_sig_I,NFFT)/L1;
f = fs/2*linspace(0,1,NFFT/2);
%%%%%% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y1(1:NFFT/2)))
title('Single-Sided Amplitude Spectrum after spreding')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
end
%% modulation
if fc >= fs/2,
error(generatemsgid('InvalidRange'),'The carrier frequency must be less than half the sampling frequency.');
end
[r,c]=size(trans_sig);
if r*c == 0,
trans_IF_R = [];
end
if (r==1), % convert row vector to column
trans_IF_R = trans_IF_R(:); len = c;
else
len = r;
end
t = (0:1/fs:((len-1)/fs))';
t = t(:,ones(1,size(trans_sig,2)));
trans_IF_R = real(trans_sig).*cos(2*pi*fc*t)+imag(trans_sig).*sin(2*pi*fc*t);
% trans_IF_R=real(trans_IF);
figure()
L1=length(trans_IF_R);%length(symbol);
NFFT = 2^nextpow2(L1); % Next power of 2 from length of y
Y1 = fft(trans_IF_R,NFFT)/L1;
f = fs/2*linspace(0,1,NFFT/2);
%%%%%% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y1(1:NFFT/2)))
title('Single-Sided Amplitude Spectrum after spreding')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
%% Channel
% fd = 2e5; % Maximum Doppler shift (Hz)
% h=rayleighchan(Tsamp,fd);
% h.StoreHistory = true; % Allow states to be stored
% fad_sig=filter(h,trans_IF_R);
% % Send signal over an AWGN channel.
EbNo = 50; % In dB
snr = EbNo + 10*log10(k) - 10*log10(code_size);
ynoisy = awgn(trans_IF_R,snr);
%% random delay generation
% w=(floor(rand(1,30+floor(10*rand(1)+1))+0.5)-.5)*2;
% rxsig=[w,y_pasband];
%% demod recived _IF
yf=ynoisy;
[r,c]=size(yf);
if r*c == 0,
yrx_IQ = [];
end
if (r==1), % convert row vector to column
yf = yf(:); len = c;
else
len = r;
end
t = (0:1/fs:((len-1)/fs))';
t = t(:,ones(1,size(yf,2)));
x_I = yf.*cos(2*pi*fc*t);
[b,a]=butter(5,fc*2/fs);
for i = 1:size(yf,2),
x_I(:,i) = filtfilt(b,a,x_I(:,i));
end
t = (0:1/fs:((len-1)/fs))';
t = t(:,ones(1,size(yf,2)));
x_Q = yf.*sin(2*pi*fc*t);
[b,a]=butter(5,fc*2/fs);
for i = 1:size(yf,2),
x_Q(:,i) = filtfilt(b,a,x_Q(:,i));
end
yrx_IQ=x_I+j*x_Q;
%% reciver
yrx_I_f = rcosflt(real(yrx_IQ),1,nsamp,'Fs/filter',rrcfilter);
% yrx_I = downsample(yrx_I,nsamp); % Downsample.
yrx_I = yrx_I_f(2*delay+1:end-2*delay); % Account for delay.
yrx_Q_f = rcosflt(imag(yrx_IQ),1,nsamp,'Fs/filter',rrcfilter);
% yrx_Q = downsample(yrx_Q,nsamp); % Downsample.
yrx_Q = yrx_Q_f(2*delay+1:end-2*delay); % Account for delay.
xI_rcos_down = downsample(yrx_I_f,nsamp); % Downsample.
xI_rcos_down = xI_rcos_down(2*delay+1:end-2*delay); % Account for delay.
xQ_rcos_down = downsample(yrx_Q_f,nsamp); % Downsample.
xQ_rcos_down = xQ_rcos_down(2*delay+1:end-2*delay); % Account for delay.
% xI_rcos_down=[x_rcos_I];
% xQ_rcos_down=[x_rcos_Q];
yrx=yrx_I+j*yrx_Q;
%% Scatter Plot
% Create scatter plot of received signal before and
% after filtering.
h = scatterplot(sqrt(nsamp)*yrx_IQ(1:nsamp*5e2),nsamp,0,'g.');
hold on;
scatterplot(yrx(1:5e2),1,0,'kx',h);
title('Received Signal, Before and After Filtering');
legend('Before Filtering','After Filtering');
axis([-5 5 -5 5]); % Set axis ranges.
%% acquisition
% %%%%acquisition %%%%%%%%%
spreader_cod_I_up=upsample(spreader_cod_I,nsamp);
spreader_cod_Q_up=upsample(spreader_cod_Q,nsamp);
M=1000;% M denot the number of chips we should check in recived signal
DMF_length=(code_size*nsamp); % the number of tap in DMF
%%%%adaptive parameter
sum_length=3; %%inth article with "L" notation
window_length=8;
const_cof_ther=.426;%%(false alarm prob=.01)
sort_const_cof_ther=1.3;%%(false alarm prob=.01)
K=6;
number_seg_I=fix((length(yrx_I))/DMF_length);
number_seg_code=fix((length(spreader_cod_I_up))/DMF_length);
cof_DMF_I=spreader_cod_I_up(1,(1:DMF_length));
cof_DMF_Q=spreader_cod_Q_up(1,(1:DMF_length));
yrx_I=yrx_I';
yrx_
2_6.rar_DELAY IN DSSS_FOE_acqusition_acqusition of DSSS_dsss
版权申诉
138 浏览量
2022-09-22
18:44:25
上传
评论
收藏 22KB RAR 举报
JaniceLu
- 粉丝: 79
- 资源: 1万+
最新资源
- Music-Player +PlayerActivity+ rockplayer+ SeeJoPlayer 播放器JAVA源码
- vscode-1.46.0.tar源码文件
- 最近很火植物大战僵尸杂交版2.08苹果+安卓+PC+防闪退工具V2+修改工具+高清工具+通关存档整合包更新
- 超级好用的截图工具PixPin,可录制Gif图
- Screenshot_2024-05-21-17-06-42-64_2332cb9b27b851b548ba47a91682926c.jpg
- 毕业设计参考 - 基于树莓派、OpenCV及Python的人脸识别
- node-v18.20.2-linux-arm64
- 222222222222
- 16张相机标定图片,可复现本文畸变矫正
- dbeaver-ce-23.3.1-x86_64-setup.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈