| clear; clc; close all;
|
|
|
|
|
| filename = "D:/uav_detect/drone-rf/AVATA2/VTSBW=10/pack1_0-1s.iq";
|
| output_dir = "D:/uav_detect/drone-rf/v20";
|
| fs = 100e6;
|
| duration_ms = 30;
|
| overlap_time = 0.5;
|
|
|
| nfft = 1024;
|
| window = hamming(3072);
|
| spec_overlap = nfft/2;
|
| cmap = colormap(jet(256));
|
|
|
|
|
|
|
| fprintf('Đang đọc file %s ...\n', filename);
|
| fid = fopen(filename, 'rb');
|
| if fid == -1, error('File not found'); end
|
|
|
| num_samples = floor(duration_ms/1000 * fs);
|
| raw = fread(fid, [2, num_samples], 'float32');
|
| fclose(fid);
|
| iq_raw = raw(1,:) + 1i*raw(2,:); iq_raw = iq_raw.';
|
|
|
| %% 3. AUGMENTATION (Dùng Class IQAugmenterPro đã gửi trước đó)
|
| % Khởi tạo
|
|
|
|
|
|
|
|
|
| % --- TẠO CÁC CASE TEST ĐỊNH LƯỢNG ---
|
| function mag_norm = robust_normalize(mag_db)
|
| % prctile(data, p) trả về giá trị phân vị thứ p
|
| min_val = prctile(mag_db(:), 10);
|
|
|
| max_val = min_val + 80;
|
|
|
| mag_clip = mag_db;
|
| mag_clip(mag_clip < min_val) = min_val;
|
| mag_clip(mag_clip > max_val) = max_val;
|
|
|
| mag_norm = (mag_clip - min_val) / (max_val - min_val);
|
| end
|
| % Case 1: Gốc (Chưa làm gì) -> Kỳ vọng: Nền Xanh Lá
|
| noise_levels = [0, 3, 5.0,10];
|
|
|
| for i = 1:length(noise_levels)
|
| level = noise_levels(i);
|
|
|
| % 1. Gọi hàm thêm nhiễu
|
| iq_processed = add_noise_floor(iq_raw, level);
|
|
|
| % 2. Tạo Spectrogram
|
| [s, ~, ~] = spectrogram(iq_processed, window, spec_overlap, nfft, fs, 'centered');
|
| mag = 20*log10(abs(s) + eps);
|
|
|
| % 3. Chuẩn hóa theo thang đo của bạn (Min -120, Max 50)
|
| mag_norm = robust_normalize(mag);
|
| % 4. Tô đen biên & DC (Giữ nguyên code cũ của bạn đoạn này)
|
| img_rgb = ind2rgb(gray2ind(mag_norm, 256), jet(256));
|
|
|
| % --- Masking biên (Code cũ) ---
|
| % img_rgb(1:margin, :, :) = 0; ... v.v
|
|
|
| % 5. Lưu ảnh
|
| % Đặt tên file gợi nhớ để biết mức nhiễu
|
| % Ví dụ: seq01_00001_noise0.jpg, seq01_00001_noise1.5.jpg
|
| fname = sprintf('seq
|
| imwrite(img_rgb, fullfile(output_dir, fname), 'Quality', 95);
|
| end |