AudioMasters
User Info & Key Stats
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
December 16, 2007, 03:34:14 PM
62675
Posts in
6217
Topics by
2169
Members
Latest Member:
tone2
News:
|
Forum Rules
AudioMasters
Audio Related
General Audio
why does this square wave sound cleaner when downsampled?
« previous
next »
Pages:
1
2
[
3
]
Author
Topic: why does this square wave sound cleaner when downsampled? (Read 3292 times)
Reply #30
«
on:
June 04, 2004, 12:16:17 AM »
pwhodges
Member
Posts: 940
why does this square wave sound cleaner when downsampled?
Quote from: Mac
I thought that by combining all the harmonics that can be represented with 44khz (3,9,15,21khz) you would end up with a very close rendition of a square wave as seen by the limited sampling frequency. To see the errors you would need to build the same limited set of harmonics in a higher sample rate, eg. lowpassing the same square at 22khz in a 96khz file would show the ripples, which would be effectively invisible if the same were attempted at 44khz?
My mistake in the harmonics (oops!) makes it more similar, but there will be plenty of ripple on the top even at the lower sample rate. But the simplistic generator makes flat tops with a varying number of points to fit the frequency, which is wrong, and has lots of extra partials (not harmonics in this case). Doing it at 96kHz is OK only because 3kHz goes into 96kHz, not because it is a much higher rate (48kHz is fine too), and the downsampling to 44.1kHz will keep it good - but look how far from flat the tops are in this case when you zoom right in. That's what should have been generated.
Paul
Logged
Reply #31
«
on:
June 04, 2004, 01:32:16 AM »
MusicConductor
Member
Posts: 1300
why does this square wave sound cleaner when downsampled?
Exactly! Because of the generation problem, the downsampled 44.1 version is more accurate even with all that Nyquisty "ringing" built into it. But most accurate would be that harmonic sound generated
correctly
at 44.1 because no "ringing" would be present.
You're right about the flat tops. It's almost like a 1-bit recording -- the generator only allows 2 values! Eye candy, right? It always
looks
like a square wave, even when it's mathematically wrong...
Logged
Reply #32
«
on:
June 04, 2004, 02:36:20 AM »
DeluXMan
Member
Posts: 910
why does this square wave sound cleaner when downsampled?
Teflon: In order to properly do the test you want to do here, the square-wave signal you test with should be aquired from an analog signal generator and recorded into your 96kHz. A/D converter then into AA/CEP. Then record it again at 48kHz. and then 44.1kHz. Then use these for your downsampling/upsampling tests.
Be sure to record several arbitrary frequencies for the square-wave tone.
You can also make your own square-wave by making multiple sine-wave files and mix them down. Then all rate conversions work just fine.
Logged
=DeluX-Man=
Reply #33
«
on:
June 04, 2004, 09:20:59 AM »
SteveG
Administrator
Member
Posts: 8319
why does this square wave sound cleaner when downsampled?
Quote from: MusicConductor
Exactly! Because of the generation problem, the downsampled 44.1 version is more accurate even with all that Nyquisty "ringing" built into it. But most accurate would be that harmonic sound generated
correctly
at 44.1 because no "ringing" would be present.
This does also illustrate another aspect of the aliasing issue - and that is that once it's there, you can't really overcome it. Up and downsampling in CEP/AA is a flitered process - but if you start with a 3kHz squarewave with aliases, up-convert it to a 96k one, and then convert it back, it will look pretty much the same as it did to start with, because all those in-band harmonics will be regarded as wanted signal (
because
they're in-band), and can't be removed at all - they are intermingled with the original 'square' wave information.
It's quite remarkable how accurately it
does
come back, as it happens - even if you do the conversion repeatedly, the top stays remarkably flat at 44.1k even though that strange shape is rather more accurately represented at 96k. What this proves (if proof were needed) is that the up and down conversions that CEP/AA does are indeed
remarkably
accurate.
Logged
Reply #34
«
on:
June 27, 2004, 12:21:29 PM »
alanofoz
Member
Posts: 460
why does this square wave sound cleaner when downsampled?
As usual, Steve has pretty well explained how & why this phenomenon occurs - it's due to the division ratio of sampling frequency to square wave frequency. I do disagree though, that inaccuracies in the AA tone generator are due to low sample rates. If you repeat this whole exercise at MusicConductor's 3150 Hz (TRY IT), you'll find the shoe very firmly on the other foot, i.e. the higher sampling rate now has the problem. And you can find plenty of square wave frequencies that won't work well for either sample rate.
So I think this answers the question about AA's competent tone generator. Although Steve seems to have some more data that might prove me wrong...
Steve also explained why there are sidebands. In fact as one who is quite used to looking at FM spectra (although in this case it is more correctly called phase modulation) I suspected this as soon as I saw the spectrum. As an aside, as one who is quite familiar with "real" spectrum analysers I find AA's Frequency analysis window is often more useful than the Spectral view.
As for the "wibbly" waveform Mac referred to, see this old post
http://audiomastersforum.net/synforum/viewtopic.php?t=9144&highlight=gibbs
and scroll down to a discussion of the Gibbs Phenomenon. In fact it's what should happen.
Quote
What this proves (if proof were needed) is that the up and down conversions that CEP/AA does are indeed remarkably accurate.
I have commented on this on more than one occasion and it certainly bears repeating.
I'd be intrigued to see other peoples' opinions on why the sidebands of the harmonics are as they are. I believe I can account for the frequencies present in the case of the 3kHz square wave, and they're not exactly as you might think, but I'm not so sure about the amplitudes.
Logged
Cheers,
Alan
Bunyip Bush Band
Reply #35
«
on:
June 27, 2004, 01:49:45 PM »
SteveG
Administrator
Member
Posts: 8319
why does this square wave sound cleaner when downsampled?
Quote from: alanofoz
As usual, Steve has pretty well explained how & why this phenomenon occurs - it's due to the division ratio of sampling frequency to square wave frequency. I do disagree though, that inaccuracies in the AA tone generator are due to low sample rates. If you repeat this whole exercise at MusicConductor's 3150 Hz (TRY IT), you'll find the shoe very firmly on the other foot, i.e. the higher sampling rate now has the problem. And you can find plenty of square wave frequencies that won't work well for either sample rate.
So I think this answers the question about AA's competent tone generator. Although Steve seems to have some more data that might prove me wrong...
I tried 3150Hz at 44.1k, 48k and 96k - and the generator takes the same approach at all frequenccies - it's not band limited in any way at all, as zooming into the waveform at sample level demonstrates. Even if you get an accurate 50% duty cycle (I agree that we should be more correctly referring to this as PWM, BTW), the issue over the sidebands remains, although it's much easier to clarify the situation with a 'perfect' square wave. The generator is following a simple rule, hence the imperfections, and
everything
that is observed is a direct or indirect consequence of this, I think.
Quote
I'd be intrigued to see other peoples' opinions on why the sidebands of the harmonics are as they are. I believe I can account for the frequencies present in the case of the 3kHz square wave, and they're not exactly as you might think, but I'm not so sure about the amplitudes.
So what's not explained as a consequence of the above?
The other unanswered (in this thread, anyway) question was
Quote from: MusicConductor
All of this is relatively moot to the original, if arcane, question -- after all, what is a square wave supposed to sound like? This is a fun theoretical question, and is helpful in assessing how our audio data is handled, but it seems to me to have no substanatial benefit in real life.
This is quite simple - we'll never know! The problem is that we hear everything through an elastic medium, and you cannot transmit the flat top of a square wave through it to your ears - whoops, an immediate LF problem. But anyway, your ears would only do a frequency analysis of it within the limits of the basilar membrane mechanism, and the problem factor here is that the response of the basilar membrane itself isn't flat - it tails off towards the HF end of the audible spectrum, so our mechanism for detecting what a square wave actually sounds like is effectively stuffed at
both
ends of the audible spectrum. And that's without considering any of the
other
factors involved, any one of which would also inhibit correct transmission.
Logged
Reply #36
«
on:
June 27, 2004, 04:07:17 PM »
MusicConductor
Member
Posts: 1300
why does this square wave sound cleaner when downsampled?
Hadn't thought of it that way, Steve... thank you once again. In this case, perception is 100% of reality, not the usual 90 or so!
The simplest way I can think of to explain how to use the AA tone generator to make square waves is this: it is accurate only if the sample rate is an exact multiple of the frequency of the tone.
Logged
Reply #37
«
on:
June 27, 2004, 10:57:36 PM »
DeluXMan
Member
Posts: 910
why does this square wave sound cleaner when downsampled?
Another way to look at it is to say the AA/CEP manufactured squarewave as it is presently generated,
includes
those frequencies beyond the nyquist that would not exist if the squarewave was actually recorded into the file from a real external generator, through an A/D converter.
As long as there are
no
frequencies beyond the nyquist coming in there will be no frequency aliasing, at
any
clock speed you choose to use.
It just so happens that the unfiltered sqaurewaves, at fundimental frequencies that fit 'evenly' into the clock speed, don't create these alias frequencies, even though they
have
frequency components beyond the nyquist.
The best way to make a suitable squarewave is to make a harmonic series of sinewaves and sum them into a single file. It only takes a few harmonics to create a squarewave that's cut-off at 44.1, 48 or 96 kHz/2.
Logged
=DeluX-Man=
Reply #38
«
on:
June 27, 2004, 11:24:09 PM »
alanofoz
Member
Posts: 460
why does this square wave sound cleaner when downsampled?
Quote from: SteveG
I tried 3150Hz at 44.1k, 48k and 96k - and the generator takes the same approach at all frequencies - it's not band limited in any way at all, as zooming into the waveform at sample level demonstrates. Even if you get an accurate 50% duty cycle (I agree that we should be more correctly referring to this as PWM, BTW), the issue over the sidebands remains, although it's much easier to clarify the situation with a 'perfect' square wave. The generator is following a simple rule, hence the imperfections, and
everything
that is observed is a direct or indirect consequence of this, I think.
This is what I'd expect though. While an appropriate filter response may yield a more
practical
waveform for the chosen sampling rate, which of many filter responses would be the most appropriate? Unless the waveform generator dialog box includes options for the filter, including an option to turn it off, I wouldn't expect it to happen. Nor would I always want it to.
I'd expect the generator to take the same approach at all frequencies, but with a 3150Hz sqare wave, only the 44.1k sampling rate produces a "clean" spectrum. I think this clearly demonstrates that the imperfections are independent of sampling rate.
Quote
So what's not explained as a consequence of the above?
For starters, how do we explain the 300Hz sideband spacing? (I couldn't justify the first conclusion I jumped to.)
Logged
Cheers,
Alan
Bunyip Bush Band
Reply #39
«
on:
June 28, 2004, 01:35:31 AM »
SteveG
Administrator
Member
Posts: 8319
why does this square wave sound cleaner when downsampled?
Quote from: I
So what's not explained as a consequence of the above?
Quote from: alanofoz
For starters, how do we explain the 300Hz sideband spacing? (I couldn't justify the first conclusion I jumped to.)
I think that the basis for this one's quite easy, and moreover
provable
up to a point. Since the sidebands are linearly spaced throughout the spectrum, they can only realistically be caused by something else that's linearly spread throughout the spectrum, and the only candidate for this is the sample clock rate. You can observe that the 300Hz spacing is exactly twice the frequency difference between 3150 and 3000, so it seems reasonable to assume that the sidebands are generated at 2x the difference between an exactly divisible number of samples and the frequency being generated. This is in
general
noted to be true, but with a rider that this is limited rather by the fact that we are talking about a discrete number of samples that's rather small, so the effect is somewhat granular. But if you try this, you do appear to get a satisfactory increase in the sideband count the closer you get to the exact submultiple, so this appears to be the right lines on which to base an explanation, although the sidebands only appear to take on a discrete number of spacings.
And so I'd
still
have this as an direct consequence of sample granularity!
But you also said
Quote
While an appropriate filter response may yield a more practical waveform for the chosen sampling rate, which of many filter responses would be the most appropriate? Unless the waveform generator dialog box includes options for the filter, including an option to turn it off, I wouldn't expect it to happen. Nor would I always want it to.
And I think that the foregoing explains why, with the best will in the world, this cannot be addressed by any sort of digital squarewave generator. Because this particular effect is related to internal difference frequencies, you cannot filter it out, whatever you do. I tried all sorts of filters on the 3000Hz sample, but because it's got 300Hz evenly-spaced sidebands throughout the spectrum as a direct consequence of the way it's been generated, there's absolutely nothing that can be done about it - and this situation remains to a degree for any attempt, however fast the clock rate, to generate a square wave by this method.
Actually, if you look at any of the literature about coherent direct digital synthesis, you will find that the foregoing argument is one of the ones that limits the performance, certainly in terms of spurii generation, of any synthesiser using this sort of technique.
Logged
Reply #40
«
on:
June 28, 2004, 02:06:30 PM »
alanofoz
Member
Posts: 460
why does this square wave sound cleaner when downsampled?
Quote from: DeluXMan
The best way to make a suitable squarewave is to make a harmonic series of sinewaves and sum them into a single file. It only takes a few harmonics to create a squarewave that's cut-off at 44.1, 48 or 96 kHz/2.
In my haste to submit & get to work I didn't see your post - it wasn't there when I started my post. Also in my haste I didn't consider the possibility of the waveform generator having a "waveform synthesis" option (even though I frequently use the technique in both digital & analogue situations. Mea culpa). I actually think that would be a good option & should be added to the wish list.
In the absence of these options though, the waveforms are exactly what I'd expect, and are often what I'd
want
.
Logged
Cheers,
Alan
Bunyip Bush Band
Reply #41
«
on:
June 28, 2004, 02:08:47 PM »
alanofoz
Member
Posts: 460
why does this square wave sound cleaner when downsampled?
Quote from: I
I'd be intrigued to see other peoples' opinions on why the sidebands of the harmonics are as they are. I believe I can account for the frequencies present in the case of the 3kHz square wave, and they're not exactly as you might think, but I'm not so sure about the amplitudes.
Sorry (maybe) but I was being a bit playful here - I thought the responses might be "interesting". Read on....
Quote from: Steve
I think that the basis for this one's quite easy, and moreover provable up to a point. etc.
This whole paragraph in
every
detail this was the conclusion I couldn't justify. Let's look at the problems I had with it...
BTW Steve I assume there's a twinkle in your eye - is "provable up to a point" somewhat like "pregnant up to a point"? It's either provable or not.
Quote from: Steve
Since the sidebands are linearly spaced throughout the spectrum, they can only realistically be caused by something else that's linearly spread throughout the spectrum, and the only candidate for this is the sample clock rate.
Actually, with angle modulation (FM and PM), sidebands will
always
be linearly spaced, even if the modulating signal (the cause) is a simple sine wave. And the only candidate for sideband spacing in
any
FM signal is the modulating frequency. So where is the 300Hz modulating frequency. If you work out the details for a 3kHz square wave you'll find that for every 10 cycles (147 samples) 3 cycles have 14 samples, the rest have 15. Thus in every 10 cycles the square wave is modulated 3 times. Therefore the modulating frequency is 0.3 * 3000 = 900Hz not 300Hz. OK, fair warning this time - this is all true, but am I being playful again?
Quote from: Steve
You can observe that the 300Hz spacing is exactly twice the frequency difference between 3150 and 3000, so it seems reasonable to assume that the sidebands are generated at 2x the difference between an exactly divisible number of samples and the frequency being generated.
Yes, I did that, but I wasn't at all comfortable with what
felt
rather coincidental. I felt I was trying to force reality to fit my observations without knowing
why
it should be so. Then I tried a number of other frequencies including 3025 and 3050. The conclusion fell apart.
And of course, if you look closely enough at the rest of our posts, it can be seen that we're more in agreement than not.
Logged
Cheers,
Alan
Bunyip Bush Band
Reply #42
«
on:
June 28, 2004, 03:49:14 PM »
SteveG
Administrator
Member
Posts: 8319
why does this square wave sound cleaner when downsampled?
Quote from: alanofoz
Actually, with angle modulation (FM and PM), sidebands will
always
be linearly spaced, even if the modulating signal (the cause) is a simple sine wave. And the only candidate for sideband spacing in
any
FM signal is the modulating frequency. So where is the 300Hz modulating frequency. If you work out the details for a 3kHz square wave you'll find that for every 10 cycles (147 samples) 3 cycles have 14 samples, the rest have 15. Thus in every 10 cycles the square wave is modulated 3 times. Therefore the modulating frequency is 0.3 * 3000 = 900Hz not 300Hz. OK, fair warning this time - this is all true, but am I being playful again?
This would only be true for a 50% duty cycle though, wouldn't it? Doesn't every cycle with 15 samples in it (7 +, 8 -) count as a modulation event? In this context, I think it
does...
Anyway, true or not, your explanation doesn't seem to fit what's happening, does it? The generator is obeying the Laws of Physics, certainly - we just haven't figured out which ones yet. Oh and just in case anybody was wondering, this has nothing to do with the AA spectrum analyser - if you do the analysis of the wave in SpectraLAB, you get the same result.
Anyway, I counted the sample alternation rates for 20 cycles of this (okay, I'm bonkers). They go like this:
8787787787787787787787877877877877878778
and this appears to give, from the 40 half cycles, 26 modulation events according to
my
definition of one! It may also be useful to note that as a result of this, the supposedly 50% duty cycle 3000Hz square wave actually comprises what appears to be a 40/26 split of 3150Hz and 2940Hz. So what I'm suggesting is that
somehow
, we should be seeing 150Hz spurs and 60Hz spurs, not the 300Hz ones. So something seems to be causing the
real
spurs to disappear... Oh, and the duty cycle
has
to be like this - it's simply not possible to generate this correctly at 44.1k.
So further thoughts about what might be causing
that
to happen are needed, I think.
Logged
Reply #43
«
on:
June 29, 2004, 08:35:40 AM »
alanofoz
Member
Posts: 460
why does this square wave sound cleaner when downsampled?
Quote from: SteveG
This would only be true for a 50% duty cycle though, wouldn't it? Doesn't every cycle with 15 samples in it (7 +, 8 -) count as a modulation event? In this context, I think it does... Anyway, true or not, your explanation doesn't seem to fit what's happening, does it? The generator is obeying the Laws of Physics, certainly - we just haven't figured out which ones yet.
You may be right, but I don't
think
so. What I
think
is happening is that the frequency deviates between 2940Hz & 3150Hz 900 times per second. The fact that the change is not linear, i.e. it is stepped simply means that the modulating signal has harmonics.
Quote from: SteveG
Oh and just in case anybody was wondering, this has nothing to do with the AA spectrum analyser - if you do the analysis of the wave in SpectraLAB, you get the same result.
Yes, AA is certainly good at representing the laws of physics correctly.
Quote from: SteveG
Anyway, I counted the sample alternation rates for 20 cycles of this (okay, I'm bonkers).
So am I! Probably more so. I've done a whole
heap
of similar counting.
Quote from: SteveG
They go like this:
8787787787787787787787877877877877878778
and this appears to give, from the 40 half cycles, 26 modulation events according to my definition of one! It may also be useful to note that as a result of this, the supposedly 50% duty cycle 3000Hz square wave actually comprises what appears to be a 40/26 split of 3150Hz and 2940Hz. So what I'm suggesting is that somehow, we should be seeing 150Hz spurs and 60Hz spurs, not the 300Hz ones. So something seems to be causing the real spurs to disappear... Oh, and the duty cycle has to be like this - it's simply not possible to generate this correctly at 44.1k.
I certainly understand what you're saying & I'm not going to say it's wrong, but see my statement earlier in this post. Actually, if we're looking at half cycles, the frequencies are 3150Hz and 2756.25Hz, but that's being picky! And I think that 26 modulation events is really 13, e.g. an event would be from an 8 & back to the next 8. That's 0.65 events for each cycle of the square wave, or 1950Hz. Either way it doesn't seem to fit the observations. But that's only what I
think
.
What I said earlier was that I believe I can account for all the frequencies present, but I'm not
quite
so sure about the amplitudes. And this is based on a 900Hz modulating frequency. A couple of minutes with a spread sheet shows that 900Hz modulating the harmonics of the square wave up to 21000 Hz will produce sidebands at
all
these frequencies.
I must admit that I'm not
completely
comfortable with
anything
we've hypothesised, but I'm least
un
comfortable with this.
Quote from: SteveG
So further thoughts about what might be causing that to happen are needed, I think.
Probably the most accurate statement in this entire thread!
Logged
Cheers,
Alan
Bunyip Bush Band
Pages:
1
2
[
3
]
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Forum Topics
-----------------------------
=> Forum Announcements
=> Forum Suggestions/Remarks
-----------------------------
Audio Software
-----------------------------
=> Adobe Audition 2.0 & 3.0
===> Adobe Audition 3.0
=====> Audition 3.0 Stickies
=====> MIDI
===> Adobe Audition 2.0
=====> Audition 2.0 Stickies
=> Previous Versions
===> Cool Edit 96, 2000, 1.2a
===> Cool Edit 2.0 & 2.1, Audition 1.0 & 1.5
=> Adobe Audition Wish List
=> Third-Party Plugins
-----------------------------
Audio Related
-----------------------------
=> General Audio
=> Radio, TV and Video Production
=> Hardware and Soundcards
=> Recordings Showcase
-----------------------------
Off Topic
-----------------------------
=> OT Posts
=> Polls
Loading...