Hot answers tagged

11

Some issues here: Your SNR formula only applies to full scale sine waves, your sine wave has -6dB amplitude so your SNR will be 6 dB lower The formula also implies rounding, not truncation, that's another 6 dB You use a frequency that's a small integer divider of the sample rate, that means you are just repeating the same samples over and over again and don'...


7

I was doing quite a bit wrong, but the key thing that I was missing was the fact that the SNR needs to be calculated over the whole Nyquist spectrum instead of only looking at the peaks. This article explains everything very well: Taking the Mystery out of the Infamous Formula, "SNR = 6.02N + 1.76dB," and Why You Should Care. Another issue was that ...


5

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^*[N-k]. $$ So you can generate $N$ Gaussian pseudo-random noise samples, $g[n]$, and place them in the frequency domain noise vector, $\epsilon$ as: $$ \...


5

To provide a more quantitative approach, I have made a jupyter notebook (which can be seen as a web page here. The results can be summarized in the following plot: In practice, I have found that numpy was always faster by a significant amount. However, it seems new alternatives are emerging and I have to include (not exhaustive): architecture specific ...


4

It depends on the sizes of the images and the filters. Sometimes it also depends on the filters themselves and the quality required. Assuming all arbitrary (Namely the filters have no special property but their size, some of them are HPF, some LPF, some neither, they are not separable, no approximation is allowed, etc...) one could follow this: If the ...


3

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 an A/D converter, but may have come from a sound file. $x_1[n]$ and $x_2[n]$ are two separate inputs. $y[n]$ is the output sample at the $n$-th time. it will ...


2

In fact Welch was a good idea. End of post. Problem solved. # Loop for FFT data for dataset in [fft1]: dataset = np.asarray(dataset) freqs, psd = welch(dataset, fs=266336/300, window='hamming', nperseg=8192) plt.semilogy(freqs, psd/dataset.size**2, color='r') for dataset2 in [fft2]: dataset2 = np.asarray(dataset2) freqs2, psd2 = welch(...


2

When you construct re_field, ditch the np.abs. It turns all negative values of the sine wave positive. Instead, do a np.realon the result of the ifft2 to get rid of the imaginary parts caused by rounding errors. Then you will get a result perfectly matching the original. In the magnitude spectrum you cannot see the sine wave you inserted, because its ...


2

You seem to know how to handle the DFT/FFT scaling so that its output matches the sampled signal's power/amplitude levels. Yet there is a discrepancy between your expectation and the obsevred DFT result? There are a few reasons. Your assumptions on the sampling rate or the signal frequency could be wrong. Indeed as it seems from your figures, the signal is ...


2

First of all, thanks for sharing this problem. I hope it can foster some good discussions here at stack-exchange. I guess this problem is commonly called Multi-Focus Multi-Image Fusion (MF-MIF). Let's look at all the images together with their grayscale histograms and the gradient magnitude (information content in each image): As the original question ...


2

Below is a function which I wrote long back, when I needed to generate AWGN time-domain samples given Noise PSD in dBm/Hz. AWGN_NOISE() : Generates Additive White Gaussian Noise of PSD power in dBm/Hz AWGN has Gaussian PDF with 0 mean and $\sigma^{2} = N_{o}/2$ $NoisePSD_{dBm/Hz} = 10.log_{10}(\frac{N_o}{2.BW})$, Why? Because, Output Noise Power(in dBm) :...


2

Why do I have ringing and such an aggressive response? Because you designed a really aggressive filter, which is borderline unstable. All the poles are less than 1/1000 away from the unit circle. How does the low cut off frequency and high sample rate affect the filter response? The lower the cutoff, the higher the order, and the higher the sample rate, ...


2

Your spectrum is zero at all frequencies other than at the carrier and the side bands. If the magnitude is zero the phase is undefined. Since you use finite precision math, the magnitude in your calculation will not be exactly zero but just a really really small number. So the phase can be computed but what you are seeing just random numerical noise. As you ...


1

In the code the OP is comparing the real and the imaginary components of the FFT in each to determine similarity. If a phase shift occurs then the real and imaginary components will also change. What the OP should be comparing is the magnitudes of the complex values in each sample, which should be invariant under such image shifts. Confirming this; the OP ...


1

The difference here is that statistical autocorrelation assumes a stationary power signal (so basically an infinite periodic signal) and does a normalisation to $[-1,1]$ and that autocorrelation just takes the finite signal as it is and does the classical convolution of the signal with itself, leading to just one point of perfect overlap and decreasing ...


1

First of all, sampling frequency and sampling rate are synonymous. You mean sampling frequency of 44.1 kHz with a data length of 20 ms. Second of all, 20 ms of data at 44.1 kHz will give you 882 points. Not enough for a 1024-point FFT. You will either need to upsample to 51.2 kHz, that way 20 ms will give you 1024 points. Or you could append 142 zeroes to ...


1

I'll give a concrete example. Let's say you have a signal that was sampled every second. The frequency is $f = \frac{1}{1} = 1 Hz$. Time: $T = \begin{bmatrix}0 & 1 & 2 & 3\end{bmatrix}$ Value: $X = \begin{bmatrix}1 & 2 & 3 & 4\end{bmatrix}$ We want to increase the frequency by $2$ i.e. $2 Hz$ (sample every 0.5 seconds). Time: $\tilde{...


1

You can use the Fourier transform for a lot of things – it can be part of a particular step in a scaling algorithm. Still, what you're looking for are scaling algorithms. In this particular case, your original data size is (74 × 128) – what that means in wavelengths or any physical unit doesn't matter to algorithms – and you want to scale it to (512 × 512). ...


1

As this page https://ccrma.stanford.edu/~jos/ReviewFourier/FFT_Convolution.html mentions, when you perform cyclic convolution (FFT convolution) you have to add zeros to your signal $A$ to the length $$N_Y = N_A + N_A -1,$$ where $N_Y$ is the length of the output convolution and $N_A$ is length of your signal. In your case you are performing the FFT ...


1

Answers to Your Questions You are right that your time instants are spaced at an interval of $T$. Hence, the sampling rate is $1/T$. ($T$ is defined in line 3 of your code.) You are also right that the second parameter of np.fft.fftfreq() is the sampling interval $T$. I am, however, not sure why you get wrong results when setting $T=100\,\text{Hz}$. This ...


1

This boils down to computing the sum of a geometric series. Given $$x[n]=e^{-\alpha n},\qquad n=0,1,\ldots,N-1\tag{1}$$ the DFT is $$\begin{align}X[k]&=\sum_{n=0}^{N-1}x[n]e^{-j2\pi nk/N}\\&=\sum_{n=0}^{N-1}e^{-\alpha n}e^{-j2\pi nk/N}\\&=\frac{1-e^{-\alpha N}}{1-e^{-\alpha}e^{-j2\pi k/N}},\qquad\alpha\neq 0,\quad k=0,1,\ldots N-1\tag{2}\end{...


1

You can solve this using scipy.fftpack (sfft) instead of np.fft, because the sfft implementation can be directly used on 2-dimensionnal arrays so you don't have to do it in a convoluted way (ba dum tsss). In your code header, add : import scipy.fftpack as sfft Then, to calculate the fft and shift the spectrum, use : Z_fft = sfft.fft2(Z) Z_shift = sfft....


1

These questions will probably seem silly to you, sorry for that. No question is "silly". My perception is that the questions are trivial and can be answered by looking things up in a textbook but if this is to get you out of a "difficult corner", here it goes: ...I was expecting that the real part will represent amplitudes of two sinusoidal signals and ...


1

Mathematically speaking, log(0) is undefined. The standard behavior for most computer languages, such as matlab, is to return -inf. Some languages, such as C++ will return -inf and raise a div by zero exception. Given that it's just a warning you could opt to ignore or suppress the warning and move on. Another option is to massage all of the 0 values to a ...


1

2 comments: First, scipy signal decimate already low-pass filters the signal. It first filters the signal and then subsamples. So there is no need to pre-filter your signal before decimation. In your case, the signal is filtered at 125 Hz, which is half the resulting sampling frequency. (decimate doc here) Second, a Butterworth filter is not an ideal ...


1

First off, you have a "bug" in your code. Look at line 45: combined_fft = np.fft.fft(signal) You are taking the FFT of your signal and calling it, and labeling it, the combined signal. Fix this, and you will see two peaks on each end. If you use the "rfft" (real FFT) call instead, you will get back the first half and the Nyquist bin for even N. ...


1

To answer the question in your title: Because it is defined to do exactly that. Think about it: the DFT is a revertible linear operation on all vectors of the $\mathbb C^N$. In other words, for every vector that you apply the DFT to, there is exactly one vector that is the result, and for every result vector, there is exactly one vector that maps to it. ...


1

This is wrong Because if your carrier frequency is less than your message frequency, then you will have trouble in filtering .


1

The amplitude is correct but it is mirrored and 90 degrees off-phase. I feel I am missing something but I cannot nail it. re_field has np.abs in it, so it's not the same thing. You've rectified the signal. To remove the negligible imaginary parts, use np.fft.ifft2(f_ishift).real instead. Also, I would expect that the magnitude spectrum would be ...


1

I just implemented one VSDFT in Matlab and confirm what is said above. FFT makes uses of symmetries, but here you can't. Instead you should have a lot less number of points to compute, as if you had a quarter of the FFT to compute.


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