Skip to main content
27 votes

How can I work on DSP using C/C++?

MATLAB is a desktop computing environment, that's designed to make it easy to do math in batches. And if you were to have access to the MATLAB source code, you'd find that as you dig down into it, ...
TimWescott's user avatar
  • 13.3k
19 votes

How can I work on DSP using C/C++?

C/C++ is the standard language for real time and embedded signal processing. MATLAB is in most cases way too memory hungry and way too slow. There is a lot of signal processing happening in, for ...
Hilmar's user avatar
  • 48.2k
13 votes
Accepted

How can I generate a sine wave with time varying frequency that is continuous, in C?

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 ...
ederwander's user avatar
  • 2,048
10 votes

How can I generate a sine wave with time varying frequency that is continuous, in C?

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 ...
pipe's user avatar
  • 198
9 votes
Accepted

Cutoff frequency of a first order recursive filter

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 ...
Matt L.'s user avatar
  • 92.5k
9 votes

How can I work on DSP using C/C++?

I come from the game development world, and I knew C/C++ programming way before I did my first signal processing program (in the context of audio filters for games), so I hope I can give you another ...
Panda Pajama's user avatar
8 votes
Accepted

4th order high-pass filter on a DSP: standard or biquads?

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 ...
Dan Boschen's user avatar
8 votes

How can I generate a sine wave with time varying frequency that is continuous, in C?

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. ...
AnonSubmitter85's user avatar
7 votes
Accepted

Recommended C/C++ General Purpose DSP Libraries

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 + ...
Angrond's user avatar
  • 86
7 votes

How can I generate a sine wave with time varying frequency that is continuous, in C?

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 ...
hotpaw2's user avatar
  • 35.7k
7 votes

How can I work on DSP using C/C++?

I find it borderline misleading to even call MATLAB a programming language. –Well, it is a Turing complete language... but so is Brainfuck (BF). You can theoretically write any software in it (given ...
leftaroundabout's user avatar
7 votes

IIR Filter Implementation in C results in unstable system response

Using 64-bit floats just papers over an underlying problem. As a polynomial increases in order, the positions of the zeros gets ever more sensitive to the values of the lowest-order terms. Moreover, ...
TimWescott's user avatar
  • 13.3k
5 votes

Hilbert Transform in C provides possibly strange results

I am not a signal processing expert, but I have made it a good practice not to mix concepts. There is something called the Hilbert Transform, and there is an analytic signal. Here is what I do to ...
Cesar's user avatar
  • 61
5 votes

Hyperbolic sine "sinh" in fixed-point?

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 ...
robert bristow-johnson's user avatar
5 votes

How to set parameters of the PI controller inside the PLL?

Two suggestions to move forward: Reduce $K_i$ to the point of an acceptable overshoot (this will provide the bottom line answer for comparison to the computations. Do system identification (Bode ...
Dan Boschen's user avatar
5 votes
Accepted

Implementing a Butterworth Filter Manually in C/C++ via Second Order Sections

c) My code is wrong That one. You have your difference equations backwards. It should be $$y[n] = x[n] + 2x[n-1] + x[n-2] - a_1y[n-1] - a_2y[n-2]$$ You have your "a" and "b" ...
Hilmar's user avatar
  • 48.2k
4 votes

What Approximation Techniques Exist for Computing the Square Root?

One square root expansion that puzzled me in the past is the one for complex magnitude (or diagonal in a rectangle); if $a>b$, then: $$ \sqrt{a^2+b^2}\approx 0.96a+0.4 b.$$ Within 4% precision, ...
Laurent Duval's user avatar
4 votes
Accepted

What exactly is "sparse representation"?

Take a sine-like signal $s$. In the appropriate Fourier $\mathcal{F}$ domain, it is represented by two "peaks", the other coefficients being zero. Fourier is a sparse representation for sines or close-...
Laurent Duval's user avatar
4 votes

IIR Lattice Filter in C programming

assume all of this (except k[0] and the output y[]) gets defined. states g[] are ...
robert bristow-johnson's user avatar
4 votes
Accepted

Decoding a PCM BFSK signal (Bell 103)

The frequency resolution is independent of the sampling rate. Consider that in the extreme of an infinite sampling rate (continuous time), the Fourier Transform of a single FSK symbol at either 1070 ...
Dan Boschen's user avatar
4 votes

How can I work on DSP using C/C++?

In addition to the several answers already given here, I just want to link this superb answer from @Fat32. My focus is on MATLAB and the bad rap often directed at it (I am not one of them). As it has ...
Gilles's user avatar
  • 3,426
4 votes

Implementing a Butterworth Filter Manually in C/C++ via Second Order Sections

My code is wrong Even without assuming that the code's behavior is wrong, for long-term maintainability it has its problems. You'd do much better to structure your code such that you have a data type ...
TimWescott's user avatar
  • 13.3k
3 votes

How can i measure soundcard latency?

Here are some approaches to consider: FMCW: Transmit a "chirp" signal where the frequency transmitted is slowly ramped from a low frequency to a high frequency (repeatably as a sawtooth or ramp ...
Dan Boschen's user avatar
3 votes

IIR coefficients and difference equation implementation in C language

...
robert bristow-johnson's user avatar
3 votes
Accepted

Hilbert Transform in C provides possibly strange results

The function in your question doesn't compute the Hilbert transform. The Hilbert transform can be implemented either in the time domain by filtering the input signal with a filter kernel that ...
Matt L.'s user avatar
  • 92.5k
3 votes

Hyperbolic sine "sinh" in fixed-point?

If you have lots of memory, I would recommend that you use a look-up table. You could use Matlab/Octave/Python to generate the look-up table in C/C++. You can combine a look-up table with ...
Ben's user avatar
  • 3,797
3 votes

How to design a digital filter in python that will run over an uC?

Filter representation and design A DTLTI IIR filter is characterized by its transfer function $ H(z) = \frac{Y(z)}{X(z)} = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + \dots + b_{P} z^{-P}}{a_0 + a_1 z^{-1} ...
tttapa's user avatar
  • 191
3 votes

Sampling a low-frequency sound doesn't work at some sampling rates

Could be a few things You may be borderline clipping. Your sine wave has an amplitude of 1, which is just at the edge of clipping (depending on how its rendered). Try it with an amplitude of 0.5 Your ...
Hilmar's user avatar
  • 48.2k
3 votes

Simulating a raised cosine filter

MATLAB's documentation doesn't recommend the use of firrcos, instead use rcosdesign as recommend. Type doc firrcos in your ...
Gilles's user avatar
  • 3,426
3 votes

How to set parameters of the PI controller inside the PLL?

1 There's a mistake in the PID connection. You must feed the quadrature component, i.e $U_q$ to the PID, not $U_d$. The setpoint of your PLL is $U_q = 0$ because you want your PLL to be in phase with ...
Ben's user avatar
  • 3,797

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