QAM.m
上传用户:tdqh1998
上传日期:2021-06-03
资源大小:3k
文件大小:4k
- % OFDM
- % QAM.m
- %********************** preparation part ***************************
- clc;
- clear;
- para=1024; % Number of parallel channel to transmit (points)
- fftlen=1024; % FFT length
- noc=1024; % Number of carrier
- nd=6; % Number of information OFDM symbol for one loop
- ml=2; % Modulation level : QAM
- sr=250000; % Symbol rate
- br=sr.*ml; % Bit rate per carrier
- gilen=256; % Length of guard interval (points)
- ber=zeros(1,21); % store ber
- %************************** main loop part **************************
- nloop=10; % Number of simulation loops
- noe = 0; % Number of error data
- nod = 0; % Number of transmitted data
- for ebn0=0:1:20 %Eb/No
- noe = 0; % Number of error data
- nod = 0; % Number of transmitted data
- for iii=1:nloop
- %************************** transmitter *********************************
- %************************** Data generation ****************************
- seldata=rand(1,para*nd*ml)>0.5; % rand : built in function
- %****************** Serial to parallel conversion ***********************
- paradata=reshape(seldata,para,nd*ml); % reshape : built in function
- %**************************QAM modulation *****************************
- [ich,qch]=qam_mod(paradata,para,nd,ml);
- kmod=1/sqrt(42); % sqrt : built in function
- ich1=ich.*kmod;
- qch1=qch.*kmod;
- %******************* IFFT ************************
- x=ich1+qch1.*i;
- y=ifft(x); % ifft : built in function
- ich2=real(y); % real : built in function
- qch2=imag(y); % imag : built in function
- %********* Gurad interval insertion **********
- [ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
- fftlen2=fftlen+gilen;
- %********* Attenuation Calculation *********
- spow=sum(ich3.^2+qch3.^2)/nd./para; % sum : built in function
- attn=0.5*spow*sr/br*10.^(-ebn0/10);
- attn=sqrt(attn);
- %*************************** Receiver *****************************
- %***************** AWGN addition *********
- [ich4,qch4]=comb(ich3,qch3,attn);
- %****************** Guard interval removal *********
- [ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);
- %****************** FFT ******************
- rx=ich5+qch5.*i;
- ry=fft(rx); % fft : built in function
- ich6=real(ry); % real : built in function
- qch6=imag(ry); % imag : built in function
- %***************** QAM demoduration *******************
- ich7=ich6./kmod;
- qch7=qch6./kmod;
- [demodata]=qam_demod(ich7,qch7,para,nd,ml);
- %************** Parallel to serial conversion *****************
- demodata1=reshape(demodata,1,para*nd*ml);
- %************************** Bit Error Rate (BER) ****************************
- % instantaneous number of error and data
- noe2=sum(abs(demodata1-seldata)); % sum : built in function
- nod2=length(seldata); % length : built in function
- % cumulative the number of error and data in noe and nod
- noe=noe+noe2;
- nod=nod+nod2;
-
- end
- ber(1,ebn0+1)=noe/nod
- switch ebn0
- case 20
- x=complex(reshape(ich,1,1024*6),reshape(qch,1,1024*6));
- y=complex(reshape(ich6,1,1024*6),reshape(qch6,1,1024*6));
- scatterplot(x,1,0,'b*'),grid on,title('映射后未加噪声时星座图')
- eyediagram(y,2)
- scatterplot(y,1,0,'b*'),grid on,title('映射后加噪声时星座图,Eb/N0(dB)=3')
-
- end
- end
- semilogy([0:1:20],ber,'bp'),grid on,title('信噪比-误码率曲线')
- xlabel('Eb/N0(dB)'),ylabel('bit error rate')
- %********************** Output result **********************************
- y=complex(reshape(ich6,1,1024*6),reshape(qch6,1,1024*6));
- scatterplot(y,1,0,'b*'),grid on,title('映射后加噪声时星座图,Eb/N0(dB)=20')
- eyediagram(y,2)
- %******************** end of file **************************************