1
$\begingroup$

I am designing (in matlab) a simple system with a DC signal at 0 Hz and some added noise. I am performing a differentiation of the signal (by simply subtracting the last values from each other), next i am applying rolling average algorithm, to filter the high frequencies, and then i simply integrate over a number of samples. Using the pwelch() function on the output i noticed that there is some noise shaping going on, and i don't really now where it is coming from...

I am aware of delta-sigma modulators, but this is not a thing i am doing here: for my integrator i am using a very simple algorithm that adds $n$ last samples together. I would expect a simple integrator behaviour here (with frequency response falling 20db/dec).

Why does the noise shaping take place? https://i.sstatic.net/dTfLl.png power spectrum of integrated signal

I am posting the code for the signal generation, differentiator and integrator below.


clear
home
close all

%generate the signal
    fs = 1;
    T = 1/fs;
    t = 0:T:(2^14);
    pos = 3 * t; 
    noise = 2 * randn(1, length(t));
    pos = pos+noise;


    %differentiate the signal
    diff_time = 1;
    diff_out = [];
    len = length(pos);
    for j = 1+diff_time : len
        diff_out(j-diff_time) = pos(j)-pos(j-diff_time);
    end

    %filter the hf with MA filter with 16 taps
    MA_avg = zeros(1,16);
    for i = 1 : length(diff_out)-16
       avg_val = MA_avg(end);
       old_val = diff_out(i);
       current_val = diff_out(i+16);
       MA_avg(end+1) = current_val-old_val+avg_val;
    end

    %integrate
    pos_intgr = integrate(MA_avg, 16);

    %get the spectral power
    NFFT = length(pos_intgr);
    [P, F] = pwelch(pos_intgr,ones(NFFT,1),0,NFFT,fs,'power');
    PdBW = 10*log10(P);
    plot(F,PdBW)
    title("pwelch")
    xlabel('Frequency')
    ylabel('Power spectrum (dbW)')

    function [acu_down] = integrate(signal, taps)
       len = length(signal);
       acu_down = [0];
       i = 1;
       k = 1;
       while i <= len-taps
          sum = 0; %reset the sum
          for j = 0 : taps-1
               sum = sum + signal(i+j); 
          end
          i = i+taps;
          acu_down(k) = sum;
          k = k+1;
      end
      %cut out the LSB
      acu_down = acu_down ./ taps;
   end
$\endgroup$
4
  • $\begingroup$ I don't really follow your code or how you got that plot. As far as I can tell, "noise" is never used, the differentiated signal is never used. Your moving average is just a moving average of a ramp. You integrate looks like another average rather than an integrate (accumulator which would add the output to the next input would be an integrator). That said the differentiator would give you the result you see, while the moving averages should approximate a Sinc function shape as the number of samples grow large. $\endgroup$ Commented Feb 27, 2020 at 13:52
  • $\begingroup$ If you cascade differentiator with an actual accumulator, you will also get the equivalent of a moving average response (this is what a CIC does). $\endgroup$ Commented Feb 27, 2020 at 13:53
  • $\begingroup$ @DanBoschen sorry, I forgot to adjust the variables before posting. I corrected the code now. Yes, the MA is a ramp, but it actually filters the higher frequencies also (i ran a FFT and it showed that it works). The output just looks like it has the spectral power of the noise pushed into higher frequencies, which i cannot understand. $\endgroup$ Commented Feb 27, 2020 at 14:05
  • $\begingroup$ Yes a MA definitely filters the higher frequencies --a MA is a low pass filter. See my answer but perhaps the real question is what are you actually wanting to do? Maybe there is a better way. $\endgroup$ Commented Feb 27, 2020 at 15:03

1 Answer 1

1
$\begingroup$

The dominant effect you see is from the differentiation which is a high pass function.

Observe the spectrum after differentiation alone:

differentiation output

As would be clearer on a log log plot the signal is going up at rate f versus frequency. (consistent with a differentiation).

Next observe the spectrum at the moving average output:

moving average

This is consistent with expected: The moving average approximates a Sinc filter response, and the nulls of a Sinc function go down at rate f versus frequency. With the differentiator going up at rate f and the moving average going down at rate f we see the flat response as observed with the nulls at $1/T$ where $T$ is the duration of the moving average.

Your final operation that you call an integrator is actually another average combined with a down-sample (decimation), and with that would result in the low frequency portion of your signal after another 16 point average; so another Sinc filter response of similar form and then the decimated (close in) spectrum out to half of the first main lobe:

final spectrum

$\endgroup$
1
  • $\begingroup$ wow, it all makes sense now. I understand what is going on here. Thanks a lot for your input! (this is a part of an resolution upscaling algorithm that I am trying to bring down to basic blocks and understand). $\endgroup$ Commented Feb 27, 2020 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.