📄 snr_max.m
字号:
function [ys,W,Q]=SNR_Max(x,Fs);
% SNR_Max is used to separate the linear mixture of multisignals
% Usage:[ys,w,q]=SNR_Max(x,Fs);
% Input:
% *x is a column vectors of signals received by the senor or mixed signals
% *Fs is the sampling rate
% Output:
% *ys is a column vectors of reconstructed signals or demixed signals
% *W is the demixing matrix
% *Q is the whitening matrix
%-----------Subtract average-----------%
[n,T]=size(x);
x=x-mean(x')'*ones(1,T);
%--------------Whitening---------------%
[F,D]=eig((x*x')/T);% Why x*x' is divided by x's length?
v=F*(D^(-0.5))*F';
Q=v;
x=v*x;
%------------Running average-----------%
WindowSize=10;% Why WindowSize equalls to 80? It seems that 10 is better
%WindowSize=5; % For the separation of speech signals
a=ones(1,WindowSize)/WindowSize;
x=x';
S=filter(a,1,x);
%--------Calculating covariance matrices--------%
U=cov(S-x,1);
V=cov(x,1);
[W d]=eig(V,U); % Calculating eigenvalue
%[W d]=eig(U,V);% The two types of expression both work well!
ys=(x*W)'; % Estimating source signals
%------------Temp Plot(Only for Test)----------%
temp_plot(ys,Fs);
function temp_plot(ys,Fs);
figure;
len=200;
t=[0:len-1]/Fs;
subplot(211);
plot(t,ys(1,1:len));
ylabel('Separated Signal ys1');
xlabel('Time(sec)');
subplot(212);
plot(t,ys(2,1:len));
ylabel('Separated Signal ys2');
xlabel('Time(sec)');
%---------------Plot-------------------%
%mplot(x);
%figure(2);
%mplot(ys);
%----------------mplot----------------%
function mplot(s);
[dim,sample]=size(s);
if dim>sample
s=s';
[dim,sample]=size(s);
end
if dim>6
error('Dimention should be no more than 6!')
end
for i=1:dim
subplot(dim,1,i);
plot(s(i,:));
axis('tight');
set(gca,'XTick',[]);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -