⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eqber_graphics.m

📁 Adaptive Filter. This script shows the BER performance of several types of equalizers in a static ch
💻 M
📖 第 1 页 / 共 2 页
字号:
    case 'update'        [h, nBits, PreD] = deal(varargin{:});        % Compute data to be plotted        HEq = fftshift(10*log10(pwelch(PreD)));        HEq = HEq - max(HEq);                % Get appropriate figure handle and update data        fig = get(get(h, 'Parent'), 'Parent');        set(0, 'CurrentFigure', fig);        set(fig, 'Visible', 'on');        set(h, 'YData', HEq);        drawnow;end% ------------------------------------------------------------------------------function [hErrs, hText1, hText2] = plot_bursterrors(plotType, varargin)% PLOT_BURSTERRORS - Plot burst error performance for multiple equalizers.%   Inputs:%      plotType     - 'init' or 'update'%      eqType       - 'linear', 'dfe', or 'mlse'%      mlseType     - 'ideal' or 'imperfect'%      firstErrPlot - flag indicating whether the current plot is the first %                     burst error performance plot for the current equalizer%      refMsg       - transmitted signal, used to find bit errors%      testMsg      - received signal, used to find bit errors%      nBits        - number of bits in a data block%      hErrs        - line handle to a bar plot showing burst error performance%      hText1       - first text handle for the burst error plot%      hText2       - second text handle for the burst error plot%   Outputs:%      hErrs        - line handle to a bar plot showing burst error performance%      hText1       - first text handle for the burst error plot%      hText2       - second text handle for the burst error plot                               switch plotType    case 'init'                % On initialization, set up all the figure properties.  On update,        % simply update the plotted data.        figure; hErrs = bar(1,1);   % initialize with dummy data        figErrs = get(get(hErrs, 'Parent'), 'Parent');        hText1 = text(1.7, 1.15, '1');  % initialize with dummy data        hText2 = text(0.5, 1.05, '2');  % initialize with dummy data        set(figErrs, 'Visible', 'off');            case 'update'                [eqType, mlseType, firstErrPlot, refMsg, testMsg, nBits, ...            hErrs, hText1, hText2] = deal(varargin{:});        if (firstErrPlot)            % Set parameters based on equalizer settings            if (strcmpi(eqType, 'linear'))                errTitle   = 'Burst Error Performance - Linear Equalizer';                color      = 'k';            elseif (strcmpi(eqType, 'dfe'))                errTitle   = 'Burst Error Performance - DFE';                color      = 'r';            elseif (strcmpi(eqType, 'mlse'))                if (strcmpi(mlseType, 'ideal'))                    errTitle = 'Burst Error Performance - Ideal MLSE';                    color    = 'g';                elseif (strcmpi(mlseType, 'imperfect'))                    errTitle = 'Burst Error Performance - Imperfect MLSE';                    color    = 'm';                end            end        end                % Find the distribution of intervals between errors for this frame of        % data. Categorize into intervals of 1, 2, 3, 4, 5, and greater than 5.        % For all error intervals greater than 5, clip the value to 6.        errs       = double(xor(refMsg, testMsg));  % actual bit errors        errIntDist = diff(find(errs==1));           % intervals between errors        errIntDist(find(errIntDist>5)) = 6;     % Clip all vals>5 to a val of 6        numErrs    = sum(errs);                 % number of errors in this frame        % Find the number of error intervals from 1 to 6        for i = 1:6            errIntPct(i) = length(errIntDist(errIntDist==i));        end                if (~isempty(errIntDist))  % for all data blocks with errors            errIntPct = errIntPct / length(errIntDist);  % normalize so that                                                         % the elements sum to 1                        % Find the average interval between errors for randomly distributed            % errors, and reformat for plotting purposes            avgInt = length(errs) / numErrs;              avgInt = num2str(avgInt);            avgInt = avgInt(1:min(4,length(avgInt)));            if (strcmpi(avgInt(end), '.')) avgInt(end) = ''; end;                        if (firstErrPlot)                close(get(get(hErrs, 'Parent'), 'Parent'))  % close last fig                figure; hErrs = bar(errIntPct, color);  % new bar plot                axErrs  = get(hErrs, 'Parent');                figErrs = get(axErrs, 'Parent');                errPos  = figposition([69 45 30 36]);                set(figErrs, 'Position', errPos);                xlabel('Interval between Consecutive Errors (bits)');                ylabel('Fraction of Occurrences');                set(axErrs, 'XTickLabel', reshape([' 1 2 3 4 5>5'],2,6)');                axis([0 7 0 1.2]);                title(errTitle);                hText1 = text(1.7, 1.15, ...                    [num2str(numErrs) ' errors in this frame']);                hText2 = text(0.5, 1.05, ...                    ['Avg random error interval = ' avgInt ' bits']);                set(hText1, 'FontWeight', 'bold');                set(hText2, 'FontWeight', 'bold');            else                set(hErrs,  'YData',  errIntPct);                set(hText1, 'String', ...                    [num2str(numErrs) ' errors in this frame']);                set(hText2, 'String', ...                    ['Avg random error interval = ' avgInt ' bits']);            end        end        drawnow;end% ------------------------------------------------------------------------------function [hBER, hLegend, legendString] = plot_simber(varargin)% PLOT_SIMBER - Plot the BER performance for the current equalizer%   Inputs:%      eqType       - 'linear', 'dfe', or 'mlse'%      mlseType     - 'ideal' or 'imperfect'%      firstBlk     - flag indicating whether the current data block is the%                     first one being processed for the current equalizer type%      EbNoIdx      - index over the range of EbNo%      EbNo         - vector of Eb/No values%      hBER         - line handle to the current line in the BER plot%      hLegend      - vector of handles corresponding to visible legend entries %                     in the BER plot%      legendString - cell array of legend strings for the BER plot%   Outputs:%      hBER         - line handle to the current line in the BER plot%      hLegend      - vector of handles corresponding to visible legend entries %                     in the BER plot%      legendString - cell array of legend strings for the BER plot[eqType, mlseType, firstBlk, EbNoIdx, EbNo, BER, hBER, hLegend, ...    legendString] = deal(varargin{:});if (firstBlk && EbNoIdx==1)    % Set parameters based on equalizer setting    if (strcmpi(eqType, 'linear'))        legendLine = 'Linear Equalizer';        color      = [0 0 0];    elseif (strcmpi(eqType, 'dfe'))        legendLine = 'DFE             ';        color      = [1 0 0];    elseif (strcmpi(eqType, 'mlse'))        if (strcmpi(mlseType, 'ideal'))            legendLine = 'Ideal MLSE      ';            color      = [0 0.8 0];        else            legendLine = 'Imperfect MLSE  ';            color      = [1 0 1];        end    end    % Set current figure to the BER figure and begin to plot a new curve.    % Update the legend for this new case.  Do not include handles to curve fits    % in the vector of legend handles.    set(0, 'CurrentFigure', get(get(hBER, 'Parent'), 'Parent'));    hBER = semilogy(EbNo(1), BER(1), '*');    set(hBER, 'Color', color);    hLegend = [hLegend hBER];    legendString = [legendString; legendLine];    legend(hLegend, legendString, 'Location', 'SouthWest');else    % Simply update the plotted data    set(0, 'CurrentFigure', get(get(hBER, 'Parent'), 'Parent'));    set(hBER, 'XData', EbNo(1:EbNoIdx), ...              'YData', BER(1:EbNoIdx));enddrawnow;% ------------------------------------------------------------------------------function hFit = plot_fitber(varargin)% PLOT_FITBER - Plot a curve fit to the current BER points.%   Inputs:%      eqType       - 'linear', 'dfe', or 'mlse'%      mlseType     - 'ideal' or 'imperfect'%      hFit         - line handle to the current BER curve fit%      EbNoIdx      - index over the range of EbNo%      EbNo         - vector of Eb/No values%      BER          - vector of BER values corresponding to the Eb/No values%   Outputs:%      hFit         - line handle to the current BER curve fit[eqType, mlseType, hFit, EbNoIdx, EbNo, BER] = deal(varargin{:});if (EbNoIdx == 4)  % first plot    % Set parameters based on equalizer setting    if (strcmpi(eqType, 'linear'))        color = [0 0 0];    elseif (strcmpi(eqType, 'dfe'))        color = [1 0 0];    elseif (strcmpi(eqType, 'mlse'))        if (strcmpi(mlseType, 'ideal'))            color   = [0 0.5 0];        elseif (strcmpi(mlseType, 'imperfect'))            color   = [1 0 1];        end    end    fitEbNo = [EbNo(1) : 0.1 : EbNo(EbNoIdx)];  % vector of Eb/No values over                                                % which to plot    fitBER = berfit(EbNo(1:EbNoIdx), BER(1:EbNoIdx), fitEbNo, [], 'exp+const');    hFit = semilogy(fitEbNo, fitBER);    set(hFit, 'Color', color);    elseif (EbNoIdx > 4)    fitEbNo = [EbNo(1) : 0.1 : EbNo(EbNoIdx)];    fitBER = berfit(EbNo(1:EbNoIdx), BER(1:EbNoIdx), fitEbNo, [], 'exp+const');    set(hFit, 'XData', fitEbNo, 'YData', fitBER);enddrawnow;% ------------------------------------------------------------------------------function hEstPlot = plot_chnlest(plotType, varargin)% PLOT_CHNLEST - Plot a channel estimate for the current block of data.%   Inputs:%      plotType     - 'init' or 'update'%      chnlEst      - impulse response of estimated channel%      chnlLen      - length of estimated channel impulse response%      excessEst    - the difference between the length of the estimated channel%                     impulse response and the actual channel impulse response%      nBits        - number of bits in a data block%      firstEstPlot - flag indicating whether the current channel estimate plot %                     is the first one%      hEstPlot     - line handle to the channel estimate plot%   Outputs:%      hEstPlot     - line handle to the channel estimate plot[chnlEst, chnlLen, excessEst, nBits, firstEstPlot, hEstPlot] = ...    deal(varargin{:});% For the first plot, set up all the figure properties and make the figure% invisible.  Thereafter, simply make the figure visible and update the plotted% data.switch plotType    case 'init'        freq = [-nBits/2 : 4 : (nBits/2)-1]' * (2*pi/nBits);        figure; hEstPlot = plot(freq, freq); % plot dummy data        figEstPlot = get(get(hEstPlot, 'Parent'), 'Parent');        pos = figposition([66.6 5 33 33]);        set(figEstPlot, 'Position', pos);  % for multiple screen resolutions        axis([-3.14 3.14 -40 10]);        title('Estimated Channel Frequency Response');        xlabel('Normalized Frequency (rad/s)');        ylabel('Normalized Magnitude Squared (dB)');        set(hEstPlot, 'Color', [1 0 1]);        set(figEstPlot, 'Visible', 'off');            case 'update'        % Process the time domain channel estimate to determine the frequency        % response.  Ensure that the data is complex, for the pwelch function.        chnlPlot = [chnlEst(1:chnlLen+excessEst); ...            zeros(nBits-(chnlLen+excessEst),1)];        if (isreal(chnlPlot))            chnlPlot(1) = real(chnlPlot(1)) + i*eps;        end        HEstPlot = fftshift(10*log10(pwelch(chnlPlot)));        HEstPlot = HEstPlot - max(HEstPlot);        set(hEstPlot, 'YData', HEstPlot);        if (firstEstPlot)            set(get(get(hEstPlot, 'Parent'), 'Parent'), 'Visible', 'on');        end        drawnow;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -