72 lines
2.1 KiB
Matlab
72 lines
2.1 KiB
Matlab
function showEQNoiseSNR(eq_signal, noise_signal, options)
|
|
arguments
|
|
eq_signal
|
|
noise_signal
|
|
options.fs_tx
|
|
options.fs_rx
|
|
options.fignum (1,1) double = NaN % Default to NaN if not provided
|
|
options.displayname (1,:) char = '' % Default to an empty string if not provided
|
|
options.color = [0.2157 0.4941 0.7216];
|
|
end
|
|
|
|
% Determine the figure number to use or create a new figure
|
|
if isnan(options.fignum)
|
|
fig = figure; % Create a new figure and get its handle
|
|
else
|
|
fig = figure(options.fignum); % Use the specified figure number
|
|
end
|
|
|
|
if isa(eq_signal,'Signal')
|
|
options.fs_tx = eq_signal.fs;
|
|
eq_signal = eq_signal.signal;
|
|
end
|
|
if isa(noise_signal,'Signal')
|
|
options.fs_rx = noise_signal.fs;
|
|
noise_signal = noise_signal.signal;
|
|
end
|
|
|
|
|
|
hold on
|
|
ax = gca;
|
|
|
|
% N = numel(ax.Children);
|
|
N = sum(arrayfun(@(x) strcmp(x.LineStyle, '-'), ax.Children));
|
|
cmap = linspecer(8);
|
|
options.color = cmap(mod(N, size(cmap, 1)) + 1, :);
|
|
|
|
% Ensure the figure is ready before calling spectrum
|
|
title('SNR of received Signal')
|
|
|
|
fft_length = 2^(nextpow2(length(eq_signal))-7);
|
|
|
|
[s_lin,w] = pwelch(eq_signal,hanning(fft_length),fft_length/2,fft_length,options.fs_tx,"centered","psd","mean");
|
|
[n_lin,w] = pwelch(noise_signal,hanning(fft_length),fft_length/2,fft_length,options.fs_rx,"centered","psd","mean");
|
|
|
|
w = w.*1e-9;
|
|
snr_dbm = 10*log10(s_lin./n_lin);
|
|
|
|
% figure(231)
|
|
hold on
|
|
plot(w,snr_dbm,'DisplayName','SNR','LineWidth',0.5,'Color',options.color);
|
|
yline(mean(snr_dbm),'HandleVisibility','off','Color',options.color);
|
|
xlabel("Frequency in GHz");
|
|
|
|
edgetick = 2^(nextpow2(options.fs_tx*1e-9));
|
|
ticks = -edgetick:16:edgetick;
|
|
xticks(ticks);
|
|
|
|
[~,b]=min(abs((-edgetick:16:edgetick)-max(w)));
|
|
xlim([-ticks(b+1) ticks(b+1)]);
|
|
|
|
max_snr = ceil(max(snr_dbm)/10)*10;
|
|
min_snr = floor(min(snr_dbm)/10)*10;
|
|
ylim([min_snr,max_snr]);
|
|
yticks(-200:10:100);
|
|
|
|
grid on; grid minor;
|
|
legend('Interpreter','none');
|
|
title('Noise of soft decision signal (not MLSE)');
|
|
|
|
|
|
end
|