2
$\begingroup$

I designed a 1st order Delta Sigma converter in PSpice, except for the decimation filter. I want to implement said decimation filter in Python, rather than in PSpice. Being new to both Python and filters in general, I turned to google, which offered me this "simple" solution.

The explanation is quite clear (I think). In my case, the parameters are the following: - signal going into the DeltaSigma ADC: 1 kHz sin wave - sampling rate of the DeltaSigma ADC: 5 MHz - simulation step size: 100 ns (might be relevant)

When I design my filter (a Windowed Sinc filter, as in the example above) I use the following parameters (I have also used some variations of these parameters): - cutoff frequency fc = 3 kHz - transition bandwidth 1 kHz, which results in N = 200001

NB: the filter might be very ambitious, but as far as I can see this is just a computation-time-related problem.

Now, if I implement the above in Python everything seems to work fine up to the filter application to my signal; this means that the sinc filter "looks" nice in the plot, the input signal is ok, etc...

For reference: this is my implementation of the filter.

# Define the parameters
fc = 0.0006 
b = 0.0002  
N = int(np.ceil((4 / b)))
if not N % 2: N += 1  # Make sure that N is odd.
n = np.arange(N)

# Compute sinc filter.
h = np.sinc(2 * fc * (n - (N - 1) / 2.))

# Compute Blackman window.
w = np.blackman(N)

# Multiply sinc filter with window.
h = h * w

# Normalize to get unity gain.
h_unity = h / np.sum(h)

After this, I simply do a convolution with:

filtered_data = np.convolve(out, h, 'valid')

Image of the output data after the filter:

Data after passing through the filter

I would expect the filtered data to be a sin wave, not that "thing".

My guess is that I am missing something fundamental and that somehow I should take care of the fact that the sampled signal is actually sampled with both the 5Mhz clock AND with the 100 ns simulation time.

Any help will be appreciated!

EDIT: clarification on the out signal.

The out signal is generated by a Delta Sigma converter, so supposedly it should be a stream of '1' and '0'.

But since the PSpice simulator has an internal step size (which is variable) the actual values of the out signal have also intermediate values (remember: the output waveform in PSpice is a voltage, so in the transition between 0/1 the voltage is calculated).

So, my out signal looks like this (not actual values, just for clarity):

Time    Out
0       0.000
0.1     0.000
0.145   0.123
0.167   0.679
0.2     1.000
0.3     1.000
0.4     1.000
0.45    0.875
0.493   0.439
0.560   0.293
0.6     0.000

This most likely introduces spurious frequencies in my spectrum.

Working on a possible solution, will let you know if it works!

$\endgroup$
  • $\begingroup$ How are you generating the signal out? What does the spectrum (or time domain) of out look like prior to filtering? These are important pieces of information that are not in your question. $\endgroup$ – hops May 16 '17 at 14:52
  • $\begingroup$ I did not include the picture of Out because I am new and could post only 2 links, sorry! Anyway, the Out signal is generated by the Delta Sigma converter so in theory it should be a sequence of zeros-ones (when the input sin wave is "very high" you have a lot of 1 and few 0, and viceversa when the sin wave is "very low"). In practice, since the PSpice simulator has an "internal" step size of 100 ns (and in practice, the step size is variable to be able to simulate in an accurate way the circuit during the transitions) my array contains many more values than expected. $\endgroup$ – Cesco May 16 '17 at 14:54
  • $\begingroup$ It would be helpful to have code that generates it then. I would suggest you look at the spectrum of your sigma-delta signal. It should show one tone in the band of interest and a lot of garbage outside the band. I would compare this to the frequency response of the filter to make sure that the cutoff frequency and stopband attenuation are sufficient. I think I could provide an answer if I had more information on forming out. $\endgroup$ – hops May 16 '17 at 15:09
  • 2
    $\begingroup$ Just for completeness and future reference, in case someone is passing by: the problem is given, as suspected, by the out signal produced by PSpice. In PSpice the simulation step that you can set is a MAXIMUM simulation step: the simulator will adjust it (especially in zones where transitions occur) to smaller values as it sees fit. This means that my out signal is not sampled at regular intervals, thus making it difficult for the filter to work. Solution (good for my needs, at this point): implement the filter in PSpice. $\endgroup$ – Cesco May 17 '17 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.