Task 2 should be finished

This commit is contained in:
ti_mo
2026-05-22 19:16:08 +02:00
parent 2fa2bf7f9a
commit 0df0c5da43
4 changed files with 591 additions and 41 deletions
+70 -14
View File
@@ -22,15 +22,19 @@ duration4 = length(trace4.iq) / sample_rate;
[S3,F3,T3] = spectrogram(trace3.iq, window, overlap, fft_precision, sample_rate, "centered");
[S4,F4,T4] = spectrogram(trace4.iq, window, overlap, fft_precision, sample_rate, "centered");
mag1 = abs(S1).^2;
mag2 = abs(S2).^2;
mag3 = abs(S3).^2;
mag4 = abs(S4).^2;
% begin calibrated color scale
P1_dB = 20 * log10(abs(S1).^2);
P2_dB = 20 * log10(abs(S2).^2);
P3_dB = 20 * log10(abs(S3).^2);
P4_dB = 20 * log10(abs(S4).^2);
P1_dB = 10 * log10(mag1);
P2_dB = 10 * log10(mag2);
P3_dB = 10 * log10(mag3);
P4_dB = 10 * log10(mag4);
all_P_dB = [P1_dB(:); P2_dB(:); P3_dB(:); P4_dB(:)];
% -50 to +50 so its like the example fig
p_dB_min = min(all_P_dB);
p_dB_max = max(all_P_dB);
% end power calibrated color scale
@@ -46,7 +50,7 @@ if ~calculations_only
cb = colorbar;
ylabel(cb, "Power [dB]");
clim([p_dB_min p_dB_max]);
xlim([0 0.05]);
% xlim([0 0.05]);
figure(2);
imagesc(T2, F2, P2_dB);
@@ -57,7 +61,7 @@ if ~calculations_only
cb = colorbar;
ylabel(cb, "Power [dB]");
clim([p_dB_min p_dB_max]);
xlim([0 0.05]);
% xlim([0 0.05]);
figure(3);
imagesc(T3, F3, P3_dB);
@@ -68,7 +72,7 @@ if ~calculations_only
cb = colorbar;
ylabel(cb, "Power [dB]");
clim([p_dB_min p_dB_max]);
xlim([0 0.05]);
% xlim([0 0.05]);
figure(4);
imagesc(T4, F4, P4_dB);
@@ -79,22 +83,70 @@ if ~calculations_only
cb = colorbar;
ylabel(cb, "Power [dB]");
clim([p_dB_min p_dB_max]);
xlim([0 0.05]); % reduce view so its like the example fig
% xlim([0 0.05]); % reduce view so its like the example fig
end
%{
% 3.
noise_floor1 = prctile(P1_dB(:), 10);
noise_floor2 = prctile(P2_dB(:), 10);
noise_floor3 = prctile(P3_dB(:), 10);
noise_floor4 = prctile(P4_dB(:), 10);
% taking the 10th percentile on the linear values or the logarithmic ones
% should not make any difference
noise_floor_avg = sum([noise_floor1 noise_floor2, noise_floor3, noise_floor4]) / 4;
noise_floor1_linear = prctile(mag1(:), 10);
noise_floor2_linear = prctile(mag2(:), 10);
noise_floor3_linear = prctile(mag3(:), 10);
noise_floor4_linear = prctile(mag4(:), 10);
noise_floor1 = linearTodB(noise_floor1_linear);
noise_floor2 = linearTodB(noise_floor2_linear);
noise_floor3 = linearTodB(noise_floor3_linear);
noise_floor4 = linearTodB(noise_floor4_linear);
% this is false -> linear avg on logarithmic values
% noise_floor_avg = sum([noise_floor1 noise_floor2, noise_floor3, noise_floor4]) / 4;
noise_floor_avg = linearTodB(mean([noise_floor1_linear noise_floor2_linear noise_floor3_linear noise_floor4_linear]));
% 4.
occupancy1 = sum(P1_dB(:) > noise_floor1 + 10) / numel(P1_dB) * 100;
occupancy2 = sum(P2_dB(:) > noise_floor2 + 10) / numel(P2_dB) * 100;
occupancy3 = sum(P3_dB(:) > noise_floor3 + 10) / numel(P3_dB) * 100;
occupancy4 = sum(P4_dB(:) > noise_floor4 + 10) / numel(P4_dB) * 100;
%}
% 3.
% Sum all frequency bins per time slot to obtain total channel power.
channel_power1_linear = sum(mag1, 1);
channel_power2_linear = sum(mag2, 1);
channel_power3_linear = sum(mag3, 1);
channel_power4_linear = sum(mag4, 1);
channel_power1_dB = linearTodB(channel_power1_linear);
channel_power2_dB = linearTodB(channel_power2_linear);
channel_power3_dB = linearTodB(channel_power3_linear);
channel_power4_dB = linearTodB(channel_power4_linear);
noise_floor1_linear = prctile(channel_power1_linear, 10);
noise_floor2_linear = prctile(channel_power2_linear, 10);
noise_floor3_linear = prctile(channel_power3_linear, 10);
noise_floor4_linear = prctile(channel_power4_linear, 10);
noise_floor1 = linearTodB(noise_floor1_linear);
noise_floor2 = linearTodB(noise_floor2_linear);
noise_floor3 = linearTodB(noise_floor3_linear);
noise_floor4 = linearTodB(noise_floor4_linear);
noise_floor_avg = linearTodB(mean([
noise_floor1_linear
noise_floor2_linear
noise_floor3_linear
noise_floor4_linear
]));
% 4.
occupancy1 = sum(channel_power1_dB > noise_floor1 + 10) / numel(channel_power1_dB) * 100;
occupancy2 = sum(channel_power2_dB > noise_floor2 + 10) / numel(channel_power2_dB) * 100;
occupancy3 = sum(channel_power3_dB > noise_floor3 + 10) / numel(channel_power3_dB) * 100;
occupancy4 = sum(channel_power4_dB > noise_floor4 + 10) / numel(channel_power4_dB) * 100;
occupancies = [occupancy1 occupancy2 occupancy3 occupancy4];
channels = [1 5 9 13];
@@ -128,4 +180,8 @@ if ~calculations_only
disp("Channel 13 occupancy: " + occupancy4 + "%" + newline)
disp("Busiest channel: " + busiest_channel)
end
function val = linearTodB(toConvert)
val = 10 * log10(toConvert);
end