seems finished
This commit is contained in:
+37
-119
@@ -1,7 +1,4 @@
|
||||
trace1 = load("traces/2412mhz.mat", "iq");
|
||||
trace2 = load("traces/2432mhz.mat", "iq");
|
||||
trace3 = load("traces/2452mhz.mat", "iq");
|
||||
trace4 = load("traces/2472mhz.mat", "iq");
|
||||
calculations_only = false;
|
||||
|
||||
window = 512;
|
||||
overlap = 64;
|
||||
@@ -9,81 +6,32 @@ fft_precision = 2048;
|
||||
|
||||
sample_rate = 20e6; % 20 MS/s -> 20e6 S/s
|
||||
|
||||
% 1.
|
||||
duration1 = length(trace1.iq) / sample_rate;
|
||||
duration2 = length(trace2.iq) / sample_rate;
|
||||
duration3 = length(trace3.iq) / sample_rate;
|
||||
duration4 = length(trace4.iq) / sample_rate;
|
||||
channels = [1 5 9 13];
|
||||
|
||||
% 2.
|
||||
% get all four plot values
|
||||
[S1,F1,T1] = spectrogram(trace1.iq, window, overlap, fft_precision, sample_rate, "centered");
|
||||
[S2,F2,T2] = spectrogram(trace2.iq, window, overlap, fft_precision, sample_rate, "centered");
|
||||
[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");
|
||||
res1 = analyzeTrace("traces/2412mhz.mat", channels(1), window, overlap, fft_precision, sample_rate);
|
||||
res2 = analyzeTrace("traces/2432mhz.mat", channels(2), window, overlap, fft_precision, sample_rate);
|
||||
res3 = analyzeTrace("traces/2452mhz.mat", channels(3), window, overlap, fft_precision, sample_rate);
|
||||
res4 = analyzeTrace("traces/2472mhz.mat", channels(4), window, overlap, fft_precision, sample_rate);
|
||||
|
||||
mag1 = abs(S1).^2;
|
||||
mag2 = abs(S2).^2;
|
||||
mag3 = abs(S3).^2;
|
||||
mag4 = abs(S4).^2;
|
||||
results = [res1 res2 res3 res4];
|
||||
|
||||
% begin calibrated color scale
|
||||
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(:)];
|
||||
% Calibrated color scale over all traces
|
||||
all_P_dB = [
|
||||
res1.P_dB(:)
|
||||
res2.P_dB(:)
|
||||
res3.P_dB(:)
|
||||
res4.P_dB(:)
|
||||
];
|
||||
|
||||
p_dB_min = min(all_P_dB);
|
||||
p_dB_max = max(all_P_dB);
|
||||
% end power calibrated color scale
|
||||
|
||||
% 2
|
||||
if ~calculations_only
|
||||
% plot all figures like example shows
|
||||
figure(1);
|
||||
imagesc(T1, F1, P1_dB);
|
||||
axis ij;
|
||||
xlabel("Time [s]");
|
||||
ylabel("Freq. [Hz]");
|
||||
title("Spectrogram Trace 1");
|
||||
cb = colorbar;
|
||||
ylabel(cb, "Power [dB]");
|
||||
clim([p_dB_min p_dB_max]);
|
||||
% xlim([0 0.05]);
|
||||
|
||||
figure(2);
|
||||
imagesc(T2, F2, P2_dB);
|
||||
axis ij;
|
||||
xlabel("Time [s]");
|
||||
ylabel("Freq. [Hz]");
|
||||
title("Spectrogram Trace 2");
|
||||
cb = colorbar;
|
||||
ylabel(cb, "Power [dB]");
|
||||
clim([p_dB_min p_dB_max]);
|
||||
% xlim([0 0.05]);
|
||||
|
||||
figure(3);
|
||||
imagesc(T3, F3, P3_dB);
|
||||
axis ij;
|
||||
xlabel("Time [s]");
|
||||
ylabel("Freq. [Hz]");
|
||||
title("Spectrogram Trace 3");
|
||||
cb = colorbar;
|
||||
ylabel(cb, "Power [dB]");
|
||||
clim([p_dB_min p_dB_max]);
|
||||
% xlim([0 0.05]);
|
||||
|
||||
figure(4);
|
||||
imagesc(T4, F4, P4_dB);
|
||||
axis ij; % flip so its like the example fig
|
||||
xlabel("Time [s]");
|
||||
ylabel("Freq. [Hz]");
|
||||
title("Spectrogram Trace 4");
|
||||
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
|
||||
plotSpectrogram(res1, 1, p_dB_min, p_dB_max);
|
||||
plotSpectrogram(res2, 2, p_dB_min, p_dB_max);
|
||||
plotSpectrogram(res3, 3, p_dB_min, p_dB_max);
|
||||
plotSpectrogram(res4, 4, p_dB_min, p_dB_max);
|
||||
end
|
||||
|
||||
%{
|
||||
@@ -115,41 +63,15 @@ 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
|
||||
res1.noise_floor_linear
|
||||
res2.noise_floor_linear
|
||||
res3.noise_floor_linear
|
||||
res4.noise_floor_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];
|
||||
occupancies = [res1.occupancy res2.occupancy res3.occupancy res4.occupancy];
|
||||
|
||||
[occupancy_max, max_idx] = max(occupancies);
|
||||
busiest_channel = channels(max_idx);
|
||||
@@ -158,30 +80,26 @@ if ~calculations_only
|
||||
disp("Results Task 1:" + newline)
|
||||
|
||||
disp("-- Trace duration ---")
|
||||
disp("Channel 1 duration: " + duration1 + "s")
|
||||
disp("Channel 5 duration: " + duration2 + "s")
|
||||
disp("Channel 9 duration: " + duration3 + "s")
|
||||
disp("Channel 13 duration: " + duration4 + "s" + newline)
|
||||
disp("Channel 1 duration: " + res1.duration + "s")
|
||||
disp("Channel 5 duration: " + res2.duration + "s")
|
||||
disp("Channel 9 duration: " + res3.duration + "s")
|
||||
disp("Channel 13 duration: " + res4.duration + "s" + newline)
|
||||
|
||||
disp("--- Noise floor ---")
|
||||
disp("Distinct:")
|
||||
disp("Channel 1 noise floor: " + noise_floor1 + "dB")
|
||||
disp("Channel 5 noise floor: " + noise_floor2 + "dB")
|
||||
disp("Channel 9 noise floor: " + noise_floor3 + "dB")
|
||||
disp("Channel 13 noise floor: " + noise_floor4 + "dB" + newline)
|
||||
disp("Channel 1 noise floor: " + res1.noise_floor + "dB")
|
||||
disp("Channel 5 noise floor: " + res2.noise_floor + "dB")
|
||||
disp("Channel 9 noise floor: " + res3.noise_floor + "dB")
|
||||
disp("Channel 13 noise floor: " + res4.noise_floor + "dB" + newline)
|
||||
|
||||
disp("Combined:")
|
||||
disp("Channel all noise floor: " + noise_floor_avg + "dB" + newline)
|
||||
|
||||
disp("-- Occupancy ---")
|
||||
disp("Channel 1 occupancy: " + occupancy1 + "%")
|
||||
disp("Channel 5 occupancy: " + occupancy2 + "%")
|
||||
disp("Channel 9 occupancy: " + occupancy3 + "%")
|
||||
disp("Channel 13 occupancy: " + occupancy4 + "%" + newline)
|
||||
disp("Channel 1 occupancy: " + res1.occupancy + "%")
|
||||
disp("Channel 5 occupancy: " + res2.occupancy + "%")
|
||||
disp("Channel 9 occupancy: " + res3.occupancy + "%")
|
||||
disp("Channel 13 occupancy: " + res4.occupancy + "%" + newline)
|
||||
|
||||
disp("Busiest channel: " + busiest_channel)
|
||||
disp("Busiest channel: " + busiest_channel + newline)
|
||||
end
|
||||
|
||||
function val = linearTodB(toConvert)
|
||||
val = 10 * log10(toConvert);
|
||||
end
|
||||
Reference in New Issue
Block a user