64QAM解调 - 始终获得相同的输出

时间:2017-12-17 14:19:00

标签: matlab

我想从文件中读取位,然后将它们转换为复数double。每个数字是32位(16 Re和16 Im)。然后我想使用qamdemod来获得每个复数的6位并将这些位保存在新的文本文件中。 我做了那个程序,但我总是得到与输出010011 = 50相同的数字 这是该计划:

    % % 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');

1 个答案:

答案 0 :(得分:0)

qamdemod没有正确地工作:正确的代码是:

    % % 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
相关问题