1
0
This repository has been archived on 2024-09-17. You can view files and clone it, but cannot push or open issues or pull requests.
SDI-TransmissionProcesses/plot_complex_sig.m

87 lines
2.3 KiB
Mathematica
Raw Normal View History

2023-09-27 06:23:10 +00:00
function plot_complex_sig(x,samples_per_symbol,Nmax,plot_style)
% plot_complex_sig(x) plots a one-dimensional complex signal as points
% in 3-D space : x-axis is the sample (time) axis, y-axis is the real part,
% and z-axis the imaginary part
%
% plot_complex_sig(x,samples_per_symbol) plots all samples in blue and
% one sample per symbol in red.
%
% plot_complex_sig(x,samples_per_symbol,Nmax) only plots the first Nmax
% samples.
%
% plot_complex_sig(x,samples_per_symbol,Nmax,'arrows') use arrows from
% (i_sample,0,0) instead of points to represent samples.
%
% version compatible with Simulink Version 7.3 (R2009a)
%% process function arguments and perform various tests on function
nargchk(1,3,nargin);
if nargin<2
samples_per_symbol = 1;
end
if (isstruct(x))
if(~isfield(x,'signals'))
error('unsupported data type')
else
if (x.signals.dimensions ~= 1)
error('does not support multidimensional signals')
else
vals = x.signals.values;
end
end
else % should be array
vals = x;
end
if nargin<3
Nmax=length(vals);
end
if nargin<4
plot_style = 'points';
end
if (~isnumeric(vals))
error('unsupported data type')
elseif (isreal(vals))
error('numbers are not complex')
end
if ((samples_per_symbol < 1) || ~(round(samples_per_symbol)==samples_per_symbol))
error('samples_per_symbol must be a strictly positive integer')
end
if ~strcmp(plot_style,'points') && ~strcmp(plot_style,'arrows')
error('possible values for plot plot_style are : "points" and "arrows"')
end
%% function implementation
sel=(1:Nmax)';
abs_max = max(abs(x(sel)));
if (samples_per_symbol==1)
if strcmp(plot_style,'points')
plot3(sel,real(vals(sel)),imag(vals(sel)),'.');
elseif strcmp(plot_style,'arrows')
quiver3(sel,zeros(size(sel)),zeros(size(sel)),zeros(size(sel)),real(vals(sel)),imag(vals(sel)),0);
end
else
plot3(sel,real(vals(sel)),imag(vals(sel)),'.');
hold on
sel= (1:samples_per_symbol:Nmax)';
if strcmp(plot_style,'points')
plot3(sel,real(vals(sel)),imag(vals(sel)),'.r');
elseif strcmp(plot_style,'arrows')
quiver3(sel,zeros(size(sel)),zeros(size(sel)),zeros(size(sel)),real(vals(sel)),imag(vals(sel)),0);
end
hold off
end
ylim([-abs_max,abs_max])
zlim([-abs_max,abs_max])
axis vis3d
grid on
xlabel('samples');
ylabel('real');
zlabel('imag');