Math behind tone generator with Beats

  • Thread starter btb4198
  • Start date
  • Tags
    Generator
In summary, you need two sine waves with different frequencies to create a beat. The beat needs to be 180 Hz. The amplitude and frequency of the beat need to be correct for the desired frequency.
  • #1
btb4198
572
10
ok this is an example:
Frequency = 180 Hz
Amplitude = 0.5 db
Beat = 4 Hz
waveform sampling rate is 44100 Hz

ok

1) Which the information above, does that mean that every 11025 samples there should be an beat ( meaning 0 s) ? The math I used was number for sample = (1D / Beat) / ( 1D/44100D)

2) if I solve for λ( wavelength) and make sure I do not start adding 0s before the λ starts again will that stop noise/ distortion in my tone ? I get ticks in my wave files, but if I do not interrupt the λ there should be no distortion or ticks right ?

3) From the information above λ should be (1/44100) / (180)
λ= 1.2597631645250692869740488788108e-7s
λ ( wavelength) = C/ F
 
Engineering news on Phys.org
  • #2
I am confused by the question, you have not explained your setup.

Are you using sine waves or logical 0 and 1 square waves?

You must differentiate between wavelength and period = 1 / frequency. Wavelength is a velocity and so requires a transmission medium. Period is just the time for one cycle.

If your waveform record contains multiples of one cycle, so the ends line up, it should not produce beats or clicks.
 
  • #3
I am using an Sine wave.

f(t) = Amplitude * Sin(PI * Frequency * T / 44100D);

I am not using the period.
just the wavelength
λ ( wavelength) = C/ F
C in velocity
f is frequency

about the transmission medium... I am make a sound file to my medium would be air
how would I could up with my λ ?
my wavefile is set to 44100 Hz so I thought my C ( velocity would be (1/44100) s
is that not right ?
 
  • #4
Have a look at the Interference beats and Tartini tones page for the math.

beatsmall.gif


There are ".wav" sound files of beating sine waves you can download and/or listen to plus interactive video clips.

This is just one page from http://www.animations.physics.unsw.edu.au/
 
  • #5
" 1) Which the information above, does that mean that every 11025 samples there should be an beat ( meaning 0 s) ? The math I used was number for sample = (1D / Beat) / ( 1D/44100D)"
Is this right ?

or is there another equation I should use?
 
  • #6
dlgoff said:
Have a look at the Interference beats and Tartini tones page for the math.

beatsmall.gif


There are ".wav" sound files of beating sine waves you can download and/or listen to plus interactive video clips.

This is just one page from http://www.animations.physics.unsw.edu.au/

ok I looked at those site
and i try to make some for the beats...
but how do i make a beat for 4 Hz that goes down to 0 ? and not just close to 0 ?
so like F(t) = 10 sin( π * 180 * t / 44100 ) + 5 sin( π * 184 * t/44100)
how different should the Amp how to be to get 0 ?
 
  • #7
btb4198 said:
F(t) = 10 sin( π * 180 * t / 44100 ) + 5 sin( π * 184 * t/44100)...
Now I think I kinda see what you're asking.

The coefficients of the two waves are not equal in this case (10 and 5), so the resultant will look something like this.

Figure_17_10_04a.jpg


Image compliments of http://cnx.org/content/m42249/latest/

Here's an interactive applet that will show how this works.

http://www.eserc.stonybrook.edu/ProjectJava/WaveInt/index.html
 
  • #8
so what should the function be ?
 
  • #9
how would the function look to make it go down to zero ?
does the two sinewave have to be 150 degrees out of phase ? to get 180 hz at a 4hz beat ?
I need it to drop down to 0
 
  • #10
does anyone know how to ?
 
  • #11
I am still totally confused about what you are trying to do. At the moment I think that is because you are not explaining your requirement in technical terms with exact meanings.

Two sine waves, with different frequencies, will not have a fixed phase. Their phase difference will rotate continuously, that phase difference is a beat between the two waves.

What do you mean by “go to zero” ? What should go to zero ?
If you can draw and post a plot of the signal you want, someone here will give you an equation.

You are assuming the world is simple and that we can easily guess what you mean.
We know the world is complex and have no idea which answer of the 100s available you are wanting.

Maybe you should define the setup you are using and then ask one question. We will then question you about your meaning, then progressively revise your setup description and question until we understand each other. You will then have the answers you need.
 
  • #12
What is your definition of a beat?

Can you write an equation for a modulated sine wave? AM Modulate a 1000 Hz sine wave with a 4 Hz sine wave (or triangle wave, or squarewave. This is multiplication.

Can you write equations for summing two sine waves of different frequencies and solve for the times when the sum is zero?

You need to precisely define the content you want. Is it a single sinewave (1 frequency) that varies in amplitude? Is it two frequencies that "beat" with each other? If it is two frequencies that "beat" at 4 hz, then they need to be 4 Hz apart in frequency (like when someone tunes a guitar by getting the "beat" to 0 Hz)

If it is 1 frequency that varies in amplitude, what is the precise definition of the amplitude controlling waveform.

You keep asking the same thing over and over without defining your terms.
 
  • #13
I am tying to make an Isochronic tones. " are regular beats of a single tone used for brainwave entrainment. Similar to monaural beats, the interference pattern that produces the beat is outside the brain so headphones are not required for entrainment to be effective. They differ from monaural beats, which are constant sine wave pulses rather than entirely separate pulses of a single tone."

http://en.wikipedia.org/wiki/Isochronic_tones#mediaviewer/File:Isochronic-toes.svg

The picture make it look like it drop down to 0 during the beat. I am trying to get a to do that without any tickles ... and I have trying fating in but that is not working... I still get a tick.

does anyone have an Isochronic algorithm?

I have been looking everywhere and I can't find one...
the only useful information I found on it, is from that wiki and as you can tell it is not that useful ...
 
  • #15
Baluncore and meBigGuy do you understand what I am asking now ?
 
  • #16
Yes, you need bursts of a single frequency sine wave, so you multiply a sinewave by what looks like a trapezoidal window to get alternating bursts of tone and quiet. The ramp at the ends of the trapezoidal window prevent clicks being produced.

It is hard to write a window function in a single line, but a multi-line way is to use the positive part of a sinewave near y=0. If k is 1 then the pulses have a sinewave profile, as k increases, say 3, the trapezoidal window starts to appear and becomes steeper and more clicky with higher k values.

w(t) = k * sin( t * 2*Pi * 4Hz )
if w(t) < 0 then w(t) = 0
if w(t) > 1 then w(t) = 1
f(t) = w(t) * Amplitude * Sin(PI * Frequency * T / 44100D);
 
  • #17
I don't understand what you find difficult about modulating a sine wave with another waveform. You have been at this for a long time.

Just modulate a 100Hz sine wave with a 1 hz sine wave. Can you write the basic equation for that (multiplying 2 sine waves). Then debug that. You know exactly what it should look like.

Generate a 100 Hz sine wave. Look at it.
Generate a 1 Hz sine wave. Look at it.
Multiply them together. Look at it.

I don't understand how you can say "it ticks" and expect people to figure out what that means. There are all sorts of reasons it might do something that you call a tick. LOOK AT THE WAVEFORM AND FIGURE OUT WHAT YOU ARE DOING THAT MAKES IT DIFFERENT THAN WHAT YOU EXPECT TO SEE!

Once you can modulate a sine wave, you can change the modulating signal to anything you wish. It that signal "ticks" then look at it and try to figure out what is wrong with the waveform. Many things could go wrong that would cause a tick. Fast slopes, missing samples, arithmetic overflow, etc. Look at the waveform and debug your code.
 
  • #18
Baluncore said:
Yes, you need bursts of a single frequency sine wave, so you multiply a sinewave by what looks like a trapezoidal window to get alternating bursts of tone and quiet. The ramp at the ends of the trapezoidal window prevent clicks being produced.

It is hard to write a window function in a single line, but a multi-line way is to use the positive part of a sinewave near y=0. If k is 1 then the pulses have a sinewave profile, as k increases, say 3, the trapezoidal window starts to appear and becomes steeper and more clicky with higher k values.

w(t) = k * sin( t * 2*Pi * 4Hz )
if w(t) < 0 then w(t) = 0
if w(t) > 1 then w(t) = 1
f(t) = w(t) * Amplitude * Sin(PI * Frequency * T / 44100D);

ok I change it like you said
I have to change a few things like I added /44100 to W(t)
I did that because without it I keep getting 0 and nothing would play
and I remove the 2... I have not had good lucky with adding 2s there.. this seem to double the Frequencies ...
so what do you think?
this is what i got:

Code:
[CODE]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NAudio.Wave;
using NAudio;

namespace Isochronic_tones_generator
{
    class isochronicTone : WaveProvider32
    {
        public isochronicTone()
        {
            Frequency = 1000;
            Amplitude = 0.25f;
            Beat = 0;
            n1 = 0;
        }
        int sample;
       static int n1;
        public float Frequency { get; set; }
        public float Amplitude { get; set; }
        public float Beat { get; set; }
        public override int Read(float[] buffer, int offset, int sampleCount)
        {
            int sampleRate = WaveFormat.SampleRate;
               for (int n = 0; n < sampleCount; n++)
                {
       float w = (float)(3D * Math.Sin( n1  * Math.PI * Beat /44100D ));
       n1++;
       if (w < 0)
       {
           w = 0;
       }
       if(w > 1)
       {
           w = 1;
       }

             float temp = (float) (w * Amplitude * Math.Sin(Math.PI * Frequency * n / 44100D));
             buffer[n + offset] = temp;
             sample++;
             if (sample >= sampleRate) sample = 0;
         }
               return sampleCount;   
    
        }
        
    }
}

[/CODE]
 
  • #19
I can't tell from your code what the signal looks or sounds like. Have you tried it ?

Since angular frequency, w, in radians per second is needed by the Sin(w) function, you will need to use w = (2 * Pi * freq_Hz * time / samples_per_sec) to correct the frequency from rad/sec to Hz.

The division by your sample rate is needed to interpolate the data points into the sample record.

Code:
Const Double TwoPi = 8 * Atn(1)
Integer sps = 44100  ' sample rate
Double Hz = 44      ' sine wave frequency
Double beat = 4      ' frequency of pulse envelope
Double k = 3         ' trapezoidal
Double w             ' window value
Double theta         ' precompute phase in sample record
Double a(0 To sps-1) ' data array for one second
Integer t            ' time

For t = 0 To sps - 1
    theta = TwoPi * t / sps
    w = k * Sin(theta * beat) 
    If (w < 0) Then w = 0
    If (w > 1) Then w = 1
    a(t) = w * Sin(theta * Hz)
Next t

See the attached is a 44 Hz tone in a 4 Hz envelope
 

Attachments

  • Isochronic.png
    Isochronic.png
    11.7 KB · Views: 554
  • #21
Yes, but are you happy with it ?
 
  • #22
Baluncore
yes, it sounds like the other file I posted. so that is good. sorry I am new to this...
that last code you posted, is that for matlab?
also I am not understanding " Since angular frequency, w, in radians per second is needed by the Sin(w) function, you will need to use w = (2 * Pi * freq_Hz * time / samples_per_sec) to correct the frequency from rad/sec to Hz.?
 
  • #23
Baluncore,

also how did you know it should be a trapezoidal waveform ?
and how did you come up with your code ?
 
  • #24
The original problem with understanding your requirement was because you referred to a “beat” as generated by the addition of two sinewaves, rather than the product of one sinewave by an envelope function.

The sine() and cosine() functions repeat every 360° or 2*Pi “radians”. That is one cycle.
One hertz, Hz, = one cycle per second, = 2 * Pi radians per second.
http://en.wikipedia.org/wiki/Radians

Notice that I get four bursts of tone per second for Hz = 4 in my code, the frequency is calibrated. I suspect you may be out by a factor of two, which is one musical octave. That may be because you did not initially understand mathematical angular measure, where 2*Pi radians = 360°.

The code I posted was not in any particular language, it was a way of writing a mathematical algorithm, in a cross between BASIC and FORTRAN. I do not like C { }.

btb4198 said:
also how did you know it should be a trapezoidal waveform ?
and how did you come up with your code ?
Experience. It must be a slow rise-time trapezoidal envelope to reduce the clicking sound of high frequencies present in a sudden step. I used part of a sine wave for the envelope because it was the easiest quick fix that would give control of the burst rate and envelope. There are other slightly better sounding solutions. I could see what was required by looking at your wiki link in post #13. I have been receiving and analysing RF signals that look like that for 35 years. My code was minimised because I avoided the complexities of implementation. I presented just enough code to show how the math works.
 
  • #25
Baluncore,

are you saying that code was not the best way to go, but just the easiest way to explain it? what would be the best way? 35 years wow...
what do you mean by " I used part of a sine wave for the envelope " ?
how are you defining envelope?
 
  • #26
The best way will never be delivered, the second best will be too late.
We can never have better than the third best.

Look at the code, w = k * Sin(theta * beat); If (w < 0) Then w = 0; If (w > 1) Then w = 1
Draw the sine wave graph on paper and apply the two conditional modifications to it.
Write some code to plot the envelope function, then play with the parameters, see and hear what the envelope edges sound like.
 
  • #27
Baluncore,

So I plugged the code into Excel and I am able to see the points better and now I see how it works.
A few questions

1) Before w = 1 do you have to do a(t) = w * Sin(theta * Hz)? Could you just do a(t) = w and then at w = 1 do a(t) = w * Sin(theta * Hz)? And at w =0 , a(t) = 0, or would that cause distortion in the waveform? Thinking about it now I think it might cause distortion, right? Because, you would be switching from one waveform to another? (Sorry, I am new to this).

2) I did (1/4Hz)/(1/44100Hz)
4hz being my beat
44100 Hz being my sampling rate
and I got 11025 samples. Meaning that is where the 0s should start and in Excel it did ! I got 3.67545E-16 with is 0 at the 11025 sample. so my question is this, I used 3 * SIN(C2 *PI() * 4 / 44100) and not 3 * SIN(C2 *2*PI() * 4 / 44100) and it seems to be right, so why is the 2 not working? When you read about waveforms online and in school they always have (2*pi* f) but when I use 2 I get the wrong information. I have an fft and when I would use the 2 I would get double my f. so why is that?
3) How did you come up with your K again? Is K the RMS value? K is Gain right?
4) What is an envelope function?
 
  • #28
4) The envelope does not have negative values so when it is multiplied by the tone it does not invert the tone. Effectively it amplitude modulates the tone. You need to plot the graph of the envelope function alone, then with the tone, so you can see how it all works. It is not something you can do in your head or a list of double precision numbers.

3) A simple sinewave has a slope of +/- 1, (per radian), as it crosses the x-axis. Multiplying by 3 steepens the crossing. Once it is steeper, I can throw out the negative part by clipping it at zero, and give it a flat top by clipping at 1. There are many possibilities for the envelope function, you could try something like w = 0.5 * (1 + Sin(2 * Pi * Hz / samples_per_second) ). That will have values of from 0 to 1.

2) I can't debug the code hidden in your computer. You must find out what is happening by plotting simple graphs such as a single cycle of a sine wave, then look at the picture and experiment. The factor of 2 time scale error will be a really simple bug, question everything fundamental that you trust. Questions you should ask are:- How long in time is the signal you generate? How many points do you generate? Are you generating (samples_per_second * seconds) data points?

1) You should plot the w value as a graph so you can play with the algorithm and see the effects.
 
Last edited:

FAQ: Math behind tone generator with Beats

What is a tone generator with beats?

A tone generator with beats is an electronic device that produces sound waves at specific frequencies to create musical tones. It also has the ability to produce beats, which are rhythmic pulsations that occur when two tones with slightly different frequencies are played together.

How does a tone generator with beats work?

A tone generator with beats works by using an oscillator to produce a continuous sine wave at a specific frequency. This signal is then sent to a mixer, where it is combined with another sine wave at a slightly different frequency. The resulting sound is a beat, which is created by the interference pattern between the two waves.

What is the math behind tone generator with beats?

The math behind tone generator with beats involves the use of trigonometric functions, particularly sine and cosine, to represent the oscillating sound waves. The frequency of the waves can be calculated using the formula f = 1/T, where f is the frequency and T is the period of the wave. The difference in frequency between the two waves determines the rate of the beats.

How do you calculate the beats per minute (BPM) for a tone generator with beats?

To calculate the BPM for a tone generator with beats, you first need to determine the difference in frequency between the two waves. This can be done by subtracting the lower frequency from the higher frequency. Then, multiply the frequency difference by 60 to convert it to beats per minute. For example, if the frequency difference is 10 Hz, the BPM would be 600 (10 x 60 = 600).

Can a tone generator with beats be used for scientific experiments?

Yes, a tone generator with beats can be used for scientific experiments, particularly in the field of auditory neuroscience. It can be used to study the perception of beats and their effects on brain activity and behavior. Additionally, it can also be used in physics experiments to demonstrate the principle of wave interference and resonance.

Similar threads

Replies
2
Views
4K
Replies
2
Views
3K
Back
Top