| clear; clc; close all;
|
|
|
|
|
| filename = "D:/UAV_DETECT/drone-rf/AVATA2/VTSBW=10/pack1_0-1s.iq";
|
| fs = 100e6;
|
| duration_ms = 30;
|
| start_offset_s = 0.5;
|
|
|
|
|
| nfft = 1024;
|
| overlap = 512;
|
| win_len = 3072;
|
| window_func = hamming(win_len);
|
|
|
|
|
| clim_range = [-120, 50];
|
| cmap_steps = 256;
|
|
|
|
|
| fprintf('Đang đọc file %s ...\n', filename);
|
| fid = fopen(filename, 'rb');
|
| if fid == -1, error('Không tìm thấy file!'); end
|
|
|
|
|
| fseek(fid, floor(start_offset_s * fs * 2 * 4), 'bof');
|
|
|
|
|
| num_samples = floor(duration_ms/1000 * fs);
|
| raw_data = fread(fid, [2, num_samples], 'float32');
|
| fclose(fid);
|
|
|
|
|
| iq_raw = raw_data(1,:) + 1i*raw_data(2,:);
|
| iq_raw = iq_raw.'; % Chuyển thành cột
|
|
|
| % --- [QUAN TRỌNG] KIỂM TRA MỨC NĂNG LƯỢNG GỐC ---
|
| % Để augment phù hợp, ta cần biết nhiễu nền gốc mạnh cỡ nào
|
| current_power_db = 20*log10(mean(abs(iq_raw).^2));
|
| fprintf('Công suất trung bình file gốc:
|
|
|
|
|
|
|
| fprintf('Đang thêm nhiễu...\n');
|
|
|
|
|
| iq_awgn = iq_raw;
|
| iq_phase = iq_raw;
|
| iq_fading = iq_raw;
|
|
|
|
|
|
|
|
|
| target_noise_db = -30;
|
| noise_pwr = 10^(target_noise_db/20);
|
| noise_vec = sqrt(noise_pwr/2) * (randn(size(iq_raw)) + 1i*randn(size(iq_raw)));
|
| iq_awgn = iq_raw + noise_vec;
|
|
|
|
|
|
|
| phase_jitter = deg2rad(45 * randn(size(iq_raw)));
|
| iq_phase = iq_raw .* exp(1i * phase_jitter);
|
|
|
|
|
|
|
| taps = [1, 0.5*exp(1i*pi/3), 0.3*exp(1i*pi)];
|
| taps = taps / norm(taps);
|
| iq_fading = conv(iq_raw, taps, 'same');
|
|
|
|
|
| figure('Name', 'Test Augmentation trên Pack1.iq', 'Position', [100, 100, 1500, 400], 'Color', 'k');
|
|
|
|
|
| my_spectrogram(iq_raw, fs, window_func, overlap, nfft, clim_range, 1, '1. GỐC (Nền Xanh)');
|
| my_spectrogram(iq_awgn, fs, window_func, overlap, nfft, clim_range, 2, '2. Thêm AWGN (Nổi hạt)');
|
| my_spectrogram(iq_phase, fs, window_func, overlap, nfft, clim_range, 3, '3. Nhiễu Pha (Nhòe dọc)');
|
| my_spectrogram(iq_fading, fs, window_func, overlap, nfft, clim_range, 4, '4. Fading (Rãnh đen)');
|
|
|
|
|
| function my_spectrogram(iq, fs, win, ovrlp, nfft, clims, idx, title_str)
|
| subplot(1, 4, idx);
|
|
|
|
|
|
|
| [s, f, t] = spectrogram(iq, win, ovrlp, nfft, fs, 'centered');
|
|
|
|
|
| s_db = 20*log10(abs(s).^2 + 1e-12);
|
|
|
|
|
|
|
|
|
| imagesc(f/1e6, t*1000, s_db.');
|
|
|
| set(gca, 'YDir', 'normal'); % Time 0 ở dưới, hoặc 'reverse' nếu muốn 0 ở trên
|
| colormap(jet(256));
|
| clim(clims); % [-120, 50]
|
|
|
| title(title_str, 'Color', 'w');
|
| xlabel('MHz');
|
| if idx==1, ylabel('Time (ms)'); end
|
| set(gca, 'XColor', 'w', 'YColor', 'w', 'GridColor', 'w');
|
| grid on;
|
| axis tight;
|
| end |