how to hold positioning vector to obtain maximum power?

1 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2018-6-14
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 个评论
Image Analyst
Image Analyst 2018-6-15
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 2018-6-18
编辑:kat001 2018-6-18
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?

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-6-14
Try movmax(). Write back if you can't figure it out.
  1 个评论
kat001
kat001 2018-6-14
编辑:kat001 2018-6-14
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by