Contour plot of a source which decays with radius.

2 views (last 30 days)
So i am trying to create a contourf() plot of a source (representative of sound), whose output decays due to the attenuation of sound with radius. I expect the output to be contours of reducing magnitude around the centre point. They should be perfectly circular.
The decay is expressed by the function
10*log10(exp(2*alpha))*(distance from source)
where alpha is calculated earlier in the script. For all intents and purposes, it is just a constant (lets say 0.005).
As i understand i should create it in polar, convert to cartesian and then plot but i end up with linear contours, not circular. I am fairly new to matlab so its all a bit above my head. This is what i have currently:
--------------
radius = 0:1000; % the distance from source i want to evaluate
theta = (0:360)*pi/180; % the polar circle in radians
[th,r] = meshgrid(theta,radius); % create a meshgrid??? this step i'm unsure of and only using due to other answers on similar topics
[TH,R] = pol2cart(th,r); %convert to cartesian
A = 10*log10(exp(2*alpha))*R; %define the function for decay of sound
figure(2)
contourf(X,Y,A) % plot. is this right?
colorbar
axis square
-----------

Accepted Answer

Calum Harrison
Calum Harrison on 29 Sep 2017
Edited: Walter Roberson on 29 Sep 2017
Managed to solve this one after returning to the fundamental mathematics. Thought id post here in the case it helps anyone in the future. My issue was incorrect definition of the coordinate system. By replacing the distance from the source, or radius, as sqrt(x^2 + y^2) the system was correctly referenced. The code was as follows:
radius = 0:3600;
theta = (0:0.1:360)*pi/180;
x = radius.*cos(theta);
y = radius.*sin(theta);
[X,Y] = meshgrid(x,y);
A = real(10*log10(exp(2*alpha)).*sqrt(X.^2+Y.^2));
figure(2)
contourf(X,Y,A)
colorbar
axis square

More Answers (1)

Walter Roberson
Walter Roberson on 29 Sep 2017
A = 10*log10(exp(2*alpha))*y;
I would recommend renaming your x and y to TH and R or the like.
  1 Comment
Calum Harrison
Calum Harrison on 29 Sep 2017
Thanks for the tip. I intended to tidy it all up later but i suppose it would have been helpful when posing the question. ill fix it now :)

Sign in to comment.

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!