QAM_64.m
上传用户:igold809
上传日期:2021-06-03
资源大小:4k
文件大小:4k
- % 64QAM-ofdm.m
- %********************** preparation part ********************************
- clc;
- clear;
- para=1024; % Number of parallel channel to transmit (points)
- fftlen=1024; % FFT length
- noc=1024; % Number of carrier
- nd=12; % Number of information OFDM symbol for one loop
- ml=6; % Modulation level : 64QAM
- sr=250000; % Symbol rate
- br=sr.*ml; % Bit rate per carrier
- gilen=256; % Length of guard interval (points)
- ber=zeros(1,31); % store ber
- %************************** main loop part ******************************
- nloop=1; % Number of simulation loops
- noe = 0; % Number of error data
- nod = 0; % Number of transmitted data
- for ebn0=0:1:30 %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
- %************************** 64QAM modulation *****************************
- mod_data_out=zeros(1024,12);
- for kk=1:1024
- mod_data_out(kk,:)=qam64_mod(paradata(kk,:));
- end
- ich=real(mod_data_out);
- qch=imag(mod_data_out);
- %******************* IFFT ************************
- x=ich+qch.*i;
- y=ifft(x); % ifft : built in function
- ich1=real(y); % real : built in function
- qch1=imag(y); % imag : built in function
- %********* Gurad interval insertion **********
- [ich2,qch2]= giins(ich1,qch1,fftlen,gilen,nd);
- fftlen2=fftlen+gilen;
- %********* Attenuation Calculation *********
- spow=sum(ich2.^2+qch2.^2)/nd./para; % sum : built in function
- attn=0.5*spow*sr/br*10.^(-ebn0/10);
- attn=sqrt(attn);
- %*************************** Receiver ********************************
- %***************** AWGN addition *********
- [ich3,qch3]=comb(ich2,qch2,attn);
- %****************** Guard interval removal ****************************
- [ich4,qch4]= girem(ich3,qch3,fftlen2,gilen,nd);
- %****************** FFT ******************
- rx=ich4+qch4.*i;
- ry=fft(rx); % fft : built in function
- ich5=real(ry); % real : built in function
- qch5=imag(ry); % imag : built in function
- dedata=ich5+qch5.*i;
- %************************** 64QAM demodulation *************************
- demodata=zeros(1024,72);
- for kk=1:1024
- demodata(kk,:)=qam64_demod(dedata(kk,:));
- end
- %************** 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*12),reshape(qch,1,1024*12));
- y=complex(reshape(ich5,1,1024*12),reshape(qch5,1,1024*12));
- scatterplot(x,1,0,'b*'),grid on,title('映射后未加噪声时星座图')
- scatterplot(y,1,0,'b*'),grid on,title('映射后加噪声时星座图,Eb/N0(dB)=20')
- eyediagram(y,2),grid on
-
- end
- end
- semilogy([0:1:30],ber,'bp'),grid on,title('信噪比-误码率曲线')
- xlabel('Eb/N0(dB)'),ylabel('bit error rate')
- %********************** Output result **********************************
- y=complex(reshape(ich5,1,1024*12),reshape(qch5,1,1024*12));
- scatterplot(y,1,0,'b*'),grid on,title('映射后加噪声时星座图,Eb/N0(dB)=30')
- eyediagram(y,2),grid on,title('映射后加噪声时眼图,Eb/N0(dB)=30')
- %******************** end of file **************************************