diff --git a/lab_3/lab_3.asv b/lab_3/lab_3.asv new file mode 100644 index 0000000..3a20e71 --- /dev/null +++ b/lab_3/lab_3.asv @@ -0,0 +1,10 @@ +trace1 = load("traces/2412mhz.mat", "iq"); +trace2 = load("traces/2432mhz.mat", "iq"); +trace3 = load("traces/2452mhz.mat", "iq"); +trace4 = load("traces/2472mhz.mat", "iq"); + +window = 512; +overlap = 64; +fft_precis + +spectrogram(trace1.iq, 512, 64, 2048, "psd", "yaxis"); \ No newline at end of file diff --git a/lab_3/lab_3.m b/lab_3/lab_3.m new file mode 100644 index 0000000..a29e188 --- /dev/null +++ b/lab_3/lab_3.m @@ -0,0 +1 @@ +task1; \ No newline at end of file diff --git a/lab_3/task1.asv b/lab_3/task1.asv new file mode 100644 index 0000000..c9e3a03 --- /dev/null +++ b/lab_3/task1.asv @@ -0,0 +1,116 @@ +trace1 = load("traces/2412mhz.mat", "iq"); +trace2 = load("traces/2432mhz.mat", "iq"); +trace3 = load("traces/2452mhz.mat", "iq"); +trace4 = load("traces/2472mhz.mat", "iq"); + +window = 512; +overlap = 64; +fft_precision = 2048; + +sample_rate = 20e6; % 20 MS/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; + +% 2. +% get all four plot values +[~,F1,T1,P1] = spectrogram(trace1.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); +[~,F2,T2,P2] = spectrogram(trace2.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); +[~,F3,T3,P3] = spectrogram(trace3.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); +[~,F4,T4,P4] = spectrogram(trace4.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); + +% begin calibrated color scale +P1_dB = 10 * log10(P1); +P2_dB = 10 * log10(P2); +P3_dB = 10 * log10(P3); +P4_dB = 10 * log10(P4); + +all_P_dB = [P1_dB(:); P2_dB(:); P3_dB(:); P4_dB(:)]; + +p_dB_min = min(all_P_dB) - 20; +p_dB_max = max(all_P_dB) + 20; +% end power calibrated color scale + +% 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; +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]); + +% 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); + +% 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; + +occupancies = [occupancy1 occupancy2 occupancy3 occupancy4]; +channels = [1 5 9 13]; + +[occupancy_max, max_idx] = max(occupancies); +busiest_channel = channels(max_idx); + +disp("Results:" + 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("--- Noise floor ---") +disp("Destinct:") +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" ) +disp(newline) +disp("Combined:") +disp("Channel all noise floor: " + sum([noise_floor1 noise_floor2, noise_floor3, noise_floor4]) / 4 + "dB") \ No newline at end of file diff --git a/lab_3/task1.m b/lab_3/task1.m new file mode 100644 index 0000000..77cdcdc --- /dev/null +++ b/lab_3/task1.m @@ -0,0 +1,126 @@ +trace1 = load("traces/2412mhz.mat", "iq"); +trace2 = load("traces/2432mhz.mat", "iq"); +trace3 = load("traces/2452mhz.mat", "iq"); +trace4 = load("traces/2472mhz.mat", "iq"); + +window = 512; +overlap = 64; +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; + +% 2. +% get all four plot values +[~,F1,T1,P1] = spectrogram(trace1.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); +[~,F2,T2,P2] = spectrogram(trace2.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); +[~,F3,T3,P3] = spectrogram(trace3.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); +[~,F4,T4,P4] = spectrogram(trace4.iq, window, overlap, fft_precision, sample_rate, "centered", "psd"); + +% begin calibrated color scale +P1_dB = 10 * log10(P1); +P2_dB = 10 * log10(P2); +P3_dB = 10 * log10(P3); +P4_dB = 10 * log10(P4); + +all_P_dB = [P1_dB(:); P2_dB(:); P3_dB(:); P4_dB(:)]; + +p_dB_min = min(all_P_dB) - 20; +p_dB_max = max(all_P_dB) + 20; +% end power calibrated color scale + +% 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; +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]); + +% 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); + +noise_floor_avg = sum([noise_floor1 noise_floor2, noise_floor3, noise_floor4]) / 4; + +% 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; + +occupancies = [occupancy1 occupancy2 occupancy3 occupancy4]; +channels = [1 5 9 13]; + +[occupancy_max, max_idx] = max(occupancies); +busiest_channel = channels(max_idx); + +disp("Results:" + 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("--- 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("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("Busiest channel: " + busiest_channel) \ No newline at end of file diff --git a/lab_3/traces/2412mhz.mat b/lab_3/traces/2412mhz.mat new file mode 100644 index 0000000..3c193f8 Binary files /dev/null and b/lab_3/traces/2412mhz.mat differ diff --git a/lab_3/traces/2432mhz.mat b/lab_3/traces/2432mhz.mat new file mode 100644 index 0000000..9f83802 Binary files /dev/null and b/lab_3/traces/2432mhz.mat differ diff --git a/lab_3/traces/2452mhz.mat b/lab_3/traces/2452mhz.mat new file mode 100644 index 0000000..83ed09c Binary files /dev/null and b/lab_3/traces/2452mhz.mat differ diff --git a/lab_3/traces/2472mhz.mat b/lab_3/traces/2472mhz.mat new file mode 100644 index 0000000..262b10b Binary files /dev/null and b/lab_3/traces/2472mhz.mat differ