|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Harmonics? (Use of formulas)
Hey,
I need to write a program that takes two integers(input) and implements the following formulas to output two other integers. f2 = f*n k = floor(lg2 (f2/440) ) starting_note = 440 * 2^k (read: 2 to the k'th power) s = 12 * lg2 (f2/starting_note) ------------------------------------------- f2=frequency of the n-th harmonic f=original frequency n=harmonic number k=octave of the n-th harmonic of the string s=note for frequency f2 starting_note=starting note of k In words: We already know that the frequency of the n-th harmonic is f2 = n * f, where f is the original frequency. The octave k of frequency f2 is floor(lg(f2/440)), where floor(x) is the greatest integer less than or equal to x and lg(x) is log to the base 2 of x. To calculate the note s for frequency f2, you must first compute the starting note of that octave by calculating starting_note = 440 * 2k. Then the actual note s = 12 * lg(f 2/ starting_note) rounded to the nearest integer. Wanted output: * The octave of the n-th harmonic of the string, k * An integer in the range 0,...,11 representing a note of the scale, s Enter the frequency of a string, f: 680 Enter the harmonic number, n: 2 The octave of harmonic 2 is 1. The note of the scale is 8. Now this is what I have so far: import java.util.Scanner; public class Harmonics { public static void main(String args[]) { System.out.printf("Enter the frequency of a string f:"); Scanner f = new Scanner(System.in); double freq = Double.parseDouble(f.nextLine()); System.out.printf("Enter the harmonic number, n:"); Scanner n = new Scanner(System.in); double harm = Double.parseDouble(n.nextLine()); } } That of course is the input. I need to know how to implement the formulas. I don't even know where to start. I'm thinking possibly a series of If statements? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Harmonics? (Use of formulas) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|