how to draw peaks in specific locations?

1 view (last 30 days)
marc kahwaji
marc kahwaji on 2 Aug 2014
Commented: marc kahwaji on 5 Aug 2014
i need to draw peaks in specific coordinations how can i do it ?

Answers (1)

Star Strider
Star Strider on 2 Aug 2014
Here is one way:
P = @(x,c,w) exp(-w*(x-c).^2); % Function to calculate peaks
W = 2; % Width (constant here, can vary as a vector if you like)
C = 5:5:15; % Peak centers
x = linspace(0,20,250); % Define ‘x’ vector
pks = zeros(size(x)); % Preallocate ‘pks’
for k1 = 1:length(C) % Loop through ‘C’ (centers) vector
pks = pks + P(x,C(k1),W);
end
figure(1) % Plot
plot(x,pks)
grid
produces:
  13 Comments
Star Strider
Star Strider on 5 Aug 2014
I see you posted that Question and Image Analyst provided an appropriate Answer. Accepting Image Analyst’s Answer and mine here would be an appropriate response from you.
marc kahwaji
marc kahwaji on 5 Aug 2014
this is my serial data code
clear all; delete(instrfind); s = serial('COM6'); instrfind set(s, 'InputBufferSize', 256); set(s, 'FlowControl', 'none'); set(s, 'BaudRate', 9600); set(s, 'Parity', 'none'); set(s, 'Timeout',1);
disp(get(s,'Name')); prop(1)=(get(s,'BaudRate')); prop(2)=(get(s,'DataBits')); prop(3)=(get(s, 'StopBit')); prop(4)=(get(s, 'InputBufferSize'));
disp(['Port Setup Done!!',num2str(prop)]); fopen(s); instrfind
stopTime = '9/24 21:53'; time = now;
i=1; j=1;
while ~isequal(datestr(now,'mm/DD HH:MM'),stopTime)
d(i,j)=fscanf(s,'%f') %reading serial data and putting them in a matrix
e=d(:,1)' %values of the first sensor
f=d(:,end)' %values of the second sensor
subplot(1,2,1);
plot(e) %plotting the values of the first sensor
grid
subplot(1,2,2);
plot(f) %plotting the values of the second sensor
grid
j=j+1; if j==3 % if the index of columns of the matrix is 3
i=i+1; %we go to a new line of the matrix we increment the index of lines
j=1; %and we put the index of columns to 1
end ;
drawnow end; fclose(s); delete(s);
clear all;
i have serial data coming from two sensors.I'm putting them in a matrix then splitting them in two matrix: e and f. e contains the values of the first sensor and f contains the values of the second sensor. i need to draw two circles, one for each sensor, and i need to color them according to the values in matrix e and f. how can i do it?

Sign in to comment.

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!