Changing Sinewave Frequency: Can it be Done?

  • Thread starter btb4198
  • Start date
In summary: Beat > 0); double Frequency4 = Convert.ToDouble(FREtx4.Text); double Amplitude4 = Convert.ToDouble(PeakTXT4.Text); if (Amplitude4 > Amplitude3)
  • #1
btb4198
572
10
I know that sinewaves have two part to them a positive frequency and neg frequency.

I am out put a sinewave 0.05 * (sine(1000 *t 2*pi*)/44100)

and I am get two frequencies but i only want one..

so can I change
sin x = 1/2 i (e^(-ix) - e^(ix) )

to

sin x = e^(ix)

so it would be
f(t) = 0.05 * (e^(i(1000 *t*2*pi))/4410)

would that just give me 1000Hz?
and not add any other Frequencies to it?
 
Physics news on Phys.org
  • #2
so can I change
sin x = 1/2 i (e^(-ix) - e^(ix) )

to

sin x = e^(ix)
No.

But I don't understand how you are getting two frequencies.
##y=A\sin \omega t: \omega = 2\pi f## ... only has the one frequency.

You could try: ##\sin\omega t = \Im [e^{i\omega t}]## ... that help?
 
  • #3
Are you worrying about the fact that use of a mathematical identity is giving you something unexpected in the 'real world? This is a common problem. Even the roots of a simple quadratic can have values that are impossible in practice.
It's is fine (very useful, in fact) to use the exponential version of a simple sinusoidal waveform but you need to bear in mind that the answers you get from your calculations often have an implied "real part of" in front of them. You can do all the calculations with sines and coses and never get involved with the exponential form but it gets very 'lumpy'.

The 'negative frequency' that your calculations imply has a reality when you amplitude modulate a carrier, where the sidebands are above and below the carrier frequency (positive and negative relative to it).
 
  • #4
If you're concerned with the negative frequency you may also chose to use a sine transform instead of a full Fourier transform.
 
  • #5
"If you're concerned with the negative frequency you may also chose to use a sine transform instead of a full Fourier transform."

what do you mean ?
 
  • #6
sophiecentaur said:
Are you worrying about the fact that use of a mathematical identity is giving you something unexpected in the 'real world? This is a common problem. Even the roots of a simple quadratic can have values that are impossible in practice.
It's is fine (very useful, in fact) to use the exponential version of a simple sinusoidal waveform but you need to bear in mind that the answers you get from your calculations often have an implied "real part of" in front of them. You can do all the calculations with sines and coses and never get involved with the exponential form but it gets very 'lumpy'.

The 'negative frequency' that your calculations imply has a reality when you amplitude modulate a carrier, where the sidebands are above and below the carrier frequency (positive and negative relative to it).

what do you mean by "The 'negative frequency' that your calculations imply has a reality when you amplitude modulate a carrier, where the sidebands are above and below the carrier frequency (positive and negative relative to it) "
 
  • #7
Simon Bridge said:
No.

But I don't understand how you are getting two frequencies.
##y=A\sin \omega t: \omega = 2\pi f## ... only has the one frequency.

You could try: ##\sin\omega t = \Im [e^{i\omega t}]## ... that help?

I am programing this...
I am using C# and the it always has a low frequency in it
 
  • #8
btb4198 said:
I am programing this...
I am using C# and the it always has a low frequency in it
Please show us the code that gives you two frequencies.

trig functions in C#
http://www.dotnetperls.com/cos-sin-tan
 
  • #9
Simon Bridge said:
Please show us the code that gives you two frequencies.

trig functions in C#
http://www.dotnetperls.com/cos-sin-tan

This is what I just tried
it did not work

Code:
 wavefile = new WaveFileWriter(save1.FileName, tone.WaveFormat);
                        double counter2 = 0;
                        double Frequency3 = Convert.ToDouble(FREtx3.Text);
                        double Amplitude3 = Convert.ToDouble(PeakTXT3.Text);
                        Beat = Convert.ToDouble(isochronictxt.Text);
                        if (Beat != 0)
                        {
                            Beat = (1 / Beat);
                        }
                        else
                        {
                            Beat = 0;
                        }
                        for (int n = 0; n < time; n++)
                        {
                            if (counter2 >= Beat)
                            {
                                for (int t = 0; t < 10000; t++)
                                {
                                    wavefile.WriteSample(0F);
                                    wavefile.WriteSample(0F);
                                    
                                }

                                counter2 = 0;
                            }
                            else
                            {
                             
                                Complex R  = Amplitude3 * (Complex.Exp((-Complex.ImaginaryOne * Math.PI * n *2D* Frequency3/ 44100D)));
                                wavefile.WriteSample((float) Math.Abs( R.Magnitude));

                                Complex L = Amplitude3 * (Complex.Exp((-Complex.ImaginaryOne * Math.PI * n * 2D * Frequency3/44100D)));
                                wavefile.WriteSample((float)Math.Abs(L.Magnitude));   
                                counter2 = counter2 + (1D / 44100D);     
                            }
                        }
                        wavefile.Flush();
                        wavefile.Dispose();
                        file.Add(save1.FileName);

I tired with an -I and without an I
both did not work
 
  • #10
OK - what is the code supposed to do?
In what way does it fail to do that?
 
  • #11
Simon Bridge said:
OK - what is the code supposed to do?
In what way does it fail to do that?

the play the same point over and over 0.5 it does not change, beside when I add the 0s
 
  • #12
this is what I am using now

:
Code:
                        wavefile = new WaveFileWriter(save1.FileName, tone.WaveFormat);
                        double counter2 = 0;
                        double Frequency3 = Convert.ToDouble(FREtx3.Text);
                        double Amplitude3 = Convert.ToDouble(PeakTXT3.Text);
                        Beat = Convert.ToDouble(isochronictxt.Text);
                        if (Beat != 0)
                        {
                            Beat = (1 / Beat);
                        }
                        else
                        {
                            Beat = 0;
                        }
                        for (int n = 0; n < time; n++)
                        {
                            if (counter2 >= Beat)
                            {
                                for (int t = 0; t < 10000; t++)
                                {
                                    wavefile.WriteSample(0F);
                                    wavefile.WriteSample(0F);
                                    
                                }

                                counter2 = 0;
                            }
                            else
                            {
                             
                                Complex R  = Amplitude3 * (Complex.Sin((Math.PI * n *2D* Frequency3/ 44100D)));
                                wavefile.WriteSample((float) Math.Abs( R.Magnitude));

                                Complex L = Amplitude3 * (Complex.Sin((Math.PI * n * 2D * Frequency3/44100D)));
                                wavefile.WriteSample((float)Math.Abs(L.Magnitude));   
                                counter2 = counter2 + (1D / 44100D);     
                            }
                        }
                        wavefile.Flush();
                        wavefile.Dispose();
                        file.Add(save1.FileName);

and this is how it looks on a graph :
why.jpg
 
  • #14
Also is did try
Math.Sin()
it did the same thing
 
  • #15
I can't help but wonder why the OP is tackling this with a computer (numerical) approach. It just adds another layer if possible errors and misunderstanding. What is wrong with doing it analytically? Hopping about amongst digital models will always bring in the possibility of problems.
 
  • #16
Just use Y = sin(theta). You don’t need to complicate anything by using Euler’s formula.

btb4198 said:
I know that sinewaves have two part to them a positive frequency and neg frequency.

No. Sine waves only have one frequency, but the output value (amplitude) of a sin function like your C# function has a peak to peak range from -1 to +1.

That’s because the trig functions are based on a unit circle (radius 1) centered at the origin of a given coordinate system (i.e. circle centered at 0,0). Both the x and y components of all the points on the circumference of that circle range from negative one to positive one.

You can scale that range to anything you like, such as 0.05 as you did in your original post. Then you have

Y = 0.05 * sin( t * some_number);

Where some_number = 1000 * 2 * pi / 44100;

This will give you a range from -0.05 to positive 0.05. If you don’t want negative values for some reason, you can translate the waveform by adding 0.05, so your formula is

Y = (0.05 * sin( t * some_number) ) + 0.05;

That will give you a positively biased sin wave with values ranging from 0 to 0.1. However, since this is being used for an audio type application, you should not be concerned with negative values. They will work just fine, and that is probably what you want anyway.

------------------------------------------------------------------------------------------

Here is a hint for making you code work.

1: To start out, forget about the input frequency, amplitude, and beat, and also leave out the counter, beat code. Just hard-code some frequency and amplitude sine wave and get that to work.

2: When that works, switch over to using the input frequency and amplitude and get that to work.

3: When that works add the beat code and make that part work.
 
  • #17
sophiecentaur said:
I can't help but wonder why the OP is tackling this with a computer (numerical) approach. It just adds another layer if possible errors and misunderstanding. What is wrong with doing it analytically? Hopping about amongst digital models will always bring in the possibility of problems.

I think he is trying to program something, not trying to analyse something. It's as if he is given some user specified input for frequency and amplitude, and it is his job to play it back via computer.
 
  • #18
So it's a programming problem and nothing fundamental?
 
  • #19
Why not work out the answer 'properly' and then use a program to produce the figures for the output? In a straightforward case like this, the code is very easy to write and you don't need to be doing any 'DSP' tricks. (It is also a good way of understanding the basics.)
 
  • #20
Ok, I listened to the .wav file and it sounds fine. How is it different from what you were expecting?

If you are concerned about that kind of a ‘click’ to the sound, it’s probably because you are enveloping a sine wave inside of (basically) a square wave. In other words (aside from some slight sawtooth effect) each pulse or burst goes straight from 0 to full volume, and then cuts off from full volume to zero.

The square wave itself is composed of many frequencies (odd harmonics). You can probably alleviate all that by modifying the code to include a volume ramp-up at the beginning of each pulse, and also a ramp-down at the end.

[Edit] (deleted)

Sine2.jpg


Picture of sine wave vs absolute value of sine wave. Not completely sure if there will be much difference in the sound of the audio, but if I were you I would take out the absolute value just to give it a try.
 
Last edited:
  • #21
btb4198 said:
the play the same point over and over 0.5 it does not change, beside when I add the 0s
What is the program supposed to do though?!
btb4198 said:
this is what I am using now
...
and this is how it looks on a graph :
... what were you expecting it to look like?
note: for a graph to make sense, you have to say what the axes represent.

btb4198 said:
Also is did try
Math.Sin()
it did the same thing
... if you are expecting a sine wave output with an audio frequency, then you are certainly doing it wrong. It has nothing to do with two frequencies or anything.
Did you use the Math.Sin() the way the link I gave you does?

The graph you get looks like it wants to be a sine wave but there are bits missing from it.
Your program has a condition where you are setting the value to zero.
Re-examine those conditions.

But you have to tell us what the program has to do before we can help you properly.
I can see that Enlish is not your first language - don't worry, we are used to that. Just give it your best try to tell us what you are supposed to be doing.

MikeGomez said:
It's as if he is given some user specified input for frequency and amplitude, and it is his job to play it back via computer.
I have a feeling this is the case too.

I suspect the program is setting large blocks of zeros which is giving a chopped sine wave.
The remaining bits could act like two or three superimposed signals (2 bars and a triangle).

[edit] did not listen the the audio file - but I suspect you are on the right path.
I'll leave you to it.
 
  • #22
Now that I’ve thought about this a bit more, I have decided that although the absolute value sine wave might sound ok if we could hear it exactly like that, there is no way to reproduce that in the real world. In the real world there is hysteresis in the speaker coil, and momentum in the speaker head, etc, and you will not be able have the signal switch from a straight downward slope to a straight upward slope instantaneously.

Do take out the absolute value function, and smooth the signal edges at ramp up and ramp down, then see if you still have any more problems.

Ok, I’ll shut up now (unless the OP ever responds again, heh heh).

@Simon
He puts the zeros in there as padding. That turns the audio on/off as a beat mechanism. I am no audio engineer, so if others have input that would be good, but as I indicated at this point it’s not clear whether the OP is still interested or not so I guess we’ll just wait and see.
 
  • #23
sophiecentaur said:
Why not work out the answer 'properly' and then use a program to produce the figures for the output? In a straightforward case like this, the code is very easy to write and you don't need to be doing any 'DSP' tricks. (It is also a good way of understanding the basics.)

I am not sure what you mean by "work out the answer 'properly"
 
  • #24
MikeGomez said:
Ok, I listened to the .wav file and it sounds fine. How is it different from what you were expecting?

If you are concerned about that kind of a ‘click’ to the sound, it’s probably because you are enveloping a sine wave inside of (basically) a square wave. In other words (aside from some slight sawtooth effect) each pulse or burst goes straight from 0 to full volume, and then cuts off from full volume to zero.

The square wave itself is composed of many frequencies (odd harmonics). You can probably alleviate all that by modifying the code to include a volume ramp-up at the beginning of each pulse, and also a ramp-down at the end.

[Edit] (deleted)

View attachment 69894


Picture of sine wave vs absolute value of sine wave. Not completely sure if there will be much difference in the sound of the audio, but if I were you I would take out the absolute value just to give it a try.

The low frequency, that should not be there. if you listen to the file, it comes and go... and it get louder and lower, like a sinwave
 
  • #25
@ simon
"What is the program supposed to do though?!"
is supposed to play a tone at on a beat.. but it should not have the low frequency in it
 
  • #26
btb4198 said:
@ simon
"What is the program supposed to do though?!"
is supposed to play a tone at on a beat.. but it should not have the low frequency in it
Are you supposed to end up with a waveform audio format file that, when played, produces a pure tone?

The wave form you had on your graph looks like most of a half-wave with chunks missing - and repeated.

Now what do you need the graph of the wave to look like?

Note: this step-by-step approach is how you troubleshoot projects.

Have you tried Mike's advise about the absolute value?
 
  • #27
I did not have the absolute value before, but when i added it, it remove some of the low frequency.
 
  • #28
Are you supposed to end up with a waveform audio format file that, when played, produces a pure tone?
Now what do you need the graph of the wave to look like?

If you do not tell us what the program is supposed to do we cannot help you.
If you do not answer questions we cannot help you.
 
  • #30
I am trying to make an Isochronic Tone generator
 
  • #31
btb4198 said:
I am not sure what you mean by "work out the answer 'properly"

What I meant was that the answer to your original question is obtainable in analytical form - giving an analytical expression that you could evaluate in one go and produce your output sample data. It strikes me that you are doing the processing the 'hard way' - and the code is letting you down. If you were dealing with an unspecified input then you would need to do it the 'DSP way' (as you are doing) but, as it's all internally generated, you should be able to calculate the final sample values in one straightforward evaluation.
How sure are you that the basic operation you are trying to do is valid and represents what you want to achieve?
 
  • #32
This looks to me like Amplitude Modulation. Is there any more to it than that?
 
  • #33
OK, I found out what is going on. Your pulses are way too short in relation to the main frequency that you are modulating. I have filled in the absolute valued sine wave from the graphic that you provided in green to give you an idea.

why2.jpg


Do you need help with the math? Assuming (based on your code) that is your playback sample rate is 44100, and your playback frequency is 1000 hz, then you should find 1000 complete sine wave cycles for each second, or one sine wave every 44.1 samples. If you pulse that once per second you should get 500 complete cycles within each pulse.
 
  • #34
MikeGomez said:
OK, I found out what is going on. Your pulses are way too short in relation to the main frequency that you are modulating. I have filled in the absolute valued sine wave from the graphic that you provided in green to give you an idea.

View attachment 69918

Do you need help with the math? Assuming (based on your code) that is your playback sample rate is 44100, and your playback frequency is 1000 hz, then you should find 1000 complete sine wave cycles for each second, or one sine wave every 44.1 samples. If you pulse that once per second you should get 500 complete cycles within each pulse.

Yes I need help with the math.
also I just learned that my wave is all wrong. I have an program that picks up sound wave and does an FFT. I know that program works because I tested it with this site
http://onlinetonegenerator.com/?freq=5000

but when I play my tone generator the Freg are a little over 2 time what it should be.. why?

here is my code

Code:
        int sampleRate = WaveFormat.SampleRate;
        if (Beat == 0)
        {
            f2 = 0;
        }
        else
        {
            f2 = Frequency - Beat;
        }
        for (int n = 0; n < sampleCount; n++)
        {
            buffer[n + offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate)) + (float)(Amplitude * Math.Sin((2 * Math.PI * sample * f2) / sampleRate));
            sample++;
            if (sample >= sampleRate) sample = 0;
        }
        buffer1 = buffer;
        return sampleCount;
    }
 

1. Can the frequency of a sinewave be changed?

Yes, the frequency of a sinewave can be changed. This can be done through various methods such as using electronic circuits or software algorithms.

2. What is the purpose of changing the frequency of a sinewave?

The purpose of changing the frequency of a sinewave can vary depending on the application. It can be used to modulate signals, generate different tones in audio equipment, or control the speed of motors.

3. Is it possible to change the frequency of a sinewave without altering its amplitude?

Yes, it is possible to change the frequency of a sinewave without altering its amplitude. This can be achieved by using frequency modulation techniques.

4. Are there any limitations to changing the frequency of a sinewave?

There are some limitations to changing the frequency of a sinewave. The maximum frequency that can be achieved depends on the capabilities of the equipment used and the frequency range of the sinewave.

5. Can the frequency of a sinewave be changed indefinitely?

No, the frequency of a sinewave cannot be changed indefinitely. There are practical limitations such as the frequency range of the equipment and the physical limitations of the components used to generate the sinewave.

Similar threads

  • Electrical Engineering
Replies
10
Views
2K
  • Other Physics Topics
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
203
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
Replies
5
Views
312
  • Other Physics Topics
Replies
5
Views
9K
  • Introductory Physics Homework Help
Replies
3
Views
160
  • Atomic and Condensed Matter
Replies
10
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
Back
Top