Thread: need help with program

  1. #1
    Registered User
    Join Date
    Nov 2003

    need help with program

    program is this

    It is the purpose of this project to create the tones of a DTMF phone. The frequencies used for each key are described at , a java applet is given at
    Assume a sampling frequency of 8 kHz and an amplitude of 1 for each sinusoid. Write a program that asks the user to input a phone number. Assume that the tones for each digit are hold for 0.1 seconds. Declare an array that can hold up to 1 second of samples. Then write a function that reads in a digit and fills the array from index n to index m. Use this function in a loop to create the total sequence. At the end of your program all values should be stored in one array. For test purposes, output the index and the value of the array at the index on the screen.

    I finished with inserting phone number and outputing them. I need help with equation. Teacher want me to output 8000numbers for each digits(for sine wave). I asked my teacher but all he told me was to use "sample=sin(n*2*pi*f1/samplerate)+sin(n*2*pi*f2/samplerate). I tried that on my program but only getting one answer.
    is this mean i have to do
    for loop for sample rate that goes 0~8000 for equation above?

    for example
    for (index=0;index<8000;index++)

    Thank your for reading
    Last edited by jp82; 11-12-2003 at 02:27 PM.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    It looks like your samplerate should be 8000, and n should count from zero to 8000.

    Don't change samplerate to index in the formula. You don't need a variable called "index". n is the index variable.

    Actually, 8000 samples will give you a full second at 8kHz. You only need 800 samples (n = 0 to 800) for 0.1 second.

    EDIT 2:
    The problem is that you have mixed-up sample-rate and sample-number (or index-n). The sample-rate is constant at 8000. Hz is cycles-per-second. So, at time = 0.1 seconds, you are at sample #800 (n=800).

    The formula will give you the ampltude for any sample number n. i.e sample[n]. If you want to know the instantaneous amplitude at sample #400, you plug 400 into the formula. This is the same as amplitude at 0.05 seconds (400/8000).

    The variables in the given formula are a bit confusing. The variable sample is actually the amplitude at sample #n.
    Last edited by DougDbug; 11-12-2003 at 04:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM