This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
CMS/4.Test/matlab.m
2024-11-19 17:19:21 +08:00

48 lines
1.4 KiB
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

% 从文件读取数据
data = load('E:\Documents\工作资料\01项目资料\03.风电机组三合一采集器项目开发\01.机舱采集器\03.测试文件\ven\Data.txt'); % 假设数据存储在名为data.txt的文件中
% 提取采样率和持续时间
fs = 60000; % 采样率为60KHz
duration = 10; % 持续时间为10秒
% 创建时间向量
t = linspace(0, duration, length(data));
% 绘制时域波形图
figure;
subplot(2,1,1);
plot(t, data);
title('时域波形');
xlabel('时间(秒)');
ylabel('幅值');
ylim([min(data)-1, max(data)+1]); % 空出一定空间保证图形美观
% 计算并绘制频域谱
N = length(data);
f = (-N/2:N/2-1)*fs/N;
f_data = fftshift(abs(fft(data))/N);
subplot(2,1,2);
plot(f, f_data);
title('频域谱');
xlabel('频率Hz');
ylabel('幅度');
% 设置频率图的x轴范围
xlim([0, fs/2]);
% 计算指标
rms_value = sqrt(mean(data.^2));
peak_value = max(data);
peak_to_peak = max(data) - min(data);
kurtosis_value = kurtosis(data);
crest_factor = max(data) / sqrt(mean(data.^2));
skewness_value = skewness(data);
% 显示指标计算结果
disp(['有效值RMS', num2str(rms_value)]);
disp(['峰值Peak', num2str(peak_value)]);
disp(['峰峰值Peak-to-Peak', num2str(peak_to_peak)]);
disp(['峭度Kurtosis', num2str(kurtosis_value)]);
disp(['峰值因数Crest Factor', num2str(crest_factor)]);
disp(['歪度Skewness', num2str(skewness_value)]);