-
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 http://www.hut.fi/~then/mytexts/dtmf_generation.html , a java applet is given at http://www.dsptutor.freeuk.com/dtmf/TG102.html
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
while()
{
for (index=0;index<8000;index++)
sample=sin(n*2*pi*f1/index)+sin(n*2*pi*f2/index).
cout<<sample;
}
Thank your for reading
-
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.
EDIT:
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.