Hot answers tagged

8 votes
Accepted

Are IIR filters (and specifically Butterworth filter) causal?

Yes, Butterworth are IIR. The decay from an impulse technically lasts forever. Yes, all [implementable] IIR are causal. Yes, because of #1 and #2. Don't use ...
user avatar
  • 14.9k
7 votes
Accepted

Convert RGB Image to Grayscale and Display It (Python + Matplotlib)

You need to set the cmap properties of the imshow() function: https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot....
user avatar
  • 39.3k
6 votes
Accepted

Why is Scipy implementation of Hilbert() function different from Matlab implementation of the function?

It works fine for me: ...
user avatar
  • 14.9k
6 votes
Accepted

Designing digital low pass filter with low pass-band group delay

Minimum phase filters will not give you a near constant group delay. You can design a non-linear phase FIR filter with a linear desired passband phase with a specified group delay that is smaller than ...
user avatar
  • 79.2k
5 votes
Accepted

Calculating values of frequency bins in Python

This is simply how Discrete Fourier Transform (i.e. Fourier Transform theory applied on sampled signal) works. You get an output of length N if your input has ...
user avatar
  • 191
5 votes
Accepted

How to generate random samples of Gaussian distribution directly in the frequency domain?

You can, but... you'll need to keep symmetry if your original time-domain signal is real-valued. If a signal $x$ is real-valued, then its DFT $X$ will exhibit complex-conjugate symmetry: $$ X[k] = X^*...
user avatar
  • 21.7k
5 votes
Accepted

How to Apply Gaussian Filter to Raw Audio Files in Python?

Do it using the following steps: Look for the optimal frequency for the Low Pass Filter. Usually close as possible to the bandwidth of your desired signal. Design an LPF filter according to the ...
user avatar
  • 39.3k
5 votes
Accepted

Scipy resample, "fourier method" explanation

Suppose you have initially a real-valued sequence x of length N. The function is basically doing this: To upsample, it ...
user avatar
  • 4,842
4 votes

Issue with the time vector returned by $\tt signal.spectrogram$ function

The default parameters of signal.spectrogram are: nperseg = 256 noverlap = nperseg/8 = 32 This means that: The length of ...
user avatar
  • 10.4k
4 votes

Butterworth band pass filter

You need to specify your filter design specifications parameters consistently for either an analog or a digital filter. With your posted code, the butterord ...
user avatar
  • 1,732
4 votes

Welch spectrogram

Reading the documentation for scipy.signal.spectrogram I noticed that it does not do any kind of periodogram averaging. It simply splits up the signal into (...
user avatar
  • 4,004
4 votes

Do DCT results contain phase spectrum?

A DCT is equivalent to a DFT of real data that is doubled and mirrored, thus rendering it symmetric. The DFT of any symmetric real signal has a phase of zero (its all cosines, no antisymmetric sine ...
user avatar
  • 33.8k
4 votes

Do DCT results contain phase spectrum?

Not really, as the transform is real. However, one could interpret the sign as a poor man's phase, being "quantized" or restricted to values $0$ or $\pi$. In other words, $1 = 1.e^{0.\imath}$ and $-1 =...
user avatar
4 votes

Decreasing Sample Rate in DFT (FFT) for Audio Analysis

There are 2 different things here that we are mixing: Bin Width As you mentioned, the bin width is a function of the ratio between the sampling rate and the number of samples. If you increase the ...
user avatar
  • 39.3k
4 votes

Checking Parseval's Theorem for Gaussian Signal by Using Scipy

There is a simple idea behind Parseval's Theorem. Unitary transform preserves the $ {L}_{2} $ Norm. The Fourier Transform (All its variants) are indeed Unitary when the correct factor is in place. ...
user avatar
  • 39.3k
4 votes

Delay in Savitzky-Golay filtering

Standard Savitzky-Golay filters are linear phase (type I) FIR filters. So they have an odd number of filter coefficients $2N+1$, and the delay equals $N$. For a good overview of Savitzky-Golay ...
user avatar
  • 79.2k
4 votes
Accepted

Apply FFT to positive spiky signal

When calculating the frequency correctly as the inverse of the period, instead of the inverse of the period times 2 pi, the fft does indeed give the expected answer.
user avatar
  • 143
4 votes
Accepted

Invertible low-pass (Butterworth) filter in python (scipy)?

Is there an invertible low-pass filter No is there something particularly difficult about inverting a low-pass filter? Yes. Digital low pass filters (in the most common sense) have a zero at ...
user avatar
  • 30.6k
4 votes
Accepted

IIR design: SciPy CMSIS-DSP coefficient format

scipy.signal returns a sos matrix when you set output='sos', which is cascaded second-order sections and has a shape of ...
user avatar
  • 2,350
3 votes
Accepted

Python different autocorrelation with FFT and non-FFT

By converting to np.int16, you're hitting integer overflow and wrapping the values around. I assume this is not intentional, since the output looks much more sane ...
user avatar
  • 14.9k
3 votes

Why is Scipy implementation of Hilbert() function different from Matlab implementation of the function?

You have to detrend the signal. If you have a DC component the behauviour changes completely. ...
user avatar
  • 41
3 votes

Morphing between two FFTs

maybe you can do it from bottom to top or top to bottom using something like the following. a notation about notation: $x[n]$ is the input sample for the $n$-th sample. this originally comes from ...
user avatar
3 votes
Accepted

How to filter out those outliers

Have you tried just median filtering the data ? That's what I'd try as a first step. Winsorizing really doesn't work on a data set that has a changing mean. It looks like python has ...
user avatar
  • 21.7k
3 votes
Accepted

How to calculate the PSD from the complex calculated STFT?

In general, if you have complex spectrum and need PSD in dB the mathematical equation is $$P_{xx} = 20\cdot\log_{10}|X_{x}|,$$ where $P_{xx}$ is your PSD in dB and $X_{x}$ is your complex STFT ...
user avatar
3 votes

How to calculate the PSD from the complex calculated STFT?

I normally use the Welch method to calculate and plot the PSD of a signal. ...
user avatar
3 votes

Why does a higher sampling frequency mess up my bandpass filter?

With an IIR filter, the higher the ratio is of sampling frequency to bandpass filter frequency, the closer the poles are to the complex unit circle in the Z-transform. Poles close to the unit circle ...
user avatar
  • 33.8k
3 votes
Accepted

Why does a higher sampling frequency mess up my bandpass filter?

As others said in the comments, this looks like numerical error. 3rd-order filters are not typically prone to this, but the higher your sampling frequency, the closer the poles move to +1: You might ...
user avatar
  • 14.9k
3 votes
Accepted

How to convert a spectrogram back to a signal

I am not a good Python coder, but did similar processing in Matlab in the past. The subject has been discussed in SE.DSP in several instances, for instance Librosa stft + istft - Understanding my ...
user avatar
3 votes

Python Hilbert does not seem to calculate the envelope

Hm well, technically it is some kind of envelope: it oscillates between hilbert(x) and -hilbert(x). Your examples (dashed lines ...
user avatar
  • 2,268
3 votes

What Are The Semantics Of Wav-File Sample Values?

I don't know much about this semantics? of WAV files but their numerical format is the following. (assuming mono) Given a recording with 8-bit per sample precision, then those samples are unsigned ...
user avatar
  • 26.5k

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