Robochameleon  v1.0
plotSignal.m
Go to the documentation of this file.
1 
2 function plotSignal(y,Nss,Fs)
3 colors
4 
5 if (Nss>1)
6  %% Processing
7  % Obtain data and plot limits
8  y=y(:);
9  ylim_time = 20*[-var(y) var(y)] + mean(y);
10  ylim_time = 1.1*[min(y) max(y)];
11  % Calculate sampling point
12  srx = y(1:end-rem(length(y),Nss));
13  y_opt = zeros(1,Nss);
14  for k=1:Nss
15  y_opt(k) = sum( abs( srx(k:Nss:end) ).^2);
16  end
17  [nul,idx] = max(y_opt);
18  % Get the symbols
19  srx = srx(idx:Nss:end);
20  srx = srx(:).'*modnorm(srx, 'avpow' ,1);
21 
22  %% Initialize plot
23  figure
24  set(gcf, 'Units', 'pixels')
25  if isreal(y)
26  ratioW = 0.4;
27  ratioH = 0.8;
28  else
29  ratioW = 0.4;
30  ratioH = 0.9;
31  end
32  scrsz = get(0,'ScreenSize');
33  %set(gcf,'Position',[scrsz(3)/2 scrsz(4)/2-200 width*50 height*50])
34  set(gcf,'OuterPosition',[1 scrsz(4)*(1-ratioH) scrsz(3)*ratioW scrsz(4)*ratioH ])
35 
36  %% Plot spectrum
37  if isreal(y)
38  subplot(3,1,1)
39  else
40  subplot(4,3,[1 2 3])
41  end
42  [ f, spectrum ] = spectra(y, Fs, 0);
43  s = 10*log10(spectrum.*conj(spectrum)*1e3);
44  sm = smooth(s,length(s)/100);
45  adj = max(s)-max(sm);
46  BW = find(sm>max(sm(10:end))-3);
47  BW = f(BW(end));
48  patchline(f*1e-9, s, 'edgecolor', blue, 'edgealpha',0.05 )
49  hold on
50  plot(f*1e-9, sm, 'color', red, 'LineWidth',2)
51  gridxy(BW*1e-9, (max(sm)-3), 'LineStyle', '--', 'color', [1 1 1]./1.5)
52  hold off
53  ylim([mean(s) max(s(100:end))])
54  xlim([0 Fs/2*1e-9])
55  grid on
56  ylabel('dBm')
57  xlabel('GHz')
58  title(['Rs = ' num2str(Fs/Nss*1e-9, '%.0f') ' Gbaud | Fs = ' num2str(Fs*1e-9, '%.0f') ' GSa/s | BW = ' num2str(BW*1e-9, '%.2f') ' GHz' ])
59  set(gca, 'LooseInset', get(gca, 'TightInset'));
60 
61  %% Plot Eyes
62  % Cropping
63  nsymb = length(y)/Nss;
64  NumberOfStoredTraces=2^11;
65  NumberOfEyes = 2;
66  if (nsymb < NumberOfStoredTraces)
67  NumberOfStoredTraces = nsymb;
68  end
69  y_eye=y(1:Nss*NumberOfStoredTraces);
70  if isreal(y)
71  subplot(3,1,2)
72  else
73  heye(1) = subplot(4,3,4);
74  title('I')
75  end
76  y_eyeI = reshape(real(y_eye),Nss*NumberOfEyes,length(y_eye)/Nss/NumberOfEyes);
77  t_eye=(0:(Nss*NumberOfEyes-1))/Fs*1e12;
78  for e=1:size(y_eyeI,2)
79  patchline(t_eye, y_eyeI(:,e), 'edgecolor', blue, 'edgealpha',0.1 )
80  end
81  hold on
82  hold on
83  y_optPlot = (y_opt-mean(y_opt));
84  y_optPlot = y_optPlot/max(y_optPlot)*std(y_eye);
85  y_optPlot = y_optPlot + mean(y_eye);
86  y_optPlot = repmat(y_optPlot(:),NumberOfEyes,1);
87  plot(t_eye, y_optPlot, '--', 'color', red)
88  gridxy((Nss+idx-1)/Fs*1e12, [], 'LineStyle', '--', 'color', [1 1 1]./1.5)
89  xlabel('Time (ps)')
90  ylabel('a.u.')
91  ylim(ylim_time)
92  xlim([0 t_eye(end)])
93 
94  if ~isreal(y)
95  heye(2) = subplot(4,3,6);
96  title('Q')
97  y_eyeQ = reshape(imag(y_eye),Nss*NumberOfEyes,length(y_eye)/Nss/NumberOfEyes);
98  for e=1:size(y_eyeQ,2)
99  patchline(t_eye, y_eyeQ(:,e), 'edgecolor', blue, 'edgealpha',0.1 )
100  end
101  hold on
102  gridxy((Nss+idx-1)/Fs*1e12, [], 'LineStyle', '--', 'color', [1 1 1]./1.5)
103  ylim([-1 1])
104  xlim([0 t_eye(end)])
105  xlabel('Time (ps)')
106  linkaxes(heye, 'x');
107  end
108 
109  %% Plot constellation
110  if ~isreal(y)
111  subplot(4,3,5);
112  plot(real(srx), imag(srx), '.', 'color', blue, 'MarkerSize',3);
113  hold on
114  % Plot clusters centroids
115  xlim([-1.5 1.5])
116  ylim([-1.5 1.5])
117  set(gca, 'LooseInset', get(gca, 'TightInset'));
118  end
119 
120  %% Plot time domain signals
121  if isreal(y)
122  subplot(3,1,3)
123  plot(real(y),'color', blue);
124  ylabel('a.u.')
125  xlabel('Samples')
126  ylim(ylim_time)
127  xlim([1 length(y)])
128  else
129  htime(1) = subplot(4,3,[7 8 9]);
130  plot(real(y),'color', blue)
131  ylabel('a.u.')
132  xlabel('Samples')
133  ylim([-1 1])
134  xlim([1 length(y)])
135 
136  htime(2) = subplot(4,3,[10 11 12]);
137  plot(imag(y),'color', blue)
138  ylabel('a.u.')
139  xlabel('Samples')
140  ylim(ylim_time)
141  xlim([1 length(y)])
142  linkaxes(htime, 'x');
143  end
144 elseif Nss==1
145  srx = y(:).'*modnorm(y, 'avpow' ,1);
146  %% Initialize plot
147  figure
148  set(gcf, 'Units', 'pixels')
149  if isreal(y)
150  ratioW = 0.6;
151  ratioH = 0.4;
152  else
153  ratioW = 0.6;
154  ratioH = 0.4;
155  end
156  scrsz = get(0,'ScreenSize');
157  %set(gcf,'Position',[scrsz(3)/2 scrsz(4)/2-200 width*50 height*50])
158  set(gcf,'OuterPosition',[1 scrsz(4)*(1-ratioH) scrsz(3)*ratioW scrsz(4)*ratioH ])
159 
160  %% plot Constellation
161  if ~isreal(y)
162  subplot(2,2,[1 3])
163  plot(real(srx), imag(srx), '.', 'color', blue, 'MarkerSize',4);
164  end
165 
166  %% plot Time signals
167  if isreal(y)
168  plot(srx,'color', blue)
169  else
170  subplot(2,2,2)
171  plot(real(srx),'color', blue)
172  ylim(ylim_time)
173  xlim([1 length(srx)])
174  ylabel('a.u.')
175  subplot(2,2,4)
176  plot(real(srx),'color', blue)
177  ylim(ylim_time)
178  xlim([1 length(srx)])
179  ylabel('a.u.')
180  xlabel('Samples')
181  end
182 else
183  disp('Wrong Nss')
184 end
185 end
function plotSignal(in y, in Nss, in Fs)
Plot signal_interface using options based on signal properties.
function spectra(in y, in Fs, in plotS)
Returns the single-sided amplitude spectrum and plots (optional)