Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2009-04-16, 16:42   #1
fyccc736
初级会员
 
注册日期: 2009-04-16
年龄: 38
帖子: 1
声望力: 0
fyccc736 正向着好的方向发展
默认 MATLAB测距

背景:本设计基于Matlab仿真平台,采用.m文件形式,利用声卡对音频范围的信号进行发射,接收及测距。其主要功能模块包括音频扩频测试信号的产生及发送;信号的实时接收;信号处理以及结果的图示显示等。要求对不同的测试信号和不同处理方法的测距性能进行比较研究.测量距离5cm --- 2m 误差 < 1%

才学习用MATLAB,做这个简直一头雾水。有兴趣和懂的可以单独联系我
QQ:1063267784
有这么一段参考,我就是调不对啊
function sonar_anal(fig)
% SONAR_ANAL is a callback for the sonar demo (tof.m).

% user data
ud=get(fig,'userdata');
ai=ud.ai;
ao=ud.ao;
h=ud.h;
txt=h.text1;

% measurement
y=getdata(ai); % get response when done

x=ud.x; % excitation chirp
N=ai.samplespertrigger; % record length
Fs=ai.samplerate; % samples/sec (Hz)
c=ud.c; % wave speed (m/sec)

% analysis
X=fft(x); Y=fft(y); % forward transforms
Z=conj(X).*Y; % freq-domain equiv xcorr (circ)

% Hilbert transform => envelope
pos=2:N/2; Z(pos)=2*Z(pos); % double positive frequencies
neg=(N/2+1):N; Z(neg)=0; % zero out neg frequencies

z=fftshift(abs(ifft(Z))); % inverse transform

i=(1:N)'; % sample index
t=(i-1-N/2)/Fs; % time index (sec)

z(t>6/c)=0; % ignore insane distances (>6m)

[pk,loc]=max(z); % height & location of peak
if length(loc)>1 % tie breaker
if max(diff(loc))==1 % fence strattler
lag=mean(t(loc)); % split the difference
else % real competition
lag=t(loc(1)); % early bird gets the worm
end
else % no contest
lag=t(loc); % time delay (sec)
end
d=lag*c; % distance (m)

% display results
%disp(sprintf('t=%.2fmsec d=%.3fm,%.1fin',lag*1e3,d,d/0.0254))
plot(t*c,z/pk), axis([0 6 0 1])
hold on, plot(d,mean(z(loc))/pk), hold off
set(h.text1,'string',sprintf('Distance = %.1f m',d))

% repeat
if strcmp(get(h.Stop,'Enable'),'on') % repeating measurements
putdata(ao,x) % preload output buffer
start([ai ao]) % do it again!
else % single measurement
set(h.Repeat,'enable','on') % enable Repeat button
end

此帖于 2009-04-16 16:48 被 fyccc736 编辑。 原因: 文字不当
fyccc736 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 12:50


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.