![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189260/image.png)
how to hold positioning vector to obtain maximum power?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
kat001
am 14 Jun. 2018
Bearbeitet: kat001
am 18 Jun. 2018
Hi,
Currently my plot looks like this (the code is attached below):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191251/image.png)
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) :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191252/image.png)
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 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]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189260/image.png)
3 Kommentare
Image Analyst
am 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.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!