how to hold positioning vector to obtain maximum power?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Image Analyst
on 14 Jun 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 Comments
Image Analyst
on 15 Jun 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.
More Answers (1)
See Also
Categories
Find more on Spectral Measurements 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!