clc
clear
duration = 1; % 数据持续时间(秒)
samplingRate =1000; % 采样率(Hz)
% 生成时间轴
t = 0:1/samplingRate:duration-1/samplingRate;
% 生成低频信号(40Hz)也目标信号
lowFrequency = 40;
lowSignal = sin(2*pi*lowFrequency*t);
% 生成高频信号(200Hz)噪声
highFrequency = 200;
highSignal = sin(2*pi*highFrequency*t);
% 生成包含高频和低频信号的总信号
totalSignal = lowSignal + highSignal;
% 绘制信号
subplot(3,1,1)
plot(t,lowSignal)
xlabel('Time (s)');
ylabel('Amplitude');
title('低频信号');
subplot(3,1,2)
plot(t,highSignal)
xlabel('Time (s)');
ylabel('Amplitude');
title('高频噪声信号');
subplot(3,1,3)
plot(t, totalSignal);
xlabel('Time (s)');
ylabel('Amplitude');
title('低频和高频的混合信号');
%设计Butterworth滤波器
fs=250;
n=4;
Wn = [1/(fs/2) 40/(fs/2)];%保留频率为1-40
[a,b]=butter(n,Wn);
sF=filter(a,b,totalSignal);
denoised_signal = medfilt1(sF,4);
subplot(4,1,1)
plot(lowSignal)
xlabel('Time (s)');
ylabel('Amplitude');
title('目标信号');
subplot(4,1,2)
plot(t, totalSignal);
xlabel('Time (s)');
ylabel('Amplitude');
title('低频和高频的混合信号');
subplot(4,1,3)
plot(sF)
xlabel('Time (s)');
ylabel('Amplitude');
title('巴特沃斯滤波器降噪信号');
subplot(4,1,4)
plot(denoised_signal)
xlabel('Time (s)');
ylabel('Amplitude');
title('巴特沃斯滤波器降噪加中值滤波信号');
这是一篇关于信号处理的文章。使用了巴特沃斯滤波器和中值滤波降噪。仿真噪声含有高频和低频的混合信号,频率使用短时傅里叶变换估计频率,最后使用巴特沃斯滤波器降噪,得到低频信号。但信号不平滑,使用了一个中值滤波使信号更加平滑。有对比图。可自行调整对应频率范围,实现降噪,得到对应频率的信号。
欢迎评论,欢迎指正。