- Communications Toolbox: https://in.mathworks.com/help/comm/index.html
- pskmod: https://in.mathworks.com/help/comm/ref/pskmod.html
- RaisedCosineTransmitFilter: https://in.mathworks.com/help/comm/ref/raisedcosinetransmitfilter.html
How to plot eye diagram of a given signal
48 views (last 30 days)
Show older comments
Mrinmoyee Mukherjee
on 26 May 2022
Answered: Idin Motedayen-Aval
on 27 May 2025
Hello,
I have a square signal with the following signal parameters
- No of bits (N) =100
- Bit duration= Tb=1/N=0.01
- Sampling rate=5 *N=500
- Sampling time= (1/sampling rate)=0.002
I used the following steps to generate generate the square signal
- Generated random 100 bits using n=randi([0 1],1,N).
- Plotted it to check the correctness
- Scaled it to 0-5
I have written the following code
N=100; %Normalised bit rate-This is the frequency of signal, 10 bits/sec
Tb=1/N; % bit duration,%bit duration of each bit=0.1sec
%Total time scale=10*0.1=1sec
srate=5*N;%sampling rate >=2*signal frequency
tsamp=1/srate;%Sampling time
n=randi([0 1],1,N); %Generate random bits=N
i=1;
t=0:tsamp:length(n); %Generating the time scale to plot the random bits
for j=1:length(t)
if t(j)<=i
mod1(j)=n(i);
else
i=i+1;
end
end
for m=1:length(t)
if mod1(m)==0
nn(m)=0; %If zero no power is transmitted
else
nn(m)=5; %If one some power is transmitted in mW
end
end
figure (1)
subplot(2,1,1);
plot(t,mod1,'linewidth',2);
title('Random Generated Bits');
xlabel('No. of Bits');
ylabel('Amplitude');
axis([0 N -2 2]);
grid on;
subplot(2,1,2);
plot(t,nn,'linewidth',2);
title('Intensity Modulated Signal');
xlabel('No.of Bits');
ylabel('Power in mWatts');
axis([0 N 0 6]);
grid on;
nn1=nn';
eyediagram(nn1,500); %500 are the number of samples in each bit
I wanted to ask
- If this is the right approach to plot the eye diagram
- Is there any way to limit the y-axis of eyediagram
Thank you
0 Comments
Accepted Answer
Moksh
on 22 Sep 2023
Hi Mrinmoyee,
I understand that you have generated a random square signal and scaled it from the range [0, 1] to [0, 5]. I assume that you have performed this scaling to visualize the modulated version of the signal.
You can try using the modulation and transition functions in the “Communications Toolbox” in MATLAB for better results and then try using the “eyediagram” function.
Here is an example code using the Communications Toolbox:
% Generating random data and modulating it using QPSK modulation
data = randi([0 3],1000,1);
modSig = pskmod(data,4,pi/4);
% Transmitting the modulated signal using a raised cosine filter
sps=4; % Number of output samples per symbol parameter
txfilter = comm.RaisedCosineTransmitFilter('OutputSamplesPerSymbol',sps);
txSig = txfilter(modSig);
% Plotting the eyediagram for the transmitted signal
h = eyediagram(txSig,2*sps);
% Use the appropriate realtionship within h and it's children plots to
% modify the y limits of required plot
h.Children(4).YLim = [-0.5 0.5]; % Default ylims = [-1 1]
For changing the limits of the eye diagram, you can store the plot’s handle and use the appropriate parent-child relationship to edit the required limits. Edited limits for the first plot are demonstrated in the code above.
For more information about the toolbox and the above used functions, please refer to the following documentation:
Hope this information helps!
Best Regards,
Moksh Aggarwal
More Answers (1)
Idin Motedayen-Aval
on 27 May 2025
The answer given by Moksh is correct. I just want to add a couple of points for others who may land on this page.
The eye diagram shown in OP's post is correct. It is the eye diagram of a real-valued square signal, so it looks "boxy". Also note that the x-axis units for eye diagram are "unit intervals" or "bit intervals" (not seconds or miliseconds, etc.).
The code provided by Moksh is doing something slightly different than the original code:
- Moksh is using QPSK modulation, so the modulate signal is complex-valued (the eye diagram shows real and imaginary parts, or I and Q channels).
- Moksh is lowpass filtering the signal (the raised cosine filter), so the signal level transition from -1 to +1 is smooth (it's not "boxy"). Thus the eye diagram looks more like a typical eye diagram with the "eye" shape.
Final point: to change the axis limits on the eye diagram, you can use the programatic approach shown by Moksh, or use the interactive tools on the plot window itself to zoom in/out. Third option is to go to the figure window, View menu -> Property Editor, and select the axes property you want to change (e.g., y-axis limits).
0 Comments
See Also
Categories
Find more on Test and Measurement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!