Files
Zcu111ResmReceiver/utilities/aux/plotspectrum.m

59 lines
1.2 KiB
Matlab

function h = plotspectrum(type, centers, bandwidth, color, unit, varargin)
for n = 1:numel(centers)
center = centers(n);
switch type
case 'sym'
x = [-1, -1, 0, 1, 1] * (bandwidth/2) + center;
y = [ 0, 0.5, 1, 0.5, 0];
case 'asym'
x = [-1, -1, 1, 1] * (bandwidth/2) + center;
y = [0, 0.5, 1, 0];
case 'asymflip'
x = [-1, -1, 1, 1] * (bandwidth/2) + center;
y = [0, 1, 0.5, 0];
otherwise
error('Invalid type.');
end
switch unit
case 'Hz'
factor = 1;
case 'kHz'
factor = 1e3;
case 'MHz'
factor = 1e6;
case 'GHz'
factor = 1e9;
otherwise
error('Invalid unit');
end
tmp = patch(x/factor, y, color, varargin{:});
if n == 1
h = tmp;
else
h = [h, tmp]; %#ok<AGROW>
end
end
switch unit
case 'Hz'
xlabel('Frequency (Hz)', 'FontWeight', 'bold')
case 'kHz'
xlabel('Frequency (kHz)', 'FontWeight', 'bold')
case 'MHz'
xlabel('Frequency (MHz)', 'FontWeight', 'bold')
case 'GHz'
xlabel('Frequency (GHz)', 'FontWeight', 'bold')
otherwise
error('Invalid unit');
end
a = gca;
a.XAxis.FontWeight = 'bold';
end