How to return all points in a polyshape

I have a signal that I am trying to modify. On the spectrogram of this signal, I have drawn a polygon using polyshape around a portion that I would ultimately like to remove/silence so that I can extract frequency information only from the portion of the signal I am interested in. How can I return all the data points of the spectrogram within the polygon so that I can use this in later functions? The inpolygon and isinterior functions allow me to verify if certain points I provide are within the polygon. However, both require me to input a series of coordinates to check. I do not want to provide the points. I would like to draw the shape and have a function that just returns the values within it.

댓글 수: 5

jonas
jonas 2018년 9월 30일
편집: jonas 2018년 9월 30일
So basically you want to use something like logical indexing or a mask? What is the shape of your polygon?
Te Jones
Te Jones 2018년 10월 1일
I'm not really sure what the best method is. I suppose I ultimately want to replace the data in those sections with NaN. The polygon is sort of a parallelogram, rather than a proper rectangle.
jonas
jonas 2018년 10월 1일
편집: jonas 2018년 10월 1일
I'm still a bit confused as to what you're looking for. Let's start by a simple example. Say we want to remove a square in the center of a set of points. We can do it with inpolygon like this:
%%Some data
x=rand(1,5000);
y=rand(1,5000);
%%Our polygon
xp=[.4 .6 .6 .4];
yp=[.4 .4 .6 .6];
%%Cut out polygon and plot
mask=inpolygon(x,y,xp,yp);
x(mask)=NaN;
y(mask)=NaN;
We could also do it by logical indexing
%%Cut out polygon and plot
mask=(x<max(xp) & x>min(xp) & y<max(yp) & y>min(yp));
x(mask)=NaN;
y(mask)=NaN;
Both of these methods yields identical results but the second one is about 6 times faster. The second approach is a bit more difficult to perform with a parallelogram, however. So, in light of this example, can you tell me why one method is better than the other? Both methods "checks" whether the points are inside of the polygon, but I don't know if it is even possible to skip this step, unless you somehow avoid creating those points to begin with.
Te Jones
Te Jones 2018년 10월 1일
My issue is that the spectrogram function returns time and frequency vectors that aren't equal. I don't know how I can take all of that data and check it against what is or isn't in the polygon. The goal is to be able to remove parts of the audio file that can't be removed with filters, like echoes. I want to be able to draw a shape around the section and eventually output a new data file that doesn't contain those portions so that I can continue with frequency analysis. So what is the way to check the output of Matlab's spectrogram so I can use x and y the way you have done with your randomly generated data?
jonas
jonas 2018년 10월 1일
편집: jonas 2018년 10월 1일
Could you upload one such file/code and mark the areas that you would like to remove? I have never used the spectogram function so I dont know the nature of its output.

댓글을 달려면 로그인하십시오.

답변 (2개)

Steven Lord
Steven Lord 2018년 9월 27일

1 개 추천

Actually, instead of extracting the vertices from the polyshape and calling inpolygon, I would call isinterior instead.
I think that's what Te Jones referred to as the "TFin" function. To address the comment "there are too many points to check them all individually", realize that the inputs representing the points to check can be vectors instead of just scalars. So you can check many points at once with one call to isinterior.
jonas
jonas 2018년 9월 26일
편집: jonas 2018년 9월 26일

0 개 추천

This is exactly what inpolygon is for

카테고리

도움말 센터File Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2018년 9월 26일

편집:

2018년 10월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by