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); endfor 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)endfor 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
Best Answer