How to manually move (smoothly) a set of evenly spaced xlines

In R2020a on a plot I plan on having a loop to produce 20 xlines that are 200 samples apart. (I know that in later versions, one xline can have an array, but not in R2020a.)
I would like to be able to manually move all of them by some offset < 200, preferably with a mouse. Ideally, I would select the left-most xline with a mouse (or even any point between the first two xlines), and as I move the mouse to the right, all 20 xlines would move smoothly to the right keeping their difference of 200 samples intact. When I let go of the mouse select key, then I would like to know the exact x-coordinate of the left-most xline. (Using the figure tooltip only gives an approximate x-coordinate.) I should then be able to repeat this until I am satisified that all the gaps between the xlines have captured the data symbols correctly.
In following example, I would want to slide the xlines to lie on top of the peaks. (Actual signals are not as clear.)
f = 50*1e6;
phi = 14*pi/9;
t = linspace(0,1,100e3);
y = sin(2*pi*f*t + phi);
plot(y)
for ii = 0:10
xline(ii*200 + 25);
end
xlim( [1 2300] );
I found this question on moving xlines answered by @Steven Lord. Thought that maybe it could help.

 Réponse acceptée

While you can't create a vector of xline objects in one call in release R2020a, you can store those handles in an array.
axis([-5 5 0 10])
h = gobjects(1, 5);
for k = 1:5
h(k) = xline(k-3); % Lines at -2, -1, 0, 1, and 2
end
Now just update the Value property of each line. A simple for loop would be easiest, but you can change all their properties at once using a one line command if you don't mind it being a little cryptic. This moves the lines to be at positions -3:1.
set(h, {'Value'}, arrayfun(@(obj) obj.Value-1, h, 'UniformOutput', false).')
This uses the "set(H,NameArray,ValueArray)" syntax from the set function's documentation page.

3 commentaires

Thanks @Steven Lord for your very quick response. Below is my modified code in the OP adding in your changes. Only question left is how to move the xlines using the mouse (preferably smoothly, or just by jumping).
I don't understand the set function but I see that it works as the lines jumped 150 samples to the right in my example. I looked for help on set, but didn't see {'Value'}, or 'UniformOutput' in this documentation:
f = 50*1e6;
phi = pi/7;
t = linspace(0,1,100e3);
y = sin(2*pi*f*t + phi);
plot(y)
h = gobjects(1, 11);
for k = 1:11
h(k) = xline( (k-1)*200 + 15); % Lines 200 samples apart
end
axis( [1 2000 -1.5 1.5] );
set(h, {'Value'}, arrayfun(@(obj) obj.Value+150, h, 'UniformOutput', false).')
Is there a way to grab hold of one of the xlines (e.g., say, the first one), and then slide them slowly and smoothly with the mouse?

Connectez-vous pour commenter.

Plus de réponses (1)

With your clarifying picture there may be another possibility. You could just put the xline objects in their required position automatically.
x = 0:3600;
y = sind(x);
L = islocalmax(y);
plot(x, y, '-');
hold on
peakLocations = x(L);
for whichpeak = 1:numel(peakLocations)
xline(peakLocations(whichpeak));
end
Another potential approach to highlight the peaks is to add a stem plot.
% stem(x(L), y(L))

3 commentaires

With actual signals, there are no clear cut peaks. The actual symbol using the above example would be a half sine wave where the positive half represents +1, and the bottom half represents -1. In fact, with actual data, the rough half sine wave might even drop slightly below 0 in the middle of the symbol, but most of the 200 samples will be above 0 if I can get the alignment correct.
I need this functionality as a sanity check so that I can see that using the 200 sample spacing, that all the symbols appear as they should over the entire length, and that there is no drift that starts to mix one symbol with another.
Do you need to perform a visual sanity check or can you programmatically check that the true values returned from islocalmax (and potentially its opposite islocalmin if you're looking for both types of local extrema) are equally spaced?
First I would like to do a visual sanity check.
I work with another group that has a proprietary waveform viewer. They show me how they analyze their data. They use the analogous equal space xlines and use the mouse to slowly move the set of lines to the right or left to analyze their data, and stop when they think their selection makes sense. If 200 samples per symbol is slightly off, they can modify this value in a their text window and all the lines become spaced accordingly. I am trying to emulate parts of their proprietary tool, so that I can perform the same analysis, and if the spacing is a little more or less than 200 samples per symbol (or even a fractional number of samples per symbol), I will be less dependent on that tool.
Once analysis is done and good sanity results are observed from the figures, then I can choose an implementation path with more confidence.
I did use findpeaks and thresholding to identify initial points to throw out. I will explore using islocal[min|max] later.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by