how to hold positioning vector to obtain maximum power?

1 visualización (últimos 30 días)
kat001
kat001 el 14 de Jun. de 2018
Editada: kat001 el 18 de Jun. de 2018
Hi,
Currently my plot looks like this (the code is attached below):
where the red line represents an position vector as the power is increasing. What I would like to do is following (used MS paint for visualization) :
In other words, as the Gaussian profile reaches its maximum, the only way to keep maximum power all time by holding the position at the same place. And I am stuck with the coding here.
So far, my code looks like this:
x = -3:0.1:3;
norm = normpdf(x,0,1);
m = 0;
mPos = zeros(length(norm),1);
for i = 2:length(norm)
if(norm(i)>norm(i-1))
m = m + 0.1;
else
m = m - 0.1;
end
mPos(i) = m;
end
plot(x, mPos, 'r')
hold on
plot(x, norm, 'b')
grid on
hold off

Respuesta aceptada

Image Analyst
Image Analyst el 14 de Jun. de 2018
Try this:
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
x = -3:0.1:3;
numPoints = length(x);
norm = normpdf(x,0,1);
m = 0;
mPos = zeros(1, numPoints);
normMax = norm(1) * ones(1, numPoints);
mPosMax = zeros(1, numPoints);
for k = 2:length(norm)
if(norm(k)>norm(k-1))
m = m + 0.1;
else
m = m - 0.1;
end
mPos(k) = m;
if norm(k) >= normMax(k-1)
normMax(k) = norm(k);
else
normMax(k) = normMax(k-1);
end
if mPos(k) >= mPosMax(k-1)
mPosMax(k) = mPos(k);
else
mPosMax(k) = mPosMax(k-1);
end
end
subplot(2, 1, 1);
plot(x, mPos, 'r-', 'LineWidth', 2)
hold on
plot(x, norm, 'b-', 'LineWidth', 2)
grid on
hold off
title('Original Signals', 'FontSize', fontSize);
xlabel('x', 'FontSize', fontSize);
ylabel('Original Signal Value', 'FontSize', fontSize);
legend('mPos', 'norm', 'Location', 'east');
subplot(2, 1, 2);
plot(x, mPosMax, 'r-', 'LineWidth', 2);
hold on;
plot(x, normMax, 'b-', 'LineWidth', 2);
grid on
hold off
title('Max (Peak Detection) Signals', 'FontSize', fontSize);
xlabel('x', 'FontSize', fontSize);
ylabel('Max Signal Value', 'FontSize', fontSize);
legend('mPos', 'norm', 'Location', 'east');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
  3 comentarios
Image Analyst
Image Analyst el 15 de Jun. de 2018
I don't know what you're doing with the line of code you put in. I don't know what normT is supposed to represent - you forgot to tell me. All you said is you've written a line of code and then asked for suggestions about it. What can I say? If it does what you want, then fine. Otherwise say what you want to do.
I don't know Simulink - sorry.
kat001
kat001 el 18 de Jun. de 2018
Editada: kat001 el 18 de Jun. de 2018
So, Now this code seems to work for horizontal or x axis. However, I have used the same code in a new function for vertical or y axis.
I have set t = 0:1:5 for the x axis fucntion. And for y axis function, it is t2 = t(end):1:10. 't' is an input for the 'y axis' function. I also want to feed the same power from 'x axis'-function to 'y axis'-function, i.e. the same power value will be picked at t2(1) and will continue until t2 = 10.
I am facing the problem with writing the code for 'normT' which is the input to y axis the vector assignment section of the code. The rest of the code won't be changing so much other than variable name changes.
Any idea?

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Jun. de 2018
Try movmax(). Write back if you can't figure it out.
  1 comentario
kat001
kat001 el 14 de Jun. de 2018
Editada: kat001 el 14 de Jun. de 2018
Well, this is not really what I had in my mind.
What I was thinking of is that the position vector checks the power level all the time. From the first plot, you may see the Gaussian profile increases to maximum then decreases and so does the position vector.
What I would like to do is to hold the power level at maximum by controlling the position vector. Hence the second plot drawn in 'paint' to show what I had in my mind.

Iniciar sesión para comentar.

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by