Plotting the maximum amplitude of p as a function of range.
1 次查看(过去 30 天)
显示 更早的评论
Hey guys, I am not sure how plot of the maximum amplitude of p as a function of range.
Could I find the maximum amplitude of p by using peak = max(signal) or do i need another function in matlab?
I am also unsure how I should write it with the loops, since it is my first time working with loops.
Thanks in advance
P1=1; % The sound pressure in Pa at 1 m range
f = 1e3; % The frequency, Hz
w = 2*pi*f; % Angular frequency, radHz
c = 340; % Sound speed, m/s
lambda = c/f; % Wavelength, m
k = 2*pi/lambda; % Wave number, m-1
r = 0.1:0.01:10; % range vector, interspaced by 1 cm
fs = 1e5;
t = [0 : 1/fs : 10/f ]; %time scale, running over ten periods
for i=1:length(t)
p(i,:) = (P1./r).*sin(w*t(i)-k*r);
end
for i=1:length(t)
plot(r,p(i,:));
title([ num2str(t(i)) ' s'])
xlabel('m');
ylabel('Pa')
axis([0 max(r) -10 10])
pause(0.1)
end
for i = 1: length(r)
plot(t',p(:,i));
title([num2str(r(i)) ' m'])
xlabel('s');
ylabel('Pa')
axis([0 max(t) P1*[-10 10] ])
pause;
end
0 个评论
采纳的回答
Star Strider
2018-12-6
It seems that the first figure does exactly that.
I would also put each loop in a separate figure:
figure
for
...
end
figure
for
...
end
If you simply want to plot the magnitudes of the peaks, the findpeaks (link) function will isolate their amplitudes and distances for you. Use it with the columns of ‘p’. I leave it to you to experiment, since I’m not certain what you’re doing in your code (that appears to me to be both efficient and clever).
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!