| |
|
| | clc; clear; close all;
|
| |
|
| |
|
| | input_folder = "D:\uav_detect\drone-rf\MAVIC3PRO\VTSBW=20";
|
| | output_root = "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));
|
| |
|
| |
|
| | 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, 'pack2_*.iq');
|
| | file_list = dir(file_pattern);
|
| | function mag_norm = robust_normalize(mag_db)
|
| |
|
| | 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
|
| | 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);
|
| |
|
| |
|
| |
|
| |
|
| | 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+1);
|
| | 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,:));
|
| | [s, ~, ~] = spectrogram(iq_chunk, window, spec_overlap, nfft, fs, 'centered');
|
| | mag = 20*log10(abs(s) + eps);
|
| |
|
| | [num_freq_bins, ~] = size(mag);
|
| |
|
| |
|
| |
|
| | edge_percent = 0.05;
|
| |
|
| |
|
| |
|
| | mag_norm = robust_normalize(mag);
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | img_rgb = ind2rgb(gray2ind(mag_norm, 256), cmap);
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | fname = sprintf('seq%02d_%05d.jpg', k, img_count);
|
| | imwrite(img_rgb, fullfile(output_dir, fname), 'Quality', 95);
|
| |
|
| |
|
| | fseek(fid, -bytes_back, 'cof');
|
| |
|
| | end
|
| |
|
| | fclose(fid);
|
| | end
|
| |
|
| | fprintf('\n=== HOÀN TẤT! KIỂM TRA FOLDER "%s" ===\n', output_root);
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | |