当前位置: 首页 > news >正文

降噪处理

%% ========== 读取对齐后的数据并进行降噪处理 ==========
clear; clc; close all;% 加载对齐后的数据
fprintf('正在加载对齐后的数据...\n');
load('对齐后的数据_85点.mat', 'aligned_data', 'time_axis');% 设置参数
datasets_to_process = 4:12;  % 要处理的数据集
target_length = 85;  % 时间点数% 设置变量名称(19个变量,已去掉第6和19个)
var_names = {'变量1', '变量2', '变量3', '变量4', '变量5', '变量7', ...'变量8', '变量9', '变量10', '变量11', '变量12', '变量13', '变量14', ...'变量15', '变量16', '变量17', '变量18', '变量20', '变量21'};% 降噪参数设置
% Savitzky-Golay滤波器参数
sg_order = 3;        % 多项式阶数(推荐2-4)
sg_framelen = 11;    % 窗口长度(必须为奇数,推荐9-15)% 也可以选择其他降噪方法,取消注释以下代码:
% method = 'savitzky-golay';  % Savitzky-Golay滤波
% method = 'moving-average';  % 移动平均
% method = 'wavelet';         % 小波降噪
method = 'savitzky-golay';  % 默认使用SG滤波% 存储降噪后的数据
denoised_data = cell(12, 1);%% ========== 对每个数据集进行降噪处理 ==========
fprintf('\n开始降噪处理...\n');
fprintf('使用方法: %s\n', method);for i = datasets_to_processdata = aligned_data{i};[n, m] = size(data);denoised = zeros(n, m);% 对每个变量分别降噪for col = 1:msignal = data(:, col);switch methodcase 'savitzky-golay'% Savitzky-Golay滤波器denoised(:, col) = sgolayfilt(signal, sg_order, sg_framelen);case 'moving-average'% 移动平均滤波window_size = 7;denoised(:, col) = movmean(signal, window_size);case 'wavelet'% 小波降噪[denoised(:, col), ~] = wdenoise(signal, 'Wavelet', 'sym4', ...'DenoisingMethod', 'Bayes');endenddenoised_data{i} = denoised;fprintf('数据集 %d 降噪完成\n', i);
endfprintf('\n所有数据集降噪处理完成!\n');%% ========== 可视化对比(降噪前后) ==========
fprintf('\n开始生成对比图像...\n');% 设置颜色
colors_original = lines(9);
colors_denoised = colors_original * 0.7;  % 降噪后的颜色稍暗% 为每个变量创建对比图
for col = 1:19% 创建新图形(包含两个子图)figure('Position', [100, 100, 1400, 600]);% 子图1:降噪前subplot(1, 2, 1);hold on;plot_idx = 1;for i = datasets_to_processdata = aligned_data{i};plot(time_axis, data(:, col), 'LineWidth', 1.5, ...'Color', colors_original(plot_idx, :), ...'DisplayName', ['数据集 ' num2str(i)]);plot_idx = plot_idx + 1;endxlabel('时间步 (1-85)', 'FontSize', 11, 'FontWeight', 'bold');ylabel('数值', 'FontSize', 11, 'FontWeight', 'bold');title(['降噪前 - ' var_names{col}], 'FontSize', 13, 'FontWeight', 'bold');legend('Location', 'best', 'FontSize', 9, 'NumColumns', 2);grid on;xlim([1, target_length]);hold off;% 子图2:降噪后subplot(1, 2, 2);hold on;plot_idx = 1;for i = datasets_to_processdata = denoised_data{i};plot(time_axis, data(:, col), 'LineWidth', 1.8, ...'Color', colors_denoised(plot_idx, :), ...'DisplayName', ['数据集 ' num2str(i)], ...'LineStyle', '-');plot_idx = plot_idx + 1;endxlabel('时间步 (1-85)', 'FontSize', 11, 'FontWeight', 'bold');ylabel('数值', 'FontSize', 11, 'FontWeight', 'bold');title(['降噪后 - ' var_names{col}], 'FontSize', 13, 'FontWeight', 'bold');legend('Location', 'best', 'FontSize', 9, 'NumColumns', 2);grid on;xlim([1, target_length]);hold off;% 添加总标题sgtitle(['变量 ' num2str(col) ': ' var_names{col} ' - 降噪对比'], ...'FontSize', 15, 'FontWeight', 'bold');% 保存图像saveas(gcf, ['降噪对比_变量' num2str(col) '.fig']);saveas(gcf, ['降噪对比_变量' num2str(col) '.png']);close(gcf);fprintf('已完成变量 %d/%d 的对比图\n', col, 19);
end%% ========== 创建单独的降噪后图像(与原格式一致) ==========
fprintf('\n开始生成降噪后的单独图像...\n');colors = lines(9);
for col = 1:19figure('Position', [100, 100, 1000, 600]);hold on;plot_idx = 1;for i = datasets_to_processdata = denoised_data{i};plot(time_axis, data(:, col), 'LineWidth', 1.8, ...'Color', colors(plot_idx, :), ...'DisplayName', ['数据集 ' num2str(i)], ...'Marker', 'none');plot_idx = plot_idx + 1;endxlabel('时间步 (1-85)', 'FontSize', 12, 'FontWeight', 'bold');ylabel('数值', 'FontSize', 12, 'FontWeight', 'bold');title(['变量 ' num2str(col) ': ' var_names{col} ' (降噪后)'], ...'FontSize', 14, 'FontWeight', 'bold');legend('Location', 'best', 'FontSize', 10, 'NumColumns', 2);grid on;xlim([1, target_length]);hold off;saveas(gcf, ['降噪后_变量' num2str(col) '.fig']);saveas(gcf, ['降噪后_变量' num2str(col) '.png']);close(gcf);fprintf('已完成变量 %d/%d 的降噪后图像\n', col, 19);
end%% ========== 保存降噪后的数据为.dat和.xlsx格式 ==========
fprintf('\n开始保存降噪后的数据文件...\n');for idx = 1:length(datasets_to_process)i = datasets_to_process(idx);data_to_save = denoised_data{i};% 生成文件名(06到14)file_number = sprintf('%02d', i + 2);dat_filename = [file_number '_te.dat'];xlsx_filename = [file_number '_te.xlsx'];% 保存为.dat文件(空格分隔)dlmwrite(dat_filename, data_to_save, 'delimiter', ' ', 'precision', '%.8f');fprintf('已保存: %s\n', dat_filename);% 保存为.xlsx文件col_headers = var_names;if exist('writematrix', 'file')% MATLAB R2019a及以上writecell([col_headers; num2cell(data_to_save)], xlsx_filename);else% 旧版本MATLABxlswrite(xlsx_filename, col_headers, 1, 'A1');xlswrite(xlsx_filename, data_to_save, 1, 'A2');endfprintf('已保存: %s\n', xlsx_filename);
end%% ========== 保存降噪后的完整数据 ==========
save('降噪后的数据_85点.mat', 'denoised_data', 'time_axis', 'method', ...'sg_order', 'sg_framelen');
fprintf('\n已保存: 降噪后的数据_85点.mat\n');%% ========== 生成降噪效果评估报告 ==========
fprintf('\n========== 降噪效果评估 ==========\n');% 计算信噪比改善
snr_improvement = zeros(length(datasets_to_process), 19);
smoothness_improvement = zeros(length(datasets_to_process), 19);for idx = 1:length(datasets_to_process)i = datasets_to_process(idx);original = aligned_data{i};denoised = denoised_data{i};for col = 1:19% 计算噪声水平(使用一阶差分的标准差)noise_original = std(diff(original(:, col)));noise_denoised = std(diff(denoised(:, col)));% 噪声减少百分比snr_improvement(idx, col) = (1 - noise_denoised/noise_original) * 100;% 平滑度改善(二阶差分)smooth_original = std(diff(original(:, col), 2));smooth_denoised = std(diff(denoised(:, col), 2));smoothness_improvement(idx, col) = (1 - smooth_denoised/smooth_original) * 100;end
endfprintf('平均噪声减少: %.2f%%\n', mean(snr_improvement(:)));
fprintf('平均平滑度改善: %.2f%%\n', mean(smoothness_improvement(:)));% 创建评估热图
figure('Position', [100, 100, 1200, 500]);
subplot(1, 2, 1);
imagesc(snr_improvement');
colorbar;
xlabel('数据集编号', 'FontSize', 11);
ylabel('变量编号', 'FontSize', 11);
title('噪声减少百分比 (%)', 'FontSize', 13, 'FontWeight', 'bold');
set(gca, 'XTick', 1:9, 'XTickLabel', datasets_to_process, 'YTick', 1:19);
colormap(jet);subplot(1, 2, 2);
imagesc(smoothness_improvement');
colorbar;
xlabel('数据集编号', 'FontSize', 11);
ylabel('变量编号', 'FontSize', 11);
title('平滑度改善百分比 (%)', 'FontSize', 13, 'FontWeight', 'bold');
set(gca, 'XTick', 1:9, 'XTickLabel', datasets_to_process, 'YTick', 1:19);
colormap(jet);sgtitle('降噪效果评估', 'FontSize', 15, 'FontWeight', 'bold');
saveas(gcf, '降噪效果评估.fig');
saveas(gcf, '降噪效果评估.png');
close(gcf);fprintf('\n========== 所有处理完成! ==========\n');
fprintf('总共生成:\n');
fprintf('  - %d 个对比图(.fig和.png)\n', 19);
fprintf('  - %d 个降噪后图像(.fig和.png)\n', 19);
fprintf('  - %d 个.dat文件\n', length(datasets_to_process));
fprintf('  - %d 个.xlsx文件\n', length(datasets_to_process));
fprintf('  - 1 个降噪后的数据.mat文件\n');
fprintf('  - 1 个降噪效果评估图\n');

 

http://www.zskr.cn/news/31452.html

相关文章:

  • 技术赋能智慧政务:政府呼叫中心的 AI 应用场景与实践难点
  • 12348 热线的标准化建设:服务流程、话术规范与质量评估体系
  • 2025 年纤维喷涂厂家最新推荐榜,聚焦企业技术实力与市场口碑深度解析
  • 吱吱企业即时通讯既可以聊天,又是企业办公协同的利器
  • 行业震动!罗永浩数字人电商直播首秀创下AI直播新标杆!
  • 2025修护/二硫化硒去屑/香氛/控油蓬松/ 洗发水推荐榜:MASIL 玛丝兰领衔,修护 / 去屑 / 控油蓬松品类的实力之选
  • 2025年知名的导热油电加热器实力厂家TOP推荐榜
  • 2025年知名的不锈钢雕塑最新TOP品牌厂家排行
  • 2025年口碑好的博物馆定制展柜实力厂家TOP推荐榜
  • 如何实现服务器文件自动同步,从而提升数据管理效率?
  • [java 21 scopevalue(preview) 特定作用域数据共享 v01]
  • 2025年可靠的酒店瓷砖厂家推荐及选购参考榜
  • outlook大附件怎么发送?主要有哪些有效的解决方案?
  • CSS 实现弧形卡片的 3 种方式
  • 2025 年北京律师事务所最新推荐榜,专业能力与服务口碑深度解析及优质机构盘点
  • 使用paddleocr提取PDF和图片文本
  • css3关键字
  • 第八周物理实验:用扭摆法测量物体的转动惯量
  • 2025 年蔬菜配送服务公司最新推荐榜,聚焦企业技术实力与市场口碑深度解析含深圳 / 宝安 / 东莞等区域优质服务商
  • 【每日一面】手写防抖函数
  • 模拟Ajax获取数据。表格显示, 带有分页功能,支持翻页,每页显示8行数据。响应式设计,适配不同屏幕尺寸
  • 2025年10月北京工装设计公司推荐榜:五强对比评测
  • 2025年10月北京工装设计公司排名:五家对比指南
  • 2025年10月防爆振动变送器厂家推荐:实力榜对比指南
  • 跨网文件交换怎么实现审批?从需求到落地的全解析!
  • MySQLDay5(基础篇完结)
  • HTML之addEventListener示例
  • 2025年10月北京工装设计公司推荐榜:筑垒领衔五强对比
  • 2025年10月山东AI公司推荐榜:优立德领衔五强对比
  • AI 超级智能体全栈方案阶段四:学术分析 AI 项目 RAG 落地指南:基于 Spring AI 的本地与阿里云知识库实践