Register to reply

Changing sinewave

by btb4198
Tags: sinewave
Share this thread:
sophiecentaur
#19
May18-14, 04:59 PM
Sci Advisor
PF Gold
sophiecentaur's Avatar
P: 11,909
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.)
MikeGomez
#20
May18-14, 05:58 PM
MikeGomez's Avatar
P: 211
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)

Click image for larger version

Name:	Sine2.jpg
Views:	1
Size:	10.4 KB
ID:	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.
Simon Bridge
#21
May18-14, 07:39 PM
Homework
Sci Advisor
HW Helper
Thanks ∞
Simon Bridge's Avatar
P: 12,434
Quote Quote by btb4198 View Post
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?!


Quote Quote by btb4198 View Post
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.

Quote Quote by btb4198 View Post
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.

Quote Quote by MikeGomez View Post
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.
MikeGomez
#22
May18-14, 08:04 PM
MikeGomez's Avatar
P: 211
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.
btb4198
#23
May18-14, 09:31 PM
P: 243
Quote Quote by sophiecentaur View Post
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"
btb4198
#24
May18-14, 09:33 PM
P: 243
Quote Quote by MikeGomez View Post
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)

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
btb4198
#25
May18-14, 09:35 PM
P: 243
@ 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
Simon Bridge
#26
May18-14, 10:20 PM
Homework
Sci Advisor
HW Helper
Thanks ∞
Simon Bridge's Avatar
P: 12,434
Quote Quote by btb4198 View Post
@ 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?
btb4198
#27
May19-14, 02:58 AM
P: 243
I did not have the absolute value before, but when i added it, it remove some of the low frequency.
Simon Bridge
#28
May19-14, 05:05 AM
Homework
Sci Advisor
HW Helper
Thanks ∞
Simon Bridge's Avatar
P: 12,434
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.
btb4198
#29
May19-14, 07:12 AM
P: 243
like that
http://en.wikipedia.org/wiki/Isochronic_tones
btb4198
#30
May19-14, 07:14 AM
P: 243
I am trying to make an Isochronic Tone generator
sophiecentaur
#31
May19-14, 01:58 PM
Sci Advisor
PF Gold
sophiecentaur's Avatar
P: 11,909
Quote Quote by btb4198 View Post
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?
sophiecentaur
#32
May19-14, 04:08 PM
Sci Advisor
PF Gold
sophiecentaur's Avatar
P: 11,909
This looks to me like Amplitude Modulation. Is there any more to it than that?
MikeGomez
#33
May20-14, 04:04 AM
MikeGomez's Avatar
P: 211
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.

Click image for larger version

Name:	why2.jpg
Views:	10
Size:	79.8 KB
ID:	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.
btb4198
#34
May20-14, 09:11 AM
P: 243
Quote Quote by MikeGomez View Post
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.

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



        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;
    }


Register to reply

Related Discussions
Oscillations of a vehicle driving on a sinewave ground Engineering, Comp Sci, & Technology Homework 5
Qustion on sinewave Precalculus Mathematics Homework 4
High frequency square to sinewave convertor Electrical Engineering 14
Sinewave term not specific? Calculus 2
Using the EKF for estimating a noisy sinewave Astronomy & Astrophysics 0