维纳滤波可直接执行matlab代码
更新时间:2023-11-25 00:44:01 阅读量: 教育文库 文档下载
- 维纳滤波matlab代码推荐度:
- 相关推荐
function output=WienerScalart96(signal,fs,IS)
% output=WIENERSCALART96(signal,fs,IS)
% Wiener filter based on tracking a priori SNR usingDecision-Directed % method, proposed by Scalart et al 96. In this method it is assumed that % SNRpost=SNRprior +1. based on this the Wiener Filter can be adapted to a % model like Ephraims model in which we have a gain function which is a % function of a priori SNR and a priori SNR is being tracked using Decision % Directed method.
% Author: Esfandiar Zavarehei % Created: MAR-05
if (nargin<3 | isstruct(IS))
IS=.25; %Initial Silence or Noise Only part in seconds end
W=fix(.025*fs); %Window length is 25 ms
SP=.4; %Shift percentage is 40% (10ms) %Overlap-Add method works good with this value(.4) wnd=hamming(W);
%IGNORE FROM HERE ...............................
if (nargin>=3 & isstruct(IS))%This option is for compatibility with another programme W=IS.windowsize SP=IS.shiftsize/W; %nfft=IS.nfft; wnd=IS.window; if isfield(IS,'IS') IS=IS.IS; else
IS=.25; end end
% ......................................UP TO HERE
pre_emph=0;
signal=filter([1 -pre_emph],1,signal);
NIS=fix((IS*fs-W)/(SP*W) +1);%number of initial silence segments
y=segment(signal,W,SP,wnd); % This function chops the signal into frames Y=fft(y);
YPhase=angle(Y(1:fix(end/2)+1,:)); %Noisy Speech Phase Y=abs(Y(1:fix(end/2)+1,:));%Specrogram
numberOfFrames=size(Y,2); FreqResol=size(Y,1);
N=mean(Y(:,1:NIS)')'; %initial Noise Power Spectrum mean
LambdaD=mean((Y(:,1:NIS)').^2)';%initial Noise Power Spectrum variance
alpha=.99; %used in smoothing xi (For Deciesion Directed method for estimation of A Priori SNR) NoiseCounter=0;
NoiseLength=9;%This is a smoothing factor for the noise updating G=ones(size(N));%Initial Gain used in calculation of the new xi Gamma=G;
X=zeros(size(Y)); % Initialize X (memory allocation)
h=waitbar(0,'Wait...');
for i=1:numberOfFrames
%%%%%%%%%%%%%%%%VAD and Noise Estimation START if i<=NIS % If initial silence ignore VAD SpeechFlag=0;
NoiseCounter=100; else % Else Do VAD
[NoiseFlag, SpeechFlag, NoiseCounter, Dist]=vad(Y(:,i),N,NoiseCounter); %Magnitude Spectrum Distance VAD end
if SpeechFlag==0 % If not Speech Update Noise Parameters
N=(NoiseLength*N+Y(:,i))/(NoiseLength+1); %Update and smooth noise mean
LambdaD=(NoiseLength*LambdaD+(Y(:,i).^2))./(1+NoiseLength); %Update and smooth noise variance end
%%%%%%%%%%%%%%%%%%%VAD and Noise Estimation END
gammaNew=(Y(:,i).^2)./LambdaD; %A postiriori SNR
xi=alpha*(G.^2).*Gamma+(1-alpha).*max(gammaNew-1,0); Tcision Directed Method for A Priori SNR
Gamma=gammaNew;
G=(xi./(xi+1));
X(:,i)=G.*Y(:,i); %Obtain the new Cleaned value
waitbar(i/numberOfFrames,h,num2str(fix(100*i/numberOfFrames))); end
close(h);
output=OverlapAdd2(X,YPhase,W,SP*W); %Overlap-add Synthesis of speech output=filter(1,[1 -pre_emph],output); %Undo the effect of Pre-emphasis
function ReconstructedSignal=OverlapAdd2(XNEW,yphase,windowLen,ShiftLen);
%Y=OverlapAdd(X,A,W,S);
%Y is the signal reconstructed signal from its spectrogram. X is a matrix %with each column being the fft of a segment of signal. A is the phase %angle of the spectrum which should have the same dimension as X. if it is %not given the phase angle of X is used which in the case of real values is %zero (assuming that its the magnitude). W is the window length of time %domain segments if not given the length is assumed to be twice as long as ?t window length. S is the shift length of the segmentation process ( for %example in the case of non overlapping signals it is equal to W and in the êse of P overlap is equal to W/2. if not givven W/2 is used. Y is the %reconstructed time domain signal. %Sep-04
%Esfandiar Zavarehei
if nargin<2
yphase=angle(XNEW); end
if nargin<3
windowLen=size(XNEW,1)*2; end
if nargin<4
ShiftLen=windowLen/2; end
if fix(ShiftLen)~=ShiftLen ShiftLen=fix(ShiftLen);
disp('The shift length have to be an integer as it is the number of samples.') disp(['shift length is fixed to ' num2str(ShiftLen)]) end
[FreqRes FrameNum]=size(XNEW);
Spec=XNEW.*exp(j*yphase);
if mod(windowLen,2) %if FreqResol is odd Spec=[Spec;flipud(conj(Spec(2:end,:)))]; else
Spec=[Spec;flipud(conj(Spec(2:end-1,:)))]; end
sig=zeros((FrameNum-1)*ShiftLen+windowLen,1); weight=sig;
for i=1:FrameNum
start=(i-1)*ShiftLen+1; spec=Spec(:,i);
sig(start:start+windowLen-1)=sig(start:start+windowLen-1)+real(ifft(spec,windowLen)); end
ReconstructedSignal=sig;
function Seg=segment(signal,W,SP,Window)
% SEGMENT chops a signal to overlapping windowed segments
% A= SEGMENT(X,W,SP,WIN) returns a matrix which its columns are segmented % and windowed frames of the input one dimentional signal, X. W is the % number of samples per window, default value W=256. SP is the shift
% percentage, default value SP=0.4. WIN is the window that is multiplied by % each segment and its length should be W. the default window is hamming % window. % 06-Sep-04
% Esfandiar Zavarehei
if nargin<3 SP=.4; end
if nargin<2 W=256; end
if nargin<4
Window=hamming(W); end
Window=Window(:); %make it a column vector
L=length(signal); SP=fix(W.*SP);
N=fix((L-W)/SP +1); %number of segments
Index=(repmat(1:W,N,1)+repmat((0:(N-1))'*SP,1,W))'; hw=repmat(Window,1,N); Seg=signal(Index).*hw;
function [NoiseFlag, SpeechFlag, Dist]=vad(signal,noise,NoiseCounter,NoiseMargin,Hangover)
%[NOISEFLAG, SPEECHFLAG, NoiseCounter, NOISECOUNTER,
DIST]=vad(SIGNAL,NOISE,NOISECOUNTER,NOISEMARGIN,HANGOVER) %Spectral Distance Voice Activity Detector
%SIGNAL is the the current frames magnitude spectrum which is to labeld as %noise or speech, NOISE is noise magnitude spectrum template (estimation),
%NOISECOUNTER is the number of imediate previous noise frames, NOISEMARGIN %(default 3)is the spectral distance threshold. HANGOVER ( default 8 )is
%the number of noise segments after which the SPEECHFLAG is reset (goes to %zero). NOISEFLAG is set to one if the the segment is labeld as noise
%NOISECOUNTER returns the number of previous noise segments, this value is %reset (to zero) whenever a speech segment is detected. DIST is the %spectral distance. %Saeed Vaseghi
íited by Esfandiar Zavarehei %Sep-04
if nargin<4
NoiseMargin=3; end
if nargin<5
Hangover=8; end
if nargin<3
NoiseCounter=0; end
FreqResol=length(signal);
SpectralDist= 20*(log10(signal)-log10(noise)); SpectralDist(find(SpectralDist<0))=0;
Dist=mean(SpectralDist); if (Dist < NoiseMargin) NoiseFlag=1;
NoiseCounter=NoiseCounter+1; else
NoiseFlag=0; NoiseCounter=0; end
% Detect noise only periods and attenuate the signal if (NoiseCounter > Hangover) SpeechFlag=0; else
SpeechFlag=1;
end
正在阅读:
维纳滤波可直接执行matlab代码11-25
村“扫黑除恶”专项斗争工作汇报范文02-22
生命顽强的梧桐树作文400字06-25
介绍一种植物的作文5篇02-05
《财务管理》试题及答案10-04
鄂建26号 省建设厅关于发布《湖北省建设项目总投资组成及其他费用定额》的通知11-25
2022年沈阳理工大学装备工程学院820物理化学二考研核心题库04-18
等待也是一种美作文550字06-20
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 维纳
- 滤波
- 执行
- 直接
- 代码
- matlab
- 上海开放大学社会实践报告范文
- 《灯塔—党建在线》党的十九大精神学习竞赛题库(2018年1月份)200道题
- 公司员工资质证书管理办法
- 苏工价11号
- 金融危机背后国际贸易失衡之思考
- 铁路行业施工企业获2009-2010国家级工法
- 光学显微镜分辨率
- 法学类专业建设情况报告 - 图文
- 用candence编辑3-8译码器
- 扫黑除恶专项斗争宣传标语口号(参考)(1)
- 爱国、敬业、诚信、友善发言稿
- 项目名称大型单轴承直驱永磁风电机组关键技术及产业化推荐单位
- 马概题库2
- 关注民生 履职为民
- 中国石油大学C语言上机题答案(2015版)答案 - 最全最详细
- 国网湖北省电力公司电气工作票实施细则(变电部分)
- 诗词格律与欣赏章节答案 八
- 行政诉讼法知识题库
- 山东省济南市历城区第二中学2017-2018学年高一物理10月月考试题
- 老师期末复习心得体会