Is there an algorithm to calculate average temperature by latitude? I googled for a long time but could only find this (source):
T = To – a.sin^2λ
Where
T = Temperature
To = Average equatorial temperature
a = a constant
λ = latitude.
But I have several problems with this:
There is no mentioning of a source
It's not mentioned what a is or what its value is
Is the dot between a and sin ("a.sin") meant to be a
multiplication sign?
So I was wondering if someone can explain if this algorithm is correct or if there is a better one, or none at all.
I found a confirmation for a basic relation of latitude and temperature here:
I could use a lookup table (but I would have to generate it by some algorithm anyway), but I'd rather have a realtime calculation for certain reasons.
So does anyone know if the algorithm above is correct, and can explain what the dot means?
I would like to implement this in C#, but any language with a C-like syntax would be fine for me.
Bonus question: Any chance to cover precipitation in a similar way?
Thanks in advance!
Firstly, what you've given and are looking for is more of a formula than an algorithm, while you could argue it was an algorithm, algorithms usually refer to calculations involving conditionals or separate steps, not just a single non-complex calculation.
No, there is no such formula. To have a formula for average temperature would involve simulation all of the meteorological system.
Approximations are entirely possible however and that's what the above formula is. The dot in this instance is multiplication, the * operator in c#.
It should also be noted this is not the correct stack exchange for this question, the physics stack exchange would be more appropriate.
Related
I'm looking for a simple implementation of total least squares.
Or any other way to approximate a line from a set of points that doesn't discriminate between the x- and y-axes.
I have been able to find some scientific papers about it, but since it seems to be such a simple and common problem, I thought that there would be some good library or example code available somewhere.
I will have to write this in C#, but I can translate from similar languages.
Wikipedia lists a simple calculation for the approximation
in the picture.
Deming regression
The problem is still treated as 1D, so it's necessary to handle the special
case of a vertical line. Swapping x for y resolves this.
Using a δ of 1 is totally fine since we're only looking for minimizing the euclidean distance to the line.
Note: The equation also breaks down for horizontal lines. Then Sxy will be zero.
I'm looking for a way to quickly get the results for a mathematical equation. Take "0.5 * sin(x) + 3" for example. The Google calculator can easily give me an exact result for HUGE values, but my C# application will stutter when drawing a graph in high value ranges or even give me an overflow. How do I solve this?
Thanks in advance!
Hi I'm a noob in audio related coding and I'm working in a pitch tracking DLL that I will use to try to create a sort of open-source version of the video-game Rocksmith as a learning experience.
So far I have managed to get the FFT to work so I can detect pitch frequency (Hz) then by using an algorithm and the table below I can manage to determine the octave (2th to 6th) and the note (C to B) for played note.
The next step is to detect the string so I can determine the fret.
I've been thinking about it and in theory I can work with this, I will know when the user is playing the right note but the game could be "Hack" because by just using the Hz the game is not able to detect if a note is played in the right string. For example 5th string + 1th fret = C4 261.63Hz is equals to 6th string + 5th fret = C4 261.63Hz.
The chances of having an user playing a note in the wrong string and getting it right is low, but I think it would be really good to know the string so I can provide to the users some error feedback when they play the wrong string (Like you should go a string up or down).
Do you know what can I do to detect the string? Thanks in advance :)
[edit]
The guitar and strings that we are using affect the timbre so analyzing the timbre seems to not be a easy way of detecting strings:
"Variations in timbre on your guitar are produced by an enormous number of factors from pickup design and position, the natural resonances and damping in your guitar due to the wood used (that's a different sort of timber!) and its construction and shape, the gauge and age of your strings, your playing technique, where you fret and pluck the string, and so on."
This might be a little bit late because the post is one years old. But here's a solution, which I found out after long research for pitch detecting a guitar.
THIS IS WHY FFT DOESN'T WORK :
You cannot use FFT since the result gives you a linear array, and the sound is calculated logarithmically (exponential distance between notes). Plus, FFT gives you an array of bins in which your frequency COULD BE, it doesnt give you the precise result.
THIS IS WHAT I SUGGEST :
Use dywapitchtrack. it's a library that uses a wavelet algorythm, which works directly on your wave instead of calculating large bins like FFT.
description:
The dywapitchtrack is based on a custom-tailored algorithm which is of very high quality:
both very accurate (precision < 0.05 semitones), very low latency (< 23 ms) and
very low error rate. It has been thoroughly tested on human voice.
It can best be described as a dynamic wavelet algorithm (dywa):
DOWNLOAD : https://github.com/inniyah/sndpeek/tree/master/src/dywapitchtrack
USE(C++):
put the .c and .h where you need it and import it in your project
include the header file
//Create a dywapitchtracker Object
dywapitchtracker pitchtracker;
//Initialise the object with this function
dywapitch_inittracking(&pitchtracker);
When your buffer is full (buffer needs to be at 44100 resolution and power of 2 of length, mine is 2048):
//use this function with your buffer
double thePitch = dywapitch_computepitch(&pitchtracker, yourBuffer, 0, 2048);
And voilà, thePitch contains precisely what you need. (feel free to ask question if something is unclear)
An simple FFT peak estimator is not a good guitar pitch detector/estimator, due to many potentially strong overtones. There exist more robust pitch estimation algorithms (search stackoverflow and DSP.stackexchange). But if you require the players to pre-characterize each string on their individual instruments, both open and fretted, before starting the game, an FFT fingerprint of those characterizations might be able to differentiate the same note played on different strings on some guitars. The thicker strings will give off slightly different ratios of energy in some of the higher overtones, as well as different amounts of slight inharmonicity.
The other answers seem to suggest a simple pitch detection method. However, it is something you will have to research.
Specifically, compare the overtones of 5th string 1st fret to sixth string 5th fret. that is, only look at 261.63*2, 261.63*3, *4, etc. Also, try looking at 261.63*0.5. Compare the amplitudes of the two signals at these freqs. There might be a pattern that could be detected.
I'm about to create a terrain for a mobile game which allows a huge terrain which is mostly limited by the available hardisk space.
This requires to keep the floating points limited to a "after-point-precision" of 2 numbers.
What is a good approach to keep it at the precision of 2 numbers after the point?
Remember: I'm running on a mobile device, so the method should be fast and easy to use and should be applicable to any arithmetic which is needed for games.
More information
I'm not talking about space( i know how much space a float takes guys, really ), i'm talking about the issue that i loose precision when my floating point is going to have to many numbers after the decimal point.
Using a int would cause that i've to convert the int into a float each frame. I don't know how fast the conversion is but this seems to cost a lot of performance when doing it for a lot of objects. ( Remeber i'm on a mobile device ).
Of course i'm also not talking about the terrain, i'm talking about objects in the terrain! The terrain is a specialized system which actually can hold a terrain size which extends the limits of the floats a lot ( It's even possible to save north america in this system when you have enough disk space, but actually the limits are set to -99km to +99km ).
Edit 2
As usual in games the movement is timebased, means i need to multiply the speed of the object with a modifier given to me by unity, this corrupts my numbers which are limited to 2 numbers after the decimal point.
An interesting way would be to implement this into the movement function:
float result = //multiply force by time
float modulus = result%0.01f;
result -= modulus; //you will do this in any case
if(modulus>=0.005f) {/*round up. if you want it to only round down, remove
the next 2 lines, if you want it to only round up, remove
the conditional statement*/
result+=0.01f; }
I can't think about how to optimize it further, I removed the else statement and have it take away the modulus without condition as it will be done anyway.
Huh, doesn't matter what precision you choose to operate at they still take up the same amount of space. Single or double would make a difference, but the real question you should ask is do you need floating points at all. If you can fit the numbers in an int, do that.
I was looking for satisfactory and safe workaround to my double precision issue specified to this problem:
This program tries to find how many small circle can fit into a large circle. It fills the large circle and then culls those that intersect the large circumference. using this formula:
distance_small_pos_from_center + small_radius < big_radius
All calculations were in double, except for screen output on WinForms which takes int for coords.
The above image shows the result of the culling. You can see that it is not symmetric when it should really be because the constraint is that there must be one small circle exactly in the center. I step through the code and find that this is because some calculations yield, for example,
99.9999999 < 100
This answer C++ double precision and rounding off says we should use all the precision available, but in this case, I had to do a Math.Round(distance_small_pos_from_center + small_radius, 3) using 3 arbitarily.
The result of the culling differs very much without Math.Round. In retrospect, this is one kind of bug that is hard to detect if I had not drawn it out. Maybe I did something wrong, or didn't understand doubles as much as I thought I had.
So, anyone has solutions or tips to avoid this kind of problem?
Sorry for not beeing able to provide a complete answer to your question, but i have no time for that right now. But when you compare floats, compare them with a "tolerance" since a float is not exact.
EDIT: modified with abs() in case you don't know which is big and small, as pointed out by Hans Kesting
Ie, do something like if(abs(big_radius - distance_small_pos_from_center) < epsilon) where epsilon is your tolerance, selected with consideration to how "inexact" the floats will be in the range where you are working..
For more precise information see:
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html
http://www.cplusplus.com/forum/articles/3638/
Use System.Decimal:
http://msdn.microsoft.com/en-us/library/system.decimal.aspx