资源简介
这是音频信号处理中的正弦模型的matlab仿真程序,有一定的参考价值
代码片段和文件信息
function [AFPfs]=an_sinsoid(filename)
%正弦模型的分析函数
%输入:
%filename——输入文件名(wav文件)
%输出:
%A——幅度矩阵
%F——频率矩阵
%P——相位矩阵
%Version 0.1 ,Written by 徐宁 07/13/2007
%y050922@njupt.edu.cn
%***********************************************
[speechfs]=wavread(filename);
%以20ms为一帧
framesize=fs*0.02;
%构造窗函数
win=hamming(framesize);
%归一化窗函数
alpha=sum(win);
win=win‘/alpha;
ii=1;
L=length(speech);
frame=floor(L/framesize);
A=cell(1frame);
F=cell(1frame);
P=cell(1frame);
while framesize*ii<=L
framespeech=speech(framesize*(ii-1)+1: framesize*ii);
framespeech=framespeech.*win;
%求DFT
dftspec1=fft(framespeech1024);
%求对数幅度谱
dftspec2=10*log10(abs(dftspec1(1:512)));
k=findpeaks(dftspec2);
A{ii}=abs(dftspec1(k));
F{ii}=k*fs/1024;
P{ii}=angle(dftspec1(k));
ii=ii+1;
end
end
function [kv]=findpeaks(xmw)
if nargin<2
m=‘ ‘;
end
nx=length(x);
if any(m==‘v‘)
x=-x(:); % invert x if searching for valleys
else
x=x(:); % force to be a column vector
end
dx=x(2:end)-x(1:end-1);
r=find(dx>0);
f=find(dx<0);
if length(r)>0 & length(f)>0 % we must have at least one rise and one fall
dr=r;
dr(2:end)=r(2:end)-r(1:end-1);
rc=repmat(1nx1);
rc(r+1)=1-dr;
rc(1)=0;
rs=cumsum(rc); % = time since the last rise
df=f;
df(2:end)=f(2:end)-f(1:end-1);
fc=repmat(1nx1);
fc(f+1)=1-df;
fc(1)=0;
fs=cumsum(fc); % = time since the last fall
rp=repmat(-1nx1);
rp([1; r+1])=[dr-1; nx-r(end)-1];
rq=cumsum(rp); % = time to the next rise
fp=repmat(-1nx1);
fp([1; f+1])=[df-1; nx-f(end)-1];
fq=cumsum(fp); % = time to the next fall
k=find((rs v=x(k);
if any(m==‘q‘) % do quadratic interpolation
b=0.5*(x(k+1)-x(k-1));
a=x(k)-b-x(k-1);
j=(a>0); % j=0 on a plateau
v(j)=x(k(j))+0.25*b(j).^2./a(j);
k(j)=k(j)+0.5*b(j)./a(j);
k(~j)=k(~j)+(fq(k(~j))-rs(k(~j)))/2; % add 0.5 to k if plateau has an even width
end
% now purge nearby peaks
if nargin>2
j=find(k(2:end)-k(1:end-1)<=w);
while any(j)
j=j+(v(j)>=v(j+1));
k(j)=[];
v(j)=[];
j=find(k(2:end)-k(1:end-1)<=w);
end
end
else
k=[];
v=[];
end
if any(m==‘v‘)
v=-v; % invert peaks if searching for valleys
end
if ~nargout
if any(m==‘v‘)
x=-x; % re-invert x if searching for valleys
ch=‘v‘;
else
ch=‘^‘;
end
plot(1:nxx‘-‘kvch);
end
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2907 2010-07-27 15:02 an_sinsoid.m
文件 461 2007-07-18 18:10 sy_sinsoid.m
文件 127 2010-07-27 15:00 test.m
----------- --------- ---------- ----- ----
3495 3
- 上一篇:LFMCW雷达汽车防撞系统仿真代码
- 下一篇:bregman信号恢复算法
评论
共有 条评论