| | clc; clear; close all;
|
| |
|
| |
|
| | function iq_new = iq_augment(iq_raw, type, param)
|
| |
|
| |
|
| |
|
| |
|
| | iq_new = iq_raw;
|
| |
|
| |
|
| |
|
| | peak_amp = quantile(abs(iq_raw), 0.999);
|
| | avg_amp = mean(abs(iq_raw));
|
| |
|
| | switch type
|
| | case 'awgn'
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | noise = (randn(size(iq_raw)) + 1j*randn(size(iq_raw)));
|
| |
|
| |
|
| | noise = noise / std(noise);
|
| |
|
| |
|
| |
|
| | iq_new = iq_raw + (peak_amp * param) * noise;
|
| |
|
| | case 'phase'
|
| |
|
| |
|
| |
|
| |
|
| | theta_noise = param * randn(size(iq_raw));
|
| |
|
| |
|
| | iq_new = iq_raw .* exp(1j * theta_noise);
|
| |
|
| | case 'fading'
|
| |
|
| |
|
| |
|
| | len = length(iq_raw);
|
| |
|
| |
|
| |
|
| | filter_len = round(len / param);
|
| | if filter_len < 3, filter_len = 3; end
|
| |
|
| |
|
| | fading_process = randn(1, len) + 1j*randn(1, len);
|
| |
|
| |
|
| | env = movmean(abs(fading_process), filter_len);
|
| |
|
| |
|
| | env = (env - min(env)) / (max(env) - min(env));
|
| |
|
| |
|
| | iq_new = iq_raw .* env;
|
| |
|
| | case 'burst'
|
| |
|
| |
|
| |
|
| |
|
| | mask = rand(size(iq_raw)) < param;
|
| |
|
| |
|
| | burst_val = (randn(size(iq_raw)) + 1j*randn(size(iq_raw))) * (peak_amp * 0.8);
|
| |
|
| | iq_new = iq_raw + mask .* burst_val;
|
| | end
|
| | end
|
| |
|
| | input_folder = "D:\uav_detect\drone-rf\DAUTELEVONANO";
|
| | output_root = "D:\uav_detect\drone-rf\DAUTELEVONANO\test";
|
| |
|
| |
|
| | GLOBAL_MIN_DB = -120;
|
| | GLOBAL_MAX_DB = 50;
|
| |
|
| |
|
| | fs = 100e6;
|
| | duration_ms = 30;
|
| | overlap_time = 0.5;
|
| |
|
| | nfft = 1024;
|
| | window = hamming(3072);
|
| | spec_overlap = nfft/2;
|
| | cmap = colormap(jet(256));
|
| | aug_types = {'original', 'awgn_light', 'awgn_heavy', 'phase_noise', 'fading'};
|
| |
|
| | samples_per_image = round(fs * (duration_ms / 1000));
|
| | step_size = round(samples_per_image * (1 - overlap_time));
|
| | bytes_back = (samples_per_image - step_size) * 8;
|
| |
|
| |
|
| |
|
| | file_pattern = fullfile(input_folder, 'pack1_*.iq');
|
| | file_list = dir(file_pattern);
|
| |
|
| | if isempty(file_list)
|
| | error('Không tìm thấy file .iq nào trong folder "%s"', input_folder);
|
| | end
|
| |
|
| |
|
| | if ~exist(output_root, 'dir')
|
| | mkdir(output_root);
|
| | end
|
| |
|
| | fprintf('Tìm thấy %d file trong "%s".\n', length(file_list), input_folder);
|
| | fprintf('Scale áp dụng: [%d dB, %d dB]\n', GLOBAL_MIN_DB, GLOBAL_MAX_DB);
|
| |
|
| |
|
| |
|
| | for k = 1:length(file_list)
|
| |
|
| |
|
| | current_filename = file_list(k).name;
|
| | full_path = fullfile(file_list(k).folder, current_filename);
|
| |
|
| |
|
| | sub_folder_name = sprintf('spectrogram%02d', k);
|
| | output_dir = fullfile(output_root, sub_folder_name);
|
| |
|
| | if ~exist(output_dir, 'dir')
|
| | mkdir(output_dir);
|
| | end
|
| |
|
| | fprintf('--> [%d/%d] Đang xử lý: %s >>> Lưu vào: %s\n', ...
|
| | k, length(file_list), current_filename, sub_folder_name);
|
| |
|
| |
|
| | fid = fopen(full_path, 'r');
|
| | if fid == -1
|
| | warning('Lỗi mở file %s', full_path);
|
| | continue;
|
| | end
|
| |
|
| | fseek(fid, 0, 'eof'); file_size = ftell(fid); fseek(fid, 0, 'bof');
|
| | img_count = 0;
|
| |
|
| |
|
| | while ~feof(fid)
|
| | img_count = img_count + 1;
|
| |
|
| | raw_data = fread(fid, [2, samples_per_image], 'float32');
|
| | if size(raw_data, 2) < samples_per_image
|
| | break;
|
| | end
|
| |
|
| |
|
| | iq_chunk = complex(raw_data(1,:), raw_data(2,:));
|
| |
|
| |
|
| | aug_types = {'awgn_light', 'awgn_heavy', 'phase', 'fading', 'burst'};
|
| |
|
| | for a = 2
|
| | type_key = aug_types{a};
|
| |
|
| | switch type_key
|
| | case 'awgn_light'
|
| |
|
| | iq_processed = iq_augment(iq_chunk, 'awgn', 0.05);
|
| |
|
| | case 'awgn_heavy'
|
| |
|
| | iq_processed = iq_augment(iq_chunk, 'awgn', 5);
|
| |
|
| | case 'phase'
|
| |
|
| | iq_processed = iq_augment(iq_chunk, 'phase', 0.8);
|
| |
|
| | case 'fading'
|
| |
|
| | iq_processed = iq_augment(iq_chunk, 'fading', 200);
|
| |
|
| | case 'burst'
|
| |
|
| | iq_processed = iq_augment(iq_chunk, 'burst', 0.03);
|
| | end
|
| |
|
| |
|
| |
|
| | [s, ~, ~] = spectrogram(iq_chunk, window, spec_overlap, nfft, fs, 'centered');
|
| | mag = 20*log10(abs(s) + eps);
|
| |
|
| |
|
| | mag(mag < GLOBAL_MIN_DB) = GLOBAL_MIN_DB;
|
| | mag(mag > GLOBAL_MAX_DB) = GLOBAL_MAX_DB;
|
| | mag_norm = (mag - GLOBAL_MIN_DB) / (GLOBAL_MAX_DB - GLOBAL_MIN_DB);
|
| |
|
| |
|
| | img_rgb = ind2rgb(gray2ind(mag_norm, 256), cmap);
|
| |
|
| |
|
| | fname = sprintf('seq%02d_%05d_%s.jpg', k, img_count, type_key);
|
| | imwrite(img_rgb, fullfile(output_dir, fname), 'Quality', 95);
|
| | end
|
| |
|
| | fseek(fid, -bytes_back, 'cof');
|
| | end
|
| |
|
| | fclose(fid);
|
| | end
|
| |
|
| | fprintf('\n=== HOÀN TẤT! KIỂM TRA FOLDER "%s" ===\n', output_root); |