Hi, I am fighting this problem for two days now: I want to simulate a passive mixer (50% and 25% Duty Cycle) which is basically a switch and hence can be modeled by multiplying the input with a rectangular waveform (or less harmonics). Suppose I have a clean sinusoidal LO x0 = sin(2*pi*100MHz*t). If I have sign(x0) (or alternatively Zero-Order-Hold with 2 samples per period) then I get a rectangular waveform containing all odd-order harmonics (3rd, 5th, 7th, ...). Now if I do Zero-Order-Hold with 4 samples per period, theory tells me I should get rid of the 3rd harmonic, i.e. I should have 1st, 5th, 9th, ... Now consider this sinple simulation setup: https://snag.gy/5YpQ8X.jpg with the expected time domain outputs: https://snag.gy/MRkcNi.jpg However, if I take the FFT of it, it can be clearly seen that BOTH out0/out1 contain all the harmonics (including 3rd): https://snag.gy/q7mMt0.jpg How is that possible? * I tried increasing the sampling ratio and number of periods. No changes * I tried adding steep Butterworth filter (and getting rid of the transoients) because I thought it's because of implicit harmonic folding when sampling. No change * I tried fixed and variable step solvers in Simulink (always sampling the output signals 1000x higher) with arbitrary accuracy. No change. Thanks, Peter
Troubles in simulating sharp edges
Started by ●November 17, 2017
Reply by ●November 17, 20172017-11-17
On 17.11.17 20.54, Peter Mairhofer wrote:> I am fighting this problem for two days now: I want to simulate a > passive mixer (50% and 25% Duty Cycle) which is basically a switch and > hence can be modeled by multiplying the input with a rectangular > waveform (or less harmonics). > > Suppose I have a clean sinusoidal LO x0 = sin(2*pi*100MHz*t). > > If I have sign(x0) (or alternatively Zero-Order-Hold with 2 samples per > period) then I get a rectangular waveform containing all odd-order > harmonics (3rd, 5th, 7th, ...). > > Now if I do Zero-Order-Hold with 4 samples per period, theory tells me I > should get rid of the 3rd harmonic, i.e. I should have 1st, 5th, 9th, ... > > Now consider this sinple simulation setup: https://snag.gy/5YpQ8X.jpg > with the expected time domain outputs: https://snag.gy/MRkcNi.jpg > > However, if I take the FFT of it, it can be clearly seen that BOTH > out0/out1 contain all the harmonics (including 3rd): > https://snag.gy/q7mMt0.jpg > > How is that possible?You are missing the reconstruction filter. Using a sample and hold function puts many rectangular shapes into your wave from. They have many harmonics. Marcel
Reply by ●November 17, 20172017-11-17
Marcel Mueller <news.5.maazl@spamgourmet.org> wrote:>> However, if I take the FFT of it, it can be clearly seen that BOTH >> out0/out1 contain all the harmonics (including 3rd): >> https://snag.gy/q7mMt0.jpg>> How is that possible?>You are missing the reconstruction filter. >Using a sample and hold function puts many rectangular shapes into your >wave from. They have many harmonics.Equivalently, an FFT is not a spectral estimate it is a transform. You need a window/filter to get a meaningful spectrum... lots of discussions on computing power spectral density here in the past. Steve
Reply by ●November 18, 20172017-11-18
>On 17.11.17 20.54, Peter Mairhofer wrote: >> I am fighting this problem for two days now: I want to simulate a >> passive mixer (50% and 25% Duty Cycle) which is basically a switch and >> hence can be modeled by multiplying the input with a rectangular >> waveform (or less harmonics). >> >> Suppose I have a clean sinusoidal LO x0 = sin(2*pi*100MHz*t). >> >> If I have sign(x0) (or alternatively Zero-Order-Hold with 2 samplesper>> period) then I get a rectangular waveform containing all odd-order >> harmonics (3rd, 5th, 7th, ...). >> >> Now if I do Zero-Order-Hold with 4 samples per period, theory tells meI>> should get rid of the 3rd harmonic, i.e. I should have 1st, 5th, 9th,...>> >> Now consider this sinple simulation setup: https://snag.gy/5YpQ8X.jpg >> with the expected time domain outputs: https://snag.gy/MRkcNi.jpg >> >> However, if I take the FFT of it, it can be clearly seen that BOTH >> out0/out1 contain all the harmonics (including 3rd): >> https://snag.gy/q7mMt0.jpg >> >> How is that possible? > >You are missing the reconstruction filter. >Using a sample and hold function puts many rectangular shapes into your >wave from. They have many harmonics.No. Unfortunately not. Re-quoting from my original post:> * I tried adding steep Butterworth filter (and getting rid of the > transoients) because I thought it's because of implicit harmonicfolding> when sampling. No changeAgain, the time-domain and frequency domain plots for this case: https://snag.gy/DvNVkd.jpg https://snag.gy/RfOpkP.jpg Now I also provide the waveforms: https://www.dropbox.com/s/i8y89lvkq3i97kt/data.mat?dl=0 And the DFT code: N1 = 15; N2 = 25; O0 = fft(out0(N1*1000+1:N2*1000))+eps; O1 = fft(out1(N1*1000+1:N2*1000))+eps; O2 = fft(out2(N1*1000+1:N2*1000))+eps; f = linspace(0, 100e6*1000, length(O0)); plot(f, dB20([ O0 , O1 , O2 ])); Thanks. --------------------------------------- Posted through http://www.DSPRelated.com
Reply by ●November 18, 20172017-11-18
>Marcel Mueller <news.5.maazl@spamgourmet.org> wrote: > >>> However, if I take the FFT of it, it can be clearly seen that BOTH >>> out0/out1 contain all the harmonics (including 3rd): >>> https://snag.gy/q7mMt0.jpg > >>> How is that possible? > >>You are missing the reconstruction filter. >>Using a sample and hold function puts many rectangular shapes into your>>wave from. They have many harmonics.As replied above: No, I added the filter:> * I tried adding steep Butterworth filter (and getting rid of the > transoients) because I thought it's because of implicit harmonicfolding> when sampling. No changeI actually tried all different kinds of filters.>Equivalently, an FFT is not a spectral estimate it is a transform. >You need a window/filter to get a meaningful spectrum... lots of >discussions on computing power spectral density here in the past.I do not even want a spectral estimate - I want the transform. Hence I excercise much care that I take an exact even number of cycles and when using the filter to skip initial transient. The transform also tells me that the third coefficient has to be zero. Using a circuit simulator (Cadence spectre) to do the same thing, the result is as expected: Third harmonic zero. With spectre I also use the DFT, in the same way. It only shows up if I want to simulate the same thing in Simulink (or MATLAB using zero-order-hold upsampling). --------------------------------------- Posted through http://www.DSPRelated.com
Reply by ●November 21, 20172017-11-21