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

📄 eyescat.m

📁 数字通信第四版原书的例程
💻 M
字号:
function eyescat(x, Fd, Fs, offset, Dpoint)
%EYESCAT Produces eye-pattern diagram or scatter plot.
%       EYESCAT(X, Fd, Fs) produces an eye-pattern diagram with time range
%       from 0 to 1/Fd. The sample frequency for input signal X is 1/Fs. Fs
%       must be larger than Fd. Fs / Fd must be a positive integer.
%
%       EYESCAT(X, Fd, Fs, OFFSET) specifies the number of points offset in
%       the eye-pattern diagram x-axis arrangement. OFFSET must be an integer.
%       The actual time shift in the plot is OFFSET/Fs second.
%
%       EYESCAT(X, Fd, Fs, OFFSET, Dpoint) marks the decision point location
%       in the eye-pattern diagram. Dpoint must be an integer, which indicates
%       number of points in from time zero. The location is at time Dpoint/Fs.
%       Dpoint is independent of axis shifting location OFFSET. When Dpoint is
%       a string, this function produces a scatter plot. The valid string can
%       be Dpoitn = '.', or '*', 'x', 'o', '+', which specifies the plot
%       symbols. In scatter plots, OFFSET point is used as a decision point,
%       when decisions are made. When OFFSET=0, the decision point is at the
%       very end point of a digit transfer sequence.
%
%       See also: DMOD, DMODCE, MODMAP.

%       Wes Wang 10/5/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:57:35 $

if nargin < 3
    error('Not enough input varaible.');
end
if nargin < 4
    offset = 0;
end;
if nargin < 5
    Dpoint = 0;
end;

[r, c] = size(x);
if r * c == 0
    disp('Input variable X is empty.')
    return;
end;
if r == 1
    x = x(:);
end;

FsDFd = Fs/ Fd;
offset = rem(offset/FsDFd, 1) * FsDFd;
if offset < 0
    offset = rem(offset/FsDFd + 1, 1) * FsDFd;
end;

if max(max(abs(imag(x)))) > 0
    x = [real(x), imag(x)];
    x = x(:, [1:2:size(x, 2), 2:2:size(x, 2)]);
end;

if isstr(Dpoint)
    %scatter plot
    if offset <= 0
        offset = FsDFd;
    end;
    yy = x(offset : FsDFd : size(x, 1), :);
    if isempty(yy)
        disp('Matrix is empty after taking the sample point.')
        return;
    end;
    if length(Dpoint) ~= 1
        Dpoint = '.';
    end;
    [len_yy, wid_yy]=size(yy);
    if wid_yy == 1
        tmp=plot(yy, zeros(1,len_yy), Dpoint);
        if Dpoint == '.'
            set(tmp, 'MarkerSize', 10);
        end;
        tmp = 'In-phase plot';
        min_y = min(yy);
        max_y = max(yy);
        if max_y <= min_y
            max_y = min_y + sqrt(eps);
            min_y = min_y - sqrt(eps);
        end;
        axis([min_y, max_y, -1, 1])
    else
        tmp=plot(yy(:, 1:2:wid_yy), yy(:, 2:2:wid_yy), Dpoint);
        if Dpoint == '.'
            set(tmp, 'MarkerSize', 10);
        end;
        if wid_yy == 2
            tmp = 'In-Phase';
        elseif wid_yy == 4
            tmp = '1st pair: yellow; 2nd: meganta';
        elseif wid_yy == 6
            tmp = '1st pair:yellow; 2nd:meganta; 3rd:cyan';
        elseif wid_yy == 8
            tmp = '1st pair:yellow; 2nd:meganta; 3rd:cyan; 4th:red';
        elseif wid_yy == 10
            tmp = '1st pair:yellow; 2nd:meganta; 3rd:cyan; 4th:red; 5th:green';
        else
            tmp = '1st pair:yellow; 2nd:meganta; 3rd:cyan; 4th:red; 5th:green; 6th:blue';
        end;
        ylabel('Quadrature')
        min_y = min(min(yy));
        max_y = max(max(yy));
        if max_y <= min_y
            max_y = min_y + sqrt(eps);
            min_y = min_y - sqrt(eps);
        end;        
        axis([min_y, max_y, min_y, max_y])
        axis('equal')
    end;
    title('Scatter plot')
    xlabel(tmp)
else
    % eye-pattern plot.
    [len_x, wid_x]=size(x);
    t = rem([0 : (len_x-1)]/FsDFd, 1)'/Fd;

    if offset > 0
        tmp = find(t+eps*FsDFd < offset/Fs);
        t(tmp) = t(tmp) + 1/Fd;
    end;

    if Dpoint <= 0
        Dpoint = FsDFd;
    end;

    t_Dpoint = t(Dpoint);
    axx=[min(t), max(t)+1/Fs, min(min(x)), max(max(x))];
    [len_x, wid_x]  = size(x);

    if offset == 0
        offset = FsDFd;
    end;

    index = fliplr([1+offset : FsDFd : len_x]);
    NN = ones(1, wid_x) * NaN;
    for ii = 1 : length(index)
        i = index(ii);
        if i > 1
            x = [x(1:i, :); NN; x(i:size(x, 1), :)];
            t = [t(1:i-1); t(i-1)+1/Fs; NaN; t(i:size(t, 1))];
        end;
    end;

    if nargin >=5
        plot(t, x, [t_Dpoint, t_Dpoint], axx(3:4),'r')
        text(t_Dpoint, axx(4), 'DPoint')
    else
        plot(t, x)
    end;

    axis(axx);
    xlabel('time (second)');
    ylabel('amplitude');
    title('Eye-Pattern Diagram')
end

⌨️ 快捷键说明

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