2017-12-17 2 views
0

파일에서 비트를 읽고 복잡한 이중으로 변환하려고합니다. 각 숫자는 32 비트 (16 Re 및 16 Im)입니다. 그런 다음 qamdemod를 사용하여 복소수 당 6 비트를 얻고 해당 비트를 새 텍스트 파일에 저장하려고합니다. 나는 그 프로그램을했지만 나는 항상 출력으로 같은 수를 가져옵니다 010011 = 프로그램 50 :64QAM 복조 - 항상 동일한 출력을 얻습니다.

% % Main Algorithm 
N=16; %length of one sample 
RUNTIME = input('How long you want to run in sec='); 
prompt = '0 - for sequentially. 1 - for randomaly ='; 
n = input(prompt); 
x=0; 
switch n 
    case 0 
     timerID = tic; %# Start a clock and return the timer ID 
     disp('sequentially'); 
     fid=fopen('rand.bin'); %need to check if file opened 
     fid_w=fopen('samples.txt','w'); %write to file 
     while true 
     %# Perform process 
      Re=fread(fid,N); 
      Re=Re'; %transpose to row vector 
      Im=fread(fid,N); 
      Im=Im'; %transpose to row vector 
      if size(Re)~=N 
       disp('Re is out of range'); 
       break; 
      end 
      if size(Im)~=N 
       disp('Im is out of range'); 
       break; 
      end 
      Re_dec=bi2de(Re); 
      Im_dec=bi2de(Im); 
      in = (Re_dec/65535) + (Im_dec*(1i)/65535); % unit circle 65535 
      double(in); 
      disp("IN:"); 
      disp(in); 
      out = qamdemod(in,64); 
      data_out = de2bi(out); 
      disp(data_out); 
      fprintf(fid_w,'%f\n',in); %write to sample file 
      if (feof(fid)) 
       disp('end of file'); 
       break; 
      end 
      if(toc(timerID) > RUNTIME) %# Get the elapsed time for the timer 
       disp('end of time'); 
       break; 
      end 
     end 
case 1 
     disp('randomaly') 
    otherwise 
     disp('error') 
end 

fclose('all'); %close all open files 



%  out = lteSymbolDemodulate(in,'64QAM'); 

답변

0

qamdemod이 correctrly 작동하지 않는 : 올바른 코드는 다음과 같습니다

% % Main Algorithm 
RUNTIME = input('How long you want to run in sec='); 
prompt = '0 - for sequentially. 1 - for randomaly ='; 
n = input(prompt); 
x=0; 
N=16; 
fid=fopen('rand.bin'); %need to check if file opened 
fid_w=fopen('samples.txt','w'); %write to file 
switch n 
    case 0 
     disp('sequentially'); 
     sequentially(fid,fid_w,RUNTIME); %call sequentially function 
    case 1 
     disp('randomaly'); 
     randomaly(fid,fid_w,RUNTIME); %call randomaly function 
    otherwise 
     disp('Error: Wrong select') 
end 
fclose('all'); %close all open files 
fid=fopen('samples.txt'); %need to check if file opened 
digest=entropy(fid); %Creating entropy 
disp(digest); 
fclose('all'); %close all open files 


    function sequentially(fid,fid_w,RUNTIME) 
N=16; %length of one sample 

timerID = tic; %# Start a clock and return the timer ID 
while true 
    %# Perform process 
    Re_bin=fread(fid,N); 
    if size(Re_bin')~=N 
     disp('Re is out of range'); 
     break; 
    end 
%  disp("Re_bin="); 
%  disp(Re_bin'); 
    Re=convert_to_number(Re_bin); 
    Im_bin=fread(fid,N); 
    if size(Im_bin')~=N 
     disp('Im is out of range'); 
     break; 
    end 
    Im=convert_to_number(Im_bin); 
    in=complex(Re,Im); 
%  disp("IN:"); 
%  disp(in); 
    out = conv_qam64(in); 
%  disp("OUT:"); 
%  disp(out); 
%%%%%%%% if want binary can use bin_out to convert %%%%%%%%% 
    %    bin_out=dec2bin(out); 
    %    disp("OUT BIN:"); 
    %    disp(bin_out); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    fprintf(fid_w,'%2.0f\n',out); %write to sample file 
    if (feof(fid)) 
%   disp('end of file'); 
     break; 
    end 
    if(toc(timerID) > RUNTIME) %# Get the elapsed time for the timer 
%   disp('end of time'); 
     break; 
    end 
end 
% fclose('all'); %close all open files