How do I calculate frequency from an x position on a bode diagram?

1 visualización (últimos 30 días)
Drew
Drew el 21 de Oct. de 2013
Respondida: Youssef Khmou el 21 de Oct. de 2013
Hi,
I'm using the code below to draw a bode diagram manually (drawing code omitted).
It's working reasonably well. In this scenario I have 3 'decades' divided by 10 logarithmic spacings for the x-axis (frequency). I am using the code to calculate the x position for where to draw the bode diagram vertical lines (gridx). In this scenario the grid canvas size is 320 pixels (gridWidth).
However, I'm not sure how I can get a corresponding frequency value from an arbitrary x-position pixel value? So for example, if I clicked somewhere on the canvas, at say, x position 109, what would be the corresponding frequency there?
Any ideas?
Thanks in advance,
Drew
gridWidth = 320;
numDecades = 3;
range = gridWidth / numDecades;
for decade = 0:numDecades-1,
for index = 1:10,
gridx = (log(index) * range / log(10.0)) + 0.5 + (decade * range);
frequency = index * 10 * (10.0^decade);
fprintf('Decade: %d, index: %d, x: %f, frequency: %f \n', decade, index, gridx, frequency);
end
fprintf('\n');
end

Respuestas (1)

Youssef  Khmou
Youssef Khmou el 21 de Oct. de 2013
Drew, Your code does not return vectors to evaluate the gridx as function of frequency, try this version :
gridWidth = 320;
numDecades = 3;
range = gridWidth / numDecades;
ctr=1;
for decade = 0:numDecades-1,
for index = 1:10,
gridx(ctr,index) = (log(index) * range / log(10.0)) + 0.5 + (decade * range);
frequency(ctr,index) = index * 10 * (10.0^decade);
fprintf('Decade: %d, index: %d, x: %f, frequency: %f \n', decade, index, gridx, frequency);
end
ctr=ctr+1;
fprintf('\n');
end
figure, plot(frequency, gridx)
xlabel(' Frequency Hz')
grid;
Using canvas, you get the corresponding frequency .

Categorías

Más información sobre Get Started with Control System Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by