get all the harmonics from a wave - r

I need to filter the harmonics of an audio track using the libraries 'seewave' and 'tuneR' of R, but I do not know the functions of this language well.
So far I have done the following:
library('seewave')
library('tuneR')
track<-readMP3('empty_spaces.mp3')
t1<-cutw(track, from=0, to=10)
autoc(t1, f=4400)
and the result is the next screen:
at first I thought that the group of points on the bottom were the harmonics and the points isolated above belonged to noise, but I think I'm not interpreting it well. Could someone help me interpret this image? or tell me what function would help me get what I need?
Thank you

This is image of distribution of frequencies across time, so by this image it s hard to see, where noise and where useful signal. To solve your problem, you should use frequency filters , chebyhev or butterworth filters (look at filter function in signal package) and of course you must know what frequencies you want to delete.

Related

Is there a name for this type of problem involving dominos?

There's this problem that my professor showed me that I thought was interesting.
The problem is as follows:
If you have a 2^n by 2^n checkerboard and remove one square from it, will you be able to fill it with L-shaped trominos?
The answer to this is yes, the method of which I thought was interesting.
Example
In this example, X is the removed square and the numbers represent the shape of the L-shaped trominos. In every possible permutation of checkerboards, there should be a solution to fill up every square with trominos.
Does anyone know if this kind of problem is named in a field of math? I'd love to learn more about these.
I'm also going to attempt to program this, anyone have any ideas that could help?
There's a broad family of problems called tiling problems that ask when, whether, and how to tile different shapes using a fixed collection of figures.
There are other questions about figure subdivisions, where the question is when, whether, or how to subdivide some larger figure apart into smaller figures of various shapes.

ST_AREA is not enough precise

I am trying to save polygon area when a new polygon has been created by the user. I found that there is a function for this purpose - ST_AREA, but when I check if it is calculating correct I find some discrepancies. Here is one example:
This is one polygon which area according to geojson.io is 31.85:
But when I run ST_AREA for the same polygon:
SELECT ST_Area(CONCAT(a.polygon, 'SRID=4326'))*10000 AS area FROM kt_polygons a where polygon_id = 180;
The result is 34.93261884737489. Something more, I am not quite sure why I multiply the result area by 10000.. I just do that because the result seems to be more realistic in that way.
I check some other polygons and the difference is not more than 5, but why this can happen? Any ideas what I do wrong?
I found a solution which helps for my case. When I get the result from ST_Area I multiply it by 9090,91. This coefficient maybe is propriate only for my problem, but you can find if there is dependency between the real areas and the one from ST_Area. If so, you can find your coefficient.

distm in R leads to crash

So I have a pretty simple question regarding the size of my data. I am trying to calculate the distance between all sets points (WGS84) in a dataset (56000).
https://www.rdocumentation.org/packages/geosphere/versions/1.5-10/topics/distm
According to the documentation: distm(x,y,fun="") if missing, y is the same as x
mydist<-distm(coordinates(mySpatialObject), fun="distHaversine")
This led me to an Error that y was missing. So I figured I could easily work around this.
distm(coordinates(WeedClim.plot),coordinates(WeedClim.plot), fun="distHaversine")
This leads to not just R:Studio, but my entire computer freezing. I had to to a hard reset twice now and do not want to go through this again, because this is my dissertation and I am afraid of breaking something else in the project XD.
Any ideas/solutions? Is there a better function that gives me a distance matrix from a set of coordinates?
THANKS!

X and Y coordinates in R. Is there an obvious way to remove data that is a certain radius away from a given point?

I am trying to clean up some eye tracking data in which people are told to focus on the middle of the screen. However, the data is somewhat noisy and I am trying to clean it up in a proper way.
I have created some code that emulates the kind of data that I have and the methods I am trying to use as well as what I am presenting below.
The data complete with noise looks as follows:
I have tried to use a simple formula to throw all samples further than some pixels from the centre away such as:
results[results$x <= xmid+threshold & results$x >= xmid-threshold,]
But that results in data in a square shape rather than a circle:
I have tried to think about what to do here and have made it as far as to define a circle that encompasses the area that I am interested in:
However, I can not see a straightforward way to only pick data within that area.The solutions I have tried have required several for loops and still not given me the result I was hoping for.
I hope that some of you can point me in the right direction here. Maybe the problem is even trivial to solve in some manner that I have not yet considered? Thanks for reading this far and here is the code if you think that you can help :)
To check whether point lies in circular region with radius threshold around center xmid, ymid, you can use expression (^ denotes 2-nd power, squaring)
(x-xmid)^2 + (y-ymid)^2 <= threshold^2

How to determine all line segments from a list of points generated from a mouse gesture?

Currently I am interning at a software company and one of my tasks has been to implement the recognition of mouse gestures. One of the senior developers helped me get started and provided code/projects that uses the $1 Unistroke Recognizer http://depts.washington.edu/aimgroup/proj/dollar/. I get, in a broad way, what the $1 Unistroke Recognizer is doing and how it works but am a bit overwhelmed with trying to understand all of the internals/finer details of it.
My problem is that I am trying to recognize the gesture of moving the mouse downards, then upwards. The $1 Unistroke Recognizer determines that the gesture I created was a downwards gesture, which is infact what it ought to do. What I really would like it to do is say "I recognize a downards gesture AND THEN an upwards gesture."
I do not know if the lack of understanding of the $1 Unistroke Recognizer completely is causing me to scratch my head, but does anyone have any ideas as to how to recognize two different gestures from moving the mouse downwards then upwards?
Here is my idea that I thought might help me but would love for someone who is an expert or even knows just a bit more than me to let me know what you think. Any help or resources that you know of would be greatly appreciated.
How My Application Currently Works:
The way that my current application works is that I capture points from where the mouse cursor is while the user holds down the left mouse button. A list of points then gets feed to a the gesture recognizer and it then spits out what it thinks to be the best shape/gesture that cooresponds to the captured points.
My Idea:
What I wanted to do is before I feed the points to the gesture recognizer is to somehow go through all the points and break them down into separate lines or curves. This way I could feed each line/curve in one at a time and from the basic movements of down, up, left, right, diagonals, and curves I could determine the final shape/gesture.
One way I thought would be good in determining if there are separate lines in my list of points is sampling groups of points and looking at their slope. If the slope of a sampled group of points differed X% from some other group of sampled points then it would be safe to assume that there is indeed a separate line present.
What I Think Are Possible Problems In My Thinking:
Where do I determine the end of a line and the start of a separate line? If I was to use the idea of checking the slope of a group of points and then determined that there was a separate line present that doesn't mean I nessecarily found the slope of a separate line. For example if you were to draw a straight edged "L" with a right angle and sample the slope of the points around the corner of the "L" you would see that the slope would give resonable indication that there is a separate line present but those points don't correspond to the start of a separate line.
How to deal with the ever changing slope of a curved line? The gesture recognizer that I use handles curves already in the way I want it too. But I don't want my method that I use to determine separate lines keep on looking for these so called separate lines in a curve because its slope is changing all the time when I sample groups of points. Would I just stop sampling points once the slope changed more than X% so many times in a row?
I'm not using the correct "type" of math for determining separate lines. Math isn't my strongest subject but I did do some research. I tried to look into Dot Products and see if that would point me in some direction, but I don't know if it will. Has anyone used Dot Prodcuts for doing something like this or some other method?
Final Thoughts, Remarks, And Thanks:
Part of my problem I feel like is that I don't know how to compeletly ask my question. I wouldn't be surprised if this problem has already been asked (in one way or another) and a solution exist that can be Googled. But my search results on Google didn't provide any solutions as I just don't know exactly how to ask my question yet. If you feel like it is confusing please let me know where and why and I will help clarify it. In doing so maybe my searches on Google will become more precise and I will be able to find a solution.
I just want to say thanks again for reading my post. I know its long but didn't really know where else to ask it. Imma talk with some other people around the office but all of my best solutions I have used throughout school have come from the StackOverflow community so I owe much thanks to you.
Edits To This Post:
(7/6 4:00 PM) Another idea I thought about was comparing all the points before a Min/Max point. For example, if I moved the mouse downards then upwards, my starting point would be the current Max point while the point where I start moving the mouse back upwards would be my min point. I could then go ahead and look to see if there are any points after the min point and if so say that there could be a new potential line. I dunno how well this will work on other shapes like stars but thats another thing Im going to look into. Has anyone done something similar to this before?
If your problem can be narrowed down to breaking apart a general curve into straight or smoothly curved partial lines then you could try this.
Comparing the slope of the segments and identifying breaking points where it is greater then some threshold would work in a very simplified case. Imagine a perfectly formed L-shape where you have a right angle between two straight lines. Obviously the corner point would be the only one where the slope difference is above the threshold as long as the threshold is between 0 and 90 degrees, and thus a identifiable breaking point.
However, the vertical and horizontal lines may be slightly curved so the threshold would need to be large enough for these small differences in slope to be ignored as breaking points. You'd also have to decide how sharp a corner the algorithm should pick up as a break. is 90 deg or higher required, or is even 30 deg enough? This is an important question.
Finally, to make this robust I would not be satisfied comparing the slopes of two adjacent segments. Hands may shake, corners may be smoothed out and the ideal conditions to find straight lines and sharp corners will probably never occur. For each point investigated for a break I would take the average slope of the N previous segments and compare it to the average slope of the N following segments. This can be efficiently implemented using a running mean. By choosing a good sample number N (depending on the accuracy of the input, the total number of points, etc) the algorithm can avoid the noise and make better detections.
Basically the algorithm would be:
For each investigated point (beginning N points into the sequence and ending N points before the end.)
Compute average slope of the N previous segments.
Compute average slope of the N next segments.
If the difference of the averages is greater than the Threshold, mark current point as a breaking point.
This is quite off the top of my head. You'd have to try it in your application.
if you work with absolute angles, like upwards and downwards, you can simply take the absolute slope between two points (not necessarily adjacent) to determine if it's RIGHT, LEFT, UP, DOWN (if that is enough of a distinction)
the art is to find a distance between points so that the angle is not random (with 1px, the angle will be a multiple of 45°)
There is a firefox plugin for Navigation using mouse gestures that works very well. I think it's FireGestures, but I'm not sure. I guess you can get some inspiration from that one
Additional thought: If you draw a shape by connectiong successive points, then connecting back to the first point, the ratio between the area and the final line segment's length is also an indicator for the gesture's "edginess"
If you are just interested in up/down/left/right, a first approximation is to check 45 degree segments of a circle. This is easily done by checking the the horizontal difference between (successive) points against the vertical difference between points.
Say you have a greater positive horizontal difference than vertical difference, then that would be 'RIGHT'.
The only difficulty then comes for example, in distinguishing UP/DOWN from UP/RIGHT/DOWN. But this could be done by distances between points. If you determine that the mouse has moved RIGHT for less than 20 pixels say, then you can ignore that movement.

Resources