Hot answers tagged

20

What your distortion box does is apply a non-linear transfer function to the signal: output = function(input) or y = f(x). You're just applying the same function to every individual input sample to get the corresponding output sample. When your input signal is a sine wave, a specific type of distortion is produced called harmonic distortion. All of the ...


13

if you want a cheap and dirty optimized power-series expansion (the coefficients for Taylor series converge slowly) for sqrt() and a bunch of other trancendentals, i have some code from long ago. i used to sell this code, but no one has paid me for it for nearly a decade. so i think i'll release it for public consumption. this particular file was for an ...


13

I can recommend you two books about DSP for C language. Embree P. M. - C Language Algorithms for Digital Signal Processing It is old and you can easily get it second-hand for a decent price. It covers pretty much all 4 topics that you described. The other one I recommend is: Malepati H. - Digital Media Processing: DSP Algorithms Using C It covers ...


13

Well lets go lol @AnonSubmitter85 give to you a nice answer, but let me show my way to do it in matlab, and this maybe can be very easy to port to C: First I'm creating 256 samples in 500hz sampled at 44100hz take a look how I accumulate the phase and in the end of the first loop I put the phase between the interval 0 and 2pi... Nice now lets go to the ...


11

You asked how a low pass filter works and mentioned that the filter uses past values of you're data. This is a non-technical discussion of what happens in a low pass filter. The low pass filter takes differing views (shifted in time) of your signal, scales them and adds them together. You can imagine drawing your signal 3 times, one being current, the ...


10

Thanks to the plot in Olli Niemitalo's answer I got convinced that the formula given in the book has a sign error. The non-linearity used for fuzz or distortion is always some type of smoothed clipping function, which compresses the input signal. So small input amplitudes experience little change whereas high input amplitudes are (more or less) softly ...


9

What you trying to achieve is called distortion. This techniques used when you want to add some harmonics to given signal. You have 2 basic methods to do this: waveshaping and ring modulation.I'll try to explain first one. Waveshaping Waveshaping allows you to make distortion via use of specially selected function. One of useful methods is Chebyshev ...


9

A moving average can be implemented recursively, but for an exact computation of the moving average you have to remember the oldest input sample in the sum (i.e. the a in your example). For a length $N$ moving average you compute: $$y[n]=\frac{1}{N}\sum_{k=n-N+1}^nx[k]\tag{1}$$ where $y[n]$ is the output signal and $x[n]$ is the input signal. Eq. (1) can ...


9

It's a little weird to see so many answers but none that presents an actual answer in C or explains how and why to do it. The general idea is to maintain a phase that is incremented by a step size that is calculated from the frequency and sample rate. This way you will never get a phase discontinuity. When doing this, one has to be very careful with ...


8

Yes. This looks like it's a typical first order low pass. The time constant can be determined by looking at the time it takes for the falling edge to drop to 37% of the max amplitude ($e^{-1}$). The cutoff frequency of the low pass filter is $1/(2 \cdot \pi \cdot t_c)$ where $t_c$ is the time constant


8

That formula for the cut-off frequency is a very inaccurate approximation. In this answer I derived the exact relation between the coefficient of a first order recursive averaging filter and its 3-dB cut-off frequency. Note that in the quoted answer I used the constant $\alpha=1-b$. From formula $(3)$ in that answer we get for the coefficient $b$ $$b = 2-\...


8

The two solutions in a floating point implementation are assumed to be identical, with the two BiQuads being a factored version of the standard difference equation. The BiQuad is the better way to go for fixed point as you isolate two 2nd order systems and in doing so will be easier to keep stable under variations due to the quantization involved. For more ...


8

The easiest way to do this is to note that frequency is by definition the derivative of the phase. Thus, you can define what the frequency of each sample is and then integrate that to get the phase. This keeps the phase continuous. For example, in matlab this would look something like so: % The two frequencies of interest. f1 = 500; f2 = 1000; % Sample ...


7

If you haven't seen it, the "Quake square root" is simply mystifying. It uses some bit-level magic to give you a very good first approximation, and then uses a round or two of Newton's approximation to revise. It might help you if you're working with limited resources. https://en.wikipedia.org/wiki/Fast_inverse_square_root http://betterexplained.com/...


7

What is wrong with a fading memory (exponential) moving average: ma_new = alpha * new_sample + (1-alpha) * ma_old


7

I'd recommend Introduction to Signal Processing by S.J. Orfanidis. It's a great book with a good mix of theory and practice, and it also has code examples in C and Matlab. Once you've worked through it you'll know enough to carry on by yourself.


7

In addition to incrementing phase (instead of incrementing time and multiplying by frequency, potentially causing jaggies), also note that the input to your trig function might need to be range limited (or wrapped) to prevent range reduction loss of precision in the trig function implementation. After incrementing by delta phase, I usually limit phase (by ...


6

The number float* array is a pointer to the array. It is a single number which contains the address of the first element of the array of float values. Usually, the initial condition (i.e. the initial 'past' elements of x and y) are 0, but if their values are not equal to 0 it is no big problem either, because after a while the initial conditions have no ...


6

Since what interests you is the "embedded system" part, and since you have a low budget (this excludes anything that requires proprietary compilers), I'd recommend building yourself a board with an ARM MCU and a codec, like this one. There's less than $50 of parts - the processor, the codec and the bare minimum to get them to work. I'm recommending this ...


6

because the code markup for SE seems to work like shit, i'll try to answer this more directly, specifically for the $\sqrt{x}$ function. yes, a power series can quickly and efficiently approximate the square root function, and only over a limited domain. the wider the domain, the more terms you will need in your power series to keep the error sufficiently ...


6

You could also approximate the square root function by using Newton's Method. Newton's Method is a way of approximating where the roots of a function are. It is also an iterative method where the result from the previous iteration is used in the next iteration until convergence. The equation for Newton's method to guess where the root is of a function $f(...


6

You need to build a time varying delay, where you can modulate the delay amount over time. The peak delay modulation is a function of your maximum desired frequency shift and the modulation frequency. This is not trivial since it will require fractional sample delays with some kind of interpolation algorithm. You can't round to the nearest integer delay ...


5

|x| denotes the absolute value - the x / |x| bit of the formula is there to make sure that the sign of the input is preserved in the output. Regarding the implementation, yes, the steps you have listed are correct.


5

Maybe a bit late, but since others might land here like me. The following are good signal processing libraries/frameworks: * https://www.gnuradio.org/ - lots of classic signal processing + cascading options * https://root.cern.ch/ - advanced statistical signal processing Both provide generic facade, fall-back implementations as well as performance ...


5

Be careful with that version of the Cookbook. I did not actually write it, although I gave permission to Doug to write it. He has a few typographic errors. The original has been moved. I think this is maybe where it lives now but there appears to be a CR/LF problem with the file. Anyway, to do trancendentals with a fixed-point processor is difficult but ...


4

Frequency domain filtering (FFT), as suggested by some comments, is definitely wrong -- it's even slower, or same speed at best! A recursive filter (IIR) is the fastes possible solution. If you choose a typical second order filter (called biquad in engineering slang) of Butterworth type and do your math right (factoring out coefficients) you only have 3 ...


4

Have you considered using the Parks McClellan algorithm to generate your FIR filters. The source code for it is available on several sites in Fortran or C. The original Fortran code is available on Wikipedia. Here are two sources for C code Github/scipy Iowa Hills You said you were trying to understand filters, so let me explain that the Parks McClellan ...


4

you don't wanna do this on a bin-by-bin basis. here's a paper by Miller Puckette that is seminal regarding this issue. what you want to do is identify specific frequency components (perhaps each lobe in the spectrum would be a specific frequency component) and multiply that entire $n$th lobe by $e^{j \phi_n}$ where $\phi_n = \omega_n \ T_n$ and $\...


4

Actually it is done by solving an quadratic equation using Newton Method: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots For numbers greater than one you can use the following Taylor expansion: http://planetmath.org/taylorexpansionofsqrt1x


4

Wavelets are not key to denoising. There are different ways to denoise an image, for example in the original signal domain or in the transform domain (i.e. Fourier or wavelet). Wavelets work best for additive noise, where the noise is random & not correlated in time. wavelet_denoise (float *fimg[3], unsigned int width, unsigned int height, float ...


Only top voted, non community-wiki answers of a minimum length are eligible