一种非平稳信号滤波方法:基于短时傅里叶变换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
相关推荐
一颗松鼠6 分钟前
JavaScript 闭包是什么?简单到看完就理解!
开发语言·前端·javascript·ecmascript
有梦想的咸鱼_8 分钟前
go实现并发安全hashtable 拉链法
开发语言·golang·哈希算法
海阔天空_201313 分钟前
Python pyautogui库:自动化操作的强大工具
运维·开发语言·python·青少年编程·自动化
天下皆白_唯我独黑21 分钟前
php 使用qrcode制作二维码图片
开发语言·php
夜雨翦春韭24 分钟前
Java中的动态代理
java·开发语言·aop·动态代理
小远yyds26 分钟前
前端Web用户 token 持久化
开发语言·前端·javascript·vue.js
何曾参静谧38 分钟前
「C/C++」C/C++ 之 变量作用域详解
c语言·开发语言·c++
q567315231 小时前
在 Bash 中获取 Python 模块变量列
开发语言·python·bash
许野平2 小时前
Rust: 利用 chrono 库实现日期和字符串互相转换
开发语言·后端·rust·字符串·转换·日期·chrono
也无晴也无风雨2 小时前
在JS中, 0 == [0] 吗
开发语言·javascript