DSPRelated.com
Forums

Sine to square wave conversion

Started by Sharan123 October 14, 2015
>I'm not sure WHY you're squaring up your sine wave, but note that doing >so in a sample-time environment can lose you a lot of phase information >if the signal frequency is close to the sampling rate -- if you look at >it in the time domain it's obvious; if you're stuck in the frequency >domain then you have to go through a bunch of math to see why the way >that the harmonics alias cause the issue.
Dear Tim, I am not squaring the sine wave (sorry, if I was ambiguous). Actually, I am converting sine to square waveform .. --------------------------------------- Posted through http://www.DSPRelated.com
>In some cases I do wonder why the term "filter" is applied. "Filter" >tends to imply that something in the input gets passed while other >things in the input do not. Is the idea that x(t) = sgn(sin(wt)) >removes the amplitude information and lets everything else through? > >Terminology does seem to be a big problem in dsp. For example the >term "squaring a sin" has been used by multiple people in this thread. >Is that making a square wave out of a sine wave or is that sin^2(x)? >;)
Dear Eric, To be frank, I have had the same doubt and I had put this question in this forum. A filter intuitively means that something is removed and something is not. But I realized that probably that was a shallow co-relation I was making about filters. After a bit of thinking, I assume filtering does not always mean removal of signal components but can also mean removal of things like noise. So, if we use moving average as an example, the noise is reduced, though the power sort of gets distributed ... in this case, the noise is removed but the signal associated is not ... Anyway, that's my 2 cents ... --------------------------------------- Posted through http://www.DSPRelated.com
On Wed, 14 Oct 2015 19:45:14 -0400, robert bristow-johnson
<rbj@audioimagination.com> wrote:

<snip>

>i have a different embarrassing trial (tried it during a rehearsal) >thinking that we could put a resistor pad on the speaker output of the >guitar amp instead of micing it. > >i thought fer sher it would work.
OK, I'll bite: What was the problem? Of course it would have a different sound quality (absent the cabinet resonance, speaker response and nonlinearities, mic response, etc), but other than sounding "too clean" the only other things that come to mind are not having enough attenuation in the resistor pad, or maybe a ground reference problem (especially if the amp was in bridge mode). What was it? Best regards, Bob Masta DAQARTA v8.00 Data AcQuisition And Real-Time Analysis www.daqarta.com Scope, Spectrum, Spectrogram, Sound Level Meter Frequency Counter, Pitch Track, Pitch-to-MIDI FREE 8-channel Signal Generator, DaqMusiq generator Science with your sound card!
On 2015-10-14 23:29:53 +0000, robert bristow-johnson said:

> On 10/14/15 2:26 PM, Piergiorgio Sartor wrote: >> On 2015-10-14 19:55, Eric Jacobsen wrote: >> [...] >>> In some cases I do wonder why the term "filter" is applied. "Filter" >>> tends to imply that something in the input gets passed while other >>> things in the input do not. Is the idea that x(t) = sgn(sin(wt)) >>> removes the amplitude information and lets everything else through? >> >> Uhm, my idea of "filter" is a process/device which >> modify the input into the output. >> To the extreme point that no modification is a >> modification (pass-thru) too. >> Or, the null filter, which produce a constant output, >> independently from the input. Particularly, zero >> output, i.e. ground. >> >> On the other hand, as you wrote, "filter" can be >> understood as "selection". > > okay, now here is where convention of usage in practice comes into > play. a "filter" as DSPers normally mean, are frequency-selection > filters. they have a "frequency response" of some sort. > > but the term has been, IMO, misused when applied to "median filter", > but i am gonna have to accept the use of the term (i know unambiguously > what is meant), just as "Hanning window" (since there has never been a > Mr. or Dr. Hanning it's named after).
A gentleman named von Hann, if I have it correctly, used weights of 1/4, 1/2 and 1/4 for averaging. The obvious name for the procedure used by von Hann would be Hanning. This is all rather confused as it is a Tukeyism and motivated by the similarity with Dick Hamming's name. Hamming was a colleague of Tukey.
> so some of us getting annoyed and curmudgeonly when oft-used terms have > their meaning forcibly changed on us, but that's what language is. > neologism are born and words evolve in usage and that changes their > meaning. > > i s'pose there is some mechanical engineer that dislikes us EEs > usurping the term "filter" when he thinks it's about a device that > selectively removes stuff in a stream of something else and the ME > might think the term for what we call a "filter" is really "Linear, > Time-Invariant system". > >> That is, take something, >> drop something else. This implies the pass-thru, >> but probably not the null filter. >> >>> Terminology does seem to be a big problem in dsp. > > yup. especially audio dsp. words like: > > sample (single value or an instrument sound or note sample) > > modulate (changing parameter such as gain or changing key) > > compression (data compression or level compression or companding) > > mix or mixer (linear mixing or non-linear mixing) > > phase (initial t=0 phase or present instantaneous phase of wave) > > bandwidth (spectrum, BPF, information theory, computer instructions/sec) > >>> For example the >>> term "squaring a sin" has been used by multiple people in this thread. >>> Is that making a square wave out of a sine wave or is that sin^2(x)? >>> ;) > > i noticed that too before getting down to this post. > > before today, i never heard the term "squaring a sin" to be used in > this way. i posted a little earlier that "x^2 != sgn(x)" or these > other approximations to sgn() like arctan(alpha*x) or tanh(alpha*x) or > erf(alpha*x). that would be the type of waveshaping function we might > use to nicely "square a sine wave". (also DC-blocking the input.)
robert bristow-johnson wrote:
> On 10/14/15 5:43 PM, radams2000@gmail.com wrote: >> This reminds me of the time when I squared up my saxophone mic signal >> , fed this to a divide-by-2 flip-flop and then fed the output to a >> speaker. > > an octave pedal? did you do anything scaling the output of the > flip-flop? like with an envelope follower? > >> I was so confident in the theory that I tried it for the first time at >> a gig. Not my finest moment ( either musically or electrically). > > oooh. that's interesting. > > i have a different embarrassing trial (tried it during a rehearsal) > thinking that we could put a resistor pad on the speaker output of the > guitar amp instead of micing it. > > i thought fer sher it would work. >
It does. You will lose the nice rolloff from the speakers, but there are DI boxes that actually support this use case - you plug the amp output into the "in" of the DI and the "out" of the DI to the speaker. These DI boxes usually have a pad - usually -20dB - which may not be enough. it will sound mostly terrible. Needs about 12-30 dB/octave rolloff at 1 to 4 kHz, depending on which sort of speaker you like. Also: I am sorely tempted to install a Panasonic electric capsule in the grille cloth of my present amp, and add the appropriate gain management/buffering/(anti)buffering to send that to an XLR. Amp has a 9v out built in.
> (i also tried a PLL to do note-to-control-voltage conversion. can't > remember the PLL chip, but it didn't work. one EE prof suggested that > we modulate up the frequency so that several octaves gets squeezed to > the 10% or whatever the PLL frequency lock was. that didn't work > either. soon after i was coding MC6809 and forgetting how to hook up > chips.) > >
Lol whut? :) (moving OT) - buy a Boss TU12, find where the lights for the notes are, solder on a blue wire to each, run that to a parallel-to-serial-converter and the rest, as they say, is software :) ( I am only half-kidding ) -- Les Cargill
Sharan123 wrote:
>> In some cases I do wonder why the term "filter" is applied. "Filter" >> tends to imply that something in the input gets passed while other >> things in the input do not. Is the idea that x(t) = sgn(sin(wt)) >> removes the amplitude information and lets everything else through? >> >> Terminology does seem to be a big problem in dsp. For example the >> term "squaring a sin" has been used by multiple people in this thread. >> Is that making a square wave out of a sine wave or is that sin^2(x)? >> ;) > > Dear Eric, > > To be frank, I have had the same doubt and I had put this question in this > forum. A filter intuitively means that something is removed and something > is not. But I realized that probably that was a shallow co-relation I was > making about filters. After a bit of thinking, I assume filtering does not > always mean removal of signal components but can also mean removal of > things like noise. > > So, if we use moving average as an example, the noise is reduced, though > the power sort of gets distributed ... in this case, the noise is removed > but the signal associated is not ... > > Anyway, that's my 2 cents ... > > --------------------------------------- > Posted through http://www.DSPRelated.com >
So the word "filter" in this context means what they mean in a Signals and Systems class. The MIT Signals and Systems class is online and is free. -- Les Cargill
Sharan123 wrote:
> Hello All, > > I have a question on the sine wave to square wave conversion. > > As a part of an issue I am trying to solve, we are converting a sine wave > to square wave. > This conversion is simple and is based on whether the amplitude at any > given instant is higher or lower than a given threshold value.
So it's a clipper: float limit = <something> float dlimit = (sample < 0) ? -limit : limit; float newv = (abs(sample) > limit) ? dlimit : sample;
> Please note > that the sinewave is of a single frequency. > > The question I have is, is this a high pass filter concept? >
No.
> This is what I thought at the beginning.But then a filter attenuates > certain frequency components and leaves rest untouched. >
Not always.
> In this case, there is exactly one frequency in the input and after > filtering, there is a square waveform. > We know very well that a sine wave had exactly one frequency & did not > have such high frequency component. > > --------------------------------------- > Posted through http://www.DSPRelated.com >
-- Les Cargill
On Thu, 15 Oct 2015 12:50:14 -0500, Les Cargill
<lcargill99@comcast.com> wrote:

>Sharan123 wrote: >> Hello All, >> >> I have a question on the sine wave to square wave conversion. >> >> As a part of an issue I am trying to solve, we are converting a sine wave >> to square wave. >> This conversion is simple and is based on whether the amplitude at any >> given instant is higher or lower than a given threshold value. > >So it's a clipper: > > >float limit = <something> >float dlimit = (sample < 0) ? -limit : limit; > >float newv = (abs(sample) > limit) ? dlimit : sample; > >> Please note >> that the sinewave is of a single frequency. >> >> The question I have is, is this a high pass filter concept? >> > >No. > >> This is what I thought at the beginning.But then a filter attenuates >> certain frequency components and leaves rest untouched. >> > >Not always. > >> In this case, there is exactly one frequency in the input and after >> filtering, there is a square waveform. >> We know very well that a sine wave had exactly one frequency & did not >> have such high frequency component. >> >> --------------------------------------- >> Posted through http://www.DSPRelated.com >>
If your arithmetic is signed, (positive or negative in value), you might just take the sign of the sine wave to indicate when the square wave is plus or minus, then, boB's your uncle. boB K7KIQ
On Thursday, October 15, 2015 at 7:28:36 AM UTC+13, Piergiorgio Sartor wrote:
> On 2015-10-14 19:48, gyansorova@gmail.com wrote: > [...] > > A zero crossing detector cannot filter when there is noise. it only converts amplitude uncertainty into phase uncertainty. ie AM to PM > > And that is a filter too. > > There is no need of noise for filtering... :-) > > bye, > > -- > > piergiorgio
That is not a filter. A filter performs some form of convolution in the traditional sense. You can get multiplicative filtering of course for multiplicative noise.
On 10/15/15 9:54 AM, Gordon Sande wrote:
> On 2015-10-14 23:29:53 +0000, robert bristow-johnson said: > >> On 10/14/15 2:26 PM, Piergiorgio Sartor wrote: >>> On 2015-10-14 19:55, Eric Jacobsen wrote: >>> [...] >>>> In some cases I do wonder why the term "filter" is applied. "Filter" >>>> tends to imply that something in the input gets passed while other >>>> things in the input do not. Is the idea that x(t) = sgn(sin(wt)) >>>> removes the amplitude information and lets everything else through? >>> >>> Uhm, my idea of "filter" is a process/device which >>> modify the input into the output. >>> To the extreme point that no modification is a >>> modification (pass-thru) too. >>> Or, the null filter, which produce a constant output, >>> independently from the input. Particularly, zero >>> output, i.e. ground. >>> >>> On the other hand, as you wrote, "filter" can be >>> understood as "selection". >> >> okay, now here is where convention of usage in practice comes into >> play. a "filter" as DSPers normally mean, are frequency-selection >> filters. they have a "frequency response" of some sort. >> >> but the term has been, IMO, misused when applied to "median filter", >> but i am gonna have to accept the use of the term (i know >> unambiguously what is meant), just as "Hanning window" (since there >> has never been a Mr. or Dr. Hanning it's named after). > > A gentleman named von Hann,
which is why it's the "Hann window".
> if I have it correctly, used weights of 1/4, 1/2 and 1/4 > for averaging. The obvious name for the procedure used by von Hann would > be Hanning. This is all rather confused as it is a Tukeyism
i didn't know it was coined by Tukey.
> and motivated by the > similarity with Dick Hamming's name.
i thought it was because of sometimes someone would conflate the two. they're close to the same.
> Hamming was a colleague of Tukey.
didn't know that. Hamming had some cool things to say. one i liked: "Does anyone believe that the difference between the Lebesgue and Riemann integrals can have physical significance, and that whether say, an airplane would or would not fly could depend on this difference? If such were claimed, I should not care to fly in that plane." i think of that when i get into fights about the Dirac delta function. a weller-known quote is: "The purpose of computation is insight, not numbers." -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."