标签:
杂谈 |
分类: 书生意气 |
一、最小二乘法
clear
clc
fs=512;
m=0:(fs-1);
xn=sqrt(20)*sin(2*pi*0.2*m)+sqrt(2)*sin(2*pi*0.213*m)+randn(1,fs);
%产生含有噪声的序列xn
Rx=xcorr(xn);
q=200;
%以下p1、p2分别是AR的阶数
p1=4;
p2=6;
%p1=4时:
p=p1;
R=zeros(p,p);
r=zeros(1,p);
for i=1:p
end
for m=1:p
end
A=-(inv(R'*R))*R'*r';
A(p+1)=1;
figure(1)
freqz(1,A,fs,1);
title('AR:p=4')
grid on;
%p2=6时:
p=p2;
R=zeros(p,p);
r=zeros(1,p);
for i=1:p
end
for m=1:p
end
A=-(inv(R'*R))*R'*r';
A(p+1)=1;
figure(2)
freqz(1,A,fs,1);
title('AR:p=6')
grid on;
运行结果:
clear;
clc;
fs=512;
m=0:(fs-1);
xn=sqrt(20)*sin(2*pi*0.2*m)+sqrt(2)*sin(2*pi*0.213*m)+randn(1,fs);
%产生含有噪声的序列xn
Rx=xcorr(xn);
pe=100;%%%%%%%%%%%%%%%%%
qe=150;%%%%%%%%%%%%%%%%
M=300;%%%%%%%%%%%%%%%%%
Re=zeros(M,pe+1);
for i=1:M
end
[U,S,V]=svd(Re);%%%%%%奇异值分解
%%求p值
p=0;
SS=zeros(1,pe+1)';
for i=1:(pe+1)
end
SS'
p
%%求Sp部分
Sp=zeros(p+1,p+1);
for j=1:p
end
%%求Sp逆矩阵
inv_Sp=inv(Sp);
%%求x
x=zeros(1,p+1)';
for i=1:(p+1)
end
A=x;
freqz(1,A,512,1);
grid on;
title('SVDTLS')
仿真结果:
http://1802.img.pp.sohu.com.cn/images/blog/2008/12/11/20/21/11ecea5ce7dg214.jpg尽管不是很好,仅是为了共享一下,以供自己以后参考。