一种非平稳信号滤波方法:基于短时傅里叶变换STFT的维纳滤波(MATLAB)


clear all
clc
close all
% Synthetized signal
% Sampling frequency 1 kHz
% Chirp: start at 50 Hz and cross 450 Hz at 10 s with strong Gussian background noise (SNR -18 dB)
fs = 1000;
T = 10;
t=0:1/fs:T;
r=chirp(t,50,T,450);
L = length(r);
wnoise = 6 .* randn(size(r));
x = wnoise + r;

figure
spectrogram(r,256,250,256,1E3);
view(-45,65)
colormap bone
title('Reference signal')


figure
subplot(1,2,1)
spectrogram(x,256,250,256,1E3);
view(-45,65)
colormap bone
title('Noisy signal')

Lw = 256;
[xest,B,Nblocks] = ADwienerFilt(x,r,Lw);

subplot(1,2,2)
spectrogram(xest,256,250,256,1E3);
view(-45,65)
colormap bone
title('Estimated signal')
function [xest,W,Nblocks] = ADwienerFilt(x,r,Lw)
%
% Wiener filter based on STFT
%   This function takes as inputs a noisy signal, x, and a reference signal, r,
%   in order to compute a bank of linear filters that provides an estimate of y
%   from x. This kind of Wiener filter based on short-time Fourier
%   transform so it can deal with non-stationary signals.
%
%   Note 1: window length (Lw) must be even
%   Note 2: overlap is fixed at 50%
%   Note 3: the filtered signal can be shortened
%
% INPUTS
% x = noisy signal
% r = reference signal
% Nw = window length
% Nblocks = total number of segments
%
% OUTPUTS
% xest = estimated signal
% W = matrix of Wiener filters

% window length must be even
if mod(Lw,2)~=0
    Lw = Lw - 1;
    disp('Window length must be an even number. Lw has been changed accordingly.')
end

L = length(x);
win = hanning(Lw);
overlap = Lw/2;
Nblocks = floor((L / (Lw/2) ) - 1);

Sxx = zeros(Nblocks,Lw);
Sxr = zeros(Nblocks,Lw);
W  = zeros(Nblocks,Lw);
xest = zeros(size(r));
ind = 1:Lw;

for j = 1:Nblocks
    
    temp = zeros(size(r));
        
    X = 1/Lw .* fft(x(ind));
    R = 1/Lw .* fft(r(ind));
    Sxx(j,:) = X .* conj(X);
    Sxr(j,:) = X .* conj(R);
    W(j,:) = Sxr(j,:) ./ Sxx(j,:);
        
    temp(ind) = Lw/2 * ifft(W(j,:) .* X);  
    xest = xest + temp;
        
    ind = ind + Lw/2;
    
end

ind = ind - Lw/2;

if L ~= ind(end)
    disp('Note that the length of the recovered signal has been shortened!')
end

xest((ind(end)+1):L)=[];

图片

图片

擅长领域:现代信号处理,机器学习,深度学习,数字孪生,时间序列分析,设备缺陷检测、设备异常检测、设备智能故障诊断与健康管理PHM等。
知乎学术咨询:
https://www.zhihu.com/consult/people/792359672131756032?isMe=1

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 20:28:04       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 20:28:04       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 20:28:04       45 阅读
  4. Python语言-面向对象

    2024-07-10 20:28:04       55 阅读

热门阅读

  1. Unity3D中使用并行的Job完成筛选类任务详解

    2024-07-10 20:28:04       20 阅读
  2. Hash算法和MD5容易受到冲突攻击的原因

    2024-07-10 20:28:04       21 阅读
  3. 将ldd命令移植到32位Arm开发板

    2024-07-10 20:28:04       20 阅读
  4. Linux C++ 047-设计模式之责任链模式

    2024-07-10 20:28:04       19 阅读
  5. 常用Docker命令

    2024-07-10 20:28:04       21 阅读
  6. Postman与世界相连:集成第三方服务的全面指南

    2024-07-10 20:28:04       21 阅读
  7. 3033.修改矩阵

    2024-07-10 20:28:04       19 阅读
  8. 架构面试-数据库优化问题

    2024-07-10 20:28:04       18 阅读
  9. 精通Sklearn时间序列分析:预测未来的艺术

    2024-07-10 20:28:04       24 阅读
  10. OpenHarmony移植小型系统exynos4412(一)

    2024-07-10 20:28:04       19 阅读