2017-12-17 11 views
0

ファイルからビットを読み取り、それらを複素数倍に変換したいとします。各数値は32ビット(16 Reと16 Im)です。次に、qamdemodを使用して1つの複素数あたり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 
関連する問題