完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
echo off;clear all;close all;
clc;tic; % --------------------------------------------- % % 参数定义 % % --------------------------------------------- % NumLoop = 10000; NumSubc = 64; NumCP = 8; SyncDelay = 0; %----------------------------------------------- % 生成的随机二进制流作为传输信号 %----------------------------------------------- BitsTx = floor(rand(1,NumLoop*NumSubc)*2);%用rand产生0:1的随机数,不会产生负值,如果用randn会产生负值;乘以2是为了使用floor函数 % --------------------------------------------- % % QAM 调制 % % --------------------------------------------- % % input: BitsTx(1,NumLoop*NumSubc); output:SymQAM(NumLoop,NumSubc/2) SymQAMtmp = reshape(BitsTx,2,NumLoop*NumSubc/2).'; SymQAMtmptmp = bi2de(SymQAMtmp,2,'left-m***'); QAMTable = [-1-i -1+i 1-i 1+i]; SymQAM = QAMTable(SymQAMtmptmp+1); % --------------------------------------------- % % IFFT % input: SymQAM(NumLoop,NumSubc/2); output: SymIFFT(NumSubc,NumLoop) % --------------------------------------------- % SymIFFT = zeros(NumSubc,NumLoop); SymIFFTtmp = reshape(SymQAM,NumSubc/2,NumLoop); SymIFFTtmptmp = zeros(NumSubc,NumLoop); SymIFFTtmptmp(1,:) = real(SymIFFTtmp(1,:)); % 实部 SymIFFTtmptmp(NumSubc/2+1,:) = imag(SymIFFTtmp(1,:)); % 虚部 SymIFFTtmptmp(2:NumSubc/2,:) = SymIFFTtmp(2:NumSubc/2,:); SymIFFTtmptmp((NumSubc/2+2):NumSubc,:) = flipdim(conj(SymIFFTtmp(2:NumSubc/2,:)),1); SymIFFT = ifft(SymIFFTtmp,NumSubc,1); % --------------------------------------------- % % 添加循环前缀 % % --------------------------------------------- % % input: SymIFFT(NumSubc,NumLoop); output: SymCP(NumSubc + NumCP,NumLoop) NumAddPrefix = NumSubc + NumCP; SymCP = zeros(NumAddPrefix,NumLoop); RowPrefix = (NumSubc - NumCP + 1):NumSubc; SymCP = [SymIFFT(RowPrefix,:);SymIFFT];%(把保护间隔放在符号的前面) %---------------------SLM----------------% M=2; Phase2=zeros(M,NumSubc); Yslm2=zeros(M,NumSubc); Seldata2=zeros(M,NumSubc); for mmm=1:M a=rand(1,NumSubc); Phase2(mmm,:)=(a<0.25)+j*(a>=0.25).*(a<0.5)-(a>=0.5).*(a<0.75)-j*(a>=0.75); Seldata2(mmm,:)=Phase2(mmm,:); Yslm2(mmm,:)=ifft(Seldata2(mmm,:)); % ifft : built in function mmam2(mmm)=max(abs(Yslm2(mmm,:)).^2); end [mmioam2,idxm2]=min(mmam2); P2=Phase2(idxm2,:); P2; yslm2=Yslm2(mmm,:); % --------------------------------------------- % % 通过信道 % % --------------------------------------------- % % input: SymCP(NumSubc + NumCP,NumLoop); output: SymCh(1,(NumSubc + NumCP)*NumLoop) SymChtmp = zeros(1,(NumSubc + NumCP)*NumLoop); SymChtmp = SymCP(:).'; % 进行这个转置操作之后就成了一个矢量; 并串变换 % 相当于把矩阵的列向量依次排列 改变为一个行向量 for snr=0:2:13; % = SNR + 10*log10(log2(2)); snrIndex4=0; snrIndex4=snrIndex4+1; BerSnrTable_SLM2(snrIndex4,1) = snr; SymCh = awgn(yslm2,snr,'measured'); % --------------------------------------------- % % 去除保护间隔 % % --------------------------------------------- % % input: SymCh(1,(NumSubc + NumCP)*NumLoop); output: SymDeCP(NumSubc,NumLoop) SymDeCP = zeros(NumSubc,NumLoop); SymDeCPtmp = reshape( SymCh ,NumSubc + NumCP,NumLoop); SymDeCP = SymDeCPtmp((NumCP+1+SyncDelay):NumAddPrefix+SyncDelay,:); % --------------------------------------------- % % FFT % % --------------------------------------------- % % input: SymDeCP(NumSubc,NumLoop); output: SymFFT(NumSubc,NumLoop) SymFFT = fft(SymDeCP,NumSubc,1); % --------------------------------------------- % % 解调 % % --------------------------------------------- % % SymFFT(NumSubc,NumLoop); output: SymDec(NumSubc,NumLoop) SymDec = zeros(NumSubc,NumLoop); SymEqtmp(1,:) = SymFFT(1,:)+i*SymFFT(NumSubc/2+1,:); SymEqtmp(2:NumSubc/2,:) = SymFFT(2:NumSubc/2,:); for m = 1:NumLoop for n = 1:NumSubc/2 Real = real(SymEqtmp(n,m)); Imag = imag(SymEqtmp(n,m)); if( abs((Real -1)) < abs((Real +1))) % 每个点到坐标轴上1和-1的距离,哪个离1近就把1付给它,同理得-1 SymDec(2*n-1,m) = 1; else SymDec(2*n-1,m) = 0;%把实部放在奇数行 end if( abs((Imag -1)) < abs((Imag +1 )) ) SymDec(2*n,m) = 1; else SymDec(2*n,m) = 0;%把虚部放在偶数行 end end end %---------------------------------------------------------------------- %误码率 Bit Error %---------------------------------------------------------------------- BitsRx = zeros(1,NumSubc*NumLoop); BitsRx = SymDec(:).'; [Num,Ber] = symerr(BitsTx,BitsRx);%(BitsTx是原始数据符号) BerSnrTable_SLM2(1,2) = Ber ; end; BerSnrTable_SLM2_plot=zeros(7,1); BerSnrTable_SLM2_plot=BerSnrTable_SLM2(:,2); save('SLM2','BerSnrTable_SLM2_plot'); semilogy(BerSnrTable_SLM2(:,1),BerSnrTable_SLM2_plot,'o-'); xlabel('SNR'); ylabel('BER'); grid on; |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
使用simulink进行三相短路故障分析时,各参数应该如何设置
1311 浏览 1 评论
想请教一下图中是simulink的什么模块,需要这种三段斜率函数模块但没找到在哪
1433 浏览 1 评论
2349 浏览 1 评论
200圆!求助大佬给一份VSG并网和离网模式的simulink仿真
2614 浏览 0 评论
MATLAB(3)--矩阵的引用(sub2ind、ind2sub、reshape函数使用)
3445 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 22:32 , Processed in 0.497692 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号