Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 30th, 2007, 03:03 AM
thename1000 thename1000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 2 thename1000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 20 sec
Reputation Power: 0
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?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Harmonics? (Use of formulas)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT