📄 eqber_graphics.m
字号:
function varargout = eqber_graphics(plotType, varargin)% EQBER_GRAPHICS - Generate and update plots for the eqber demo.% [hBER, hLegend, legendString, hLinSpec, hDfeSpec, hErrs, ...% hText1, hText2, hFit, hEstPlot] = ...% eqber_graphics('init', chnl, EbNo, idealBER, nBits)% generates handles to be used later in the simulation run.% Inputs:% chnl - channel impulse response% EbNo - vector of Eb/No values% idealBER - ideal BPSK BER values corresponding to the EbNo vector% nBits - number of bits in a data block% Outputs:% hBER - handle to a 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% hLinSpec - line handle for the spectrum plot of the linearly % equalized signal% hDfeSpec - line handle for the spectrum plot of the DFE equalized% signal% 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% hFit - line handle for fitted BER curves% hEstPlot - line handle for the channel estimate plot%%% hSpecPlot = eqber_graphics('sigspec', eqType, hSpecPlot, nBits, PreD)% updates the spectrum plots for adaptively equalized signals.% Inputs:% eqType - 'linear', 'dfe', or 'mlse'% hSpecPlot - line handle for the spectrum plot% nBits - number of bits in a data block% PreD - equalized, predetected signal% Outputs:% hSpecPlot - line handle for the spectrum plot%%% [hErrs, hText1, hText2] = eqber_graphics('bursterrors', eqType, ...% mlseType, firstErrPlot, refMsg, testMsg, nBits, hErrs, hText1, hText2)% updates the burst error performance plots.% Inputs:% 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%%% [hBER, hLegend, legendString] = eqber_graphics('simber', eqType, ...% mlseType, firstBlk, EbNoIdx, EbNo, BER, hBER, hLegend, legendString)% updates the BER plot.% 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%%% hFit = eqber_graphics('fitber', eqType, mlseType, hFit, EbNoIdx, EbNo, BER)% updates the curve fit to the simulated BER data.% 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%%% hEstPlot = eqber_graphics('chnlest', chnlEst, chnlLen, excessEst, ...% nBits, firstEstPlot, hEstPlot) updates the channel estimate plot for the% MLSE algorithm.% Inputs:% 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% Copyright 1996-2004 The MathWorks, Inc.% $Revision: 1.1.4.1 $ $Date: 2004/06/30 23:03:09 $% ------------------------------------------------------------------------------switch plotType case 'init' [chnl, EbNo, idealBER, nBits] = deal(varargin{:}); % Plot the unequalized channel plot_uneqchnl(chnl); % Plot the ideal BPSK BER curve [hBER, hLegend, legendString] = plot_idealber(EbNo, idealBER); % Initialize a figure to display the linearly equalized signal spectrum hLinSpec = plot_sigspec('init', 'linear', nBits); % Initialize a figure to display the DFE equalized signal spectrum hDfeSpec = plot_sigspec('init', 'dfe', nBits); % Initialize a figure to display the burst error performance of the % linear equalizer, DFE equalizer, MLSE equalizer with an ideal channel % estimate, and an MLSE equalizer with an imperfect channel estimate [hErrs, hText1, hText2] = plot_bursterrors('init', [], [], []); % Initialize a dummy line handle for BER curve fitting set(0, 'CurrentFigure', get(get(hBER, 'Parent'), 'Parent')); hFit = semilogy(0, 1); % Initialize a figure to display the frequency response of the imperfect % channel estimate hEstPlot = plot_chnlest('init', nBits); varargout{1} = hBER; varargout{2} = hLegend; varargout{3} = legendString; varargout{4} = hLinSpec; varargout{5} = hDfeSpec; varargout{6} = hErrs; varargout{7} = hText1; varargout{8} = hText2; varargout{9} = hFit; varargout{10} = hEstPlot; case 'sigspec' hSpecPlot = plot_sigspec('update', varargin{:}); varargout{1} = hSpecPlot; case 'bursterrors' [hErrs, hText1, hText2] = plot_bursterrors('update', varargin{:}); varargout{1} = hErrs; varargout{2} = hText1; varargout{3} = hText2; case 'simber' [hBER, hLegend, legendString] = plot_simber(varargin{:}); varargout{1} = hBER; varargout{2} = hLegend; varargout{3} = legendString; case 'fitber' hFit = plot_fitber(varargin{:}); varargout{1} = hFit; case 'chnlest' hEstPlot = plot_chnlest('update', varargin{:}); varargout{1} = hEstPlot;end% ------------------------------------------------------------------------------function plot_uneqchnl(chnl);% PLOT_UNEQCHNL - Plot the frequency response of the unequalized channel% Inputs:% chnl - channel impulse response% Generate a normalized frequency vector from -pi to piFFTlen = 2048;freq = [-FFTlen/2 : (FFTlen/2)-1]' * (2*pi/FFTlen);% Generate the normalized frequency responsechnlLen = length(chnl);FFTchnl = [chnl; zeros(FFTlen - chnlLen, 1)];magFFT = abs(fft(FFTchnl));plot(freq, 20*log10(fftshift(magFFT/max(magFFT))));axis([-3.14 3.14 -40 10]);pos = figposition([0 45 33 33]); % for multiple screen resolutionsset(gcf, 'Position', pos);title('Unequalized Channel Frequency Response');xlabel('Normalized Frequency (rad/s)');ylabel('Normalized Magnitude Squared (dB)');drawnow;% ------------------------------------------------------------------------------function [hBER, hLegend, legendString] = plot_idealber(EbNo, idealBER)% PLOT_IDEALBER - Plot the BER for ideal BPSK% Inputs:% EbNo - vector of Eb/No values% idealBER - ideal BER values corresponding to the EbNo values% 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 plotfigure; pos = figposition([33.3 45 36 36]); figBER = gcf;set(figBER, 'Position', pos); % for multiple screen resolutionsaxBER = axes;set(axBER, 'YScale' , 'log', ... 'XLim' , [0 16], ... 'YLim' , [1e-6 1], ... 'XTick' , [0:2:16], ... 'XGrid' , 'on', ... 'YGrid' , 'on', ... 'YMinorGrid', 'off', ... 'Title' , text('String','Equalizer BER Comparison'), ... 'XLabel' , text('String', 'Eb/No (dB)'), ... 'YLabel' , text('String', 'BER'));hold on; hBER = semilogy(EbNo, idealBER);legendString = 'Ideal BPSK ';hLegend = hBER;legend(hLegend, legendString, 'Location', 'SouthWest');drawnow;% ------------------------------------------------------------------------------function h = plot_sigspec(plotType, eqType, varargin)% PLOT_SIGSPEC - Initialize or update a plot of an equalized signal spectrum% Inputs:% plotType - 'init' or 'update' % eqType - 'linear' or 'dfe'% h - line handle to the signal spectrum plot% nBits - number of bits in a data block% PreD - equalized, predetected signal% Outputs:% h - line handle to the signal spectrum plot % On initialization, set up all the figure properties and make the figure% invisible. On update, simply make the figure visible and reset the values of% the plotted data.switch plotType case 'init' % Generate a frequency vector nBits = varargin{1}; freq = [-nBits/2 : 4 : (nBits/2)-1]' * (2*pi/nBits); figure; h = plot(freq, freq); % initialize with dummy data fig = get(get(h, 'Parent'), 'Parent'); set(fig, 'Visible', 'off'); axis([-3.14 3.14 -40 10]); xlabel('Normalized Frequency (rad/s)'); ylabel('Normalized Power Spectrum (dB)'); if (strcmpi(eqType, 'linear')) pos = figposition([0 5 33 33]); figTitle = 'Linearly Equalized Signal Power Spectrum'; color = [0 0 0]; elseif (strcmpi(eqType, 'dfe')) pos = figposition([33.3 5 33 33]); figTitle = 'Decision Feedback Equalized Signal Power Spectrum'; color = [1 0 0]; end title(figTitle); set(fig, 'Position', pos); % for multiple screen resolutions set(h, 'Color', color);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -