| Communications Toolbox | ![]() |
The code below illustrates the use of the eye diagram for finding the best decision point. It maps a random digital signal to a 16-QAM waveform, then uses a raised cosine filter to simulate a noisy transmission channel. Several commands manipulate the filtered data to isolate its steady-state behavior. Then the eyediagram command produces an eye diagram from the resulting signal.
% Define the M-ary number and sampling rates. M = 16; Fd = 1; Fs = 10; Pd = 100; % Number of points in the calculation msg_d = randint(Pd,1,M); % Random integers in the range [0,M-1] % Modulate using square QAM. msg_a = qammod(msg_d,M); % Assume the channel is equivalent to a raised cosine filter. delay = 3; % Delay of the raised cosine filter rcv = rcosflt(msg_a,Fd,Fs,'fir/normal',.5,delay); % Truncate the output of rcosflt to remove response tails. N = Fs/Fd; propdelay = delay .* N + 1; % Propagation delay of filter rcv1 = rcv(propdelay:end-(propdelay-1),:); % Truncated version % Plot the eye diagram of the resulting signal sampled and % displayed with no offset. offset1 = 0; h1 = eyediagram(rcv1,N,1/Fd,offset1); set(h1,'Name','Eye Diagram Displayed with No Offset');
Notice that a vertical line down the center of the diagram would cross the "eye" at its most widely opened point, as in the image below.

If the eyediagram command used a different offset value, then a vertical line down the center of the diagram would not cross the eye at the most widely opened point. The code and image to illustrate this are below.
offset2 = 2; h2 = eyediagram(rcv1,N,1/Fd,offset2,'r-'); set(h2,'Name','Eye Diagram Displayed with Offset=2');

As an additional example of using the eyediagram function, the commands below display the eye diagram with no offset, but based on data that is sampled with an offset of two samples. This sampling offset simulates errors in timing that result from being two samples away from perfect synchronization.
h3 = eyediagram(rcv1(1+offset2:end,:),N,1/Fd,0); set(h3,'Name','Eye Diagram Sampled with Offset=2');
| Eye Diagrams | Scatter Plots | ![]() |
© 1994-2005 The MathWorks, Inc.