0
$\begingroup$

I want to test some code generated by this site. I selected Bessel LP 1st sample rate $600\textrm{ Hz}$ corner $8\textrm{ Hz}$ long $10\textrm{ bit}$. If I adjust the code for octave to be:

clear all;
close all;

N = 1024

v0=256;
v1=256;

m = [];

for mi = 1:128
    ip=round(rand(N,1)*512);
    for i = 1:N
        v0 = v1;
        tmp = ((((ip(i) * 2699550)/32)
              + ((v0 * 3856860)/2))
              + 1048576) / 2097152;
        v1 = tmp;
        op(i) = v0 + v1;
    endfor
    op = fft(op,N);
    m = [m; abs(op(2:N/2))];
endfor

x=[2:N/2];
y = mean(m);

semilogx(x,20*log(y)-170);

I get this plot:

filter plot

which looks vaguely correct but the slope is $\approx 13\textrm{ dB/octave}$ and not the expected $6\textrm{ dB/octave}$.

I have limited experience with DSP so I need a method to verify the actual code. Can someone recommend a procedure for verifying code like this (that works)?

$\endgroup$
2
$\begingroup$

I think the solution is to use $\log_{10}(y)$ instead of $\log(y)$. log(y) in octave is the natural $\log$, but you want a log base $10$, which is log10(y).

Confirming this:

$20\log_{10}(0.5) = -6 \textrm{ dB/octave}$

$20\ln(0.5) = \frac{-13.86}{20} \textrm{ nepers/octave}$

I am using $\textrm{ln}$ for natural log to avoid any confusion.

$\endgroup$
  • $\begingroup$ That was it! You win. $\endgroup$ – squarewav Jun 17 '16 at 17:37
  • $\begingroup$ Without the factor $20$ in front, the natural logarithm of a ratio would have the unit nepers. $\endgroup$ – Matt L. Jun 17 '16 at 20:24

Your Answer

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

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