I have to add non-Gaussian random noise in synthetic seismic data in my project, but apparently I can only find the methods to add Gaussian noise as below:
import numpy as np
noise = np.random.normal(0,1,100)
Are there any ways to generate them?
Related
In the original dataset there is noise. I want to denoise them. Spline interpolation or wavelet filtering can be used.
Please find the dataset sample here
>t1=1583516027000;t2=1583516028000
>t3=1583515991000;t4=1583515993000
>u1=d5[(d5['time']>=t1) & (d5['time']<=t2)]
>u2=d5[(d5['time']>=t3) & (d5['time']<=t4)]
t1,t2,t3,t4 are the timestamp interval where the noise occurred. To denoise them,
>u1['ch1'].interpolate(method='spline', order=2)
It provides me an error and also interpolation only interpolate the missing observations not the existing values.
Also, for wavelet denoise filtering I wrote this code
>import pywt
>import numpy as np
>from scipy.misc import electrocardiogram
>import scipy.signal as signal
>import matplotlib.pyplot as plt
>from skimage.restoration import denoise_wavelet
>wavelet_type='db6'
>x_denoise = denoise_wavelet(u1.iloc[:,0], method='BayesShrink', mode='soft', wavelet_levels=3, wavelet='sym8', rescale_sigma='True')
However, it does not change any results. How can I do this task? I am new to post the question. This is my first question. May be I am not clearly able to explain all the problem. My intention is to make a denoise dataset using spline interpolation and wavelet denoising filtering. But the problem is I can not filter the whole dataset. I have to filter only based on time interval because whole dataset dose not include the artifacts or noises. If I filter the whole data, it would also remove the original data. Therefore, I have to filter based on time interval.
I have a camera XIMEA and I want to make algorithm that could get and stack number of frames with my algorithm in real time.
For example, we have a live video. after 15-th frame I want to get [1,15] frames in one list (List comprehension?) and make something with them. After that I want to get a list with frames [2,16], [3,17] etc while I won't stop it. How can I do that?
I have a code like that for camera
import cv2
import time
import numpy as np
from matplotlib import pyplot as plt
from scipy import ndimage
cam = xiapi.Camera()
cam.open_device()
img = xiapi.Image()
now you see what libraries I used for it.
LSI algorithm (temporale filter) is about to get mean value for one pixel in a few frames (in my case in 15). Should I use some numpy functions for pictures as for arrays or opencv for frames?
I'm completely new to python, scipy, matplotlib and programming in general.
I'm using the following code, which I came across online, to apply FFT to .wav files:
import scipy.io.wavfile as wavfile
import scipy
import scipy.fftpack as fftpk
import numpy as np
from matplotlib import pyplot as plt
s_rate, signal = wavfile.read("file.wav")
FFT = abs(scipy.fft.fft(signal))
freqs = fftpk.fftfreq(len(FFT), (1.0/s_rate))
plt.plot(freqs[range(len(FFT)//2)], FFT[range(len(FFT)//2)])
plt.xlabel('Frequency (Hz)')
plt.ylabel('Amplitude')
plt.show()
The resulting graphs give amplitude values that range from 0 to a few thousands, depending on the files, and I have no idea what unit these are in. I'm guessing they might be relative amplitudes, and I was wondering if there is a way to turn that into decibels, as I need specific values.
Thank you
Tanguy
They are amplitudes relative to the quantization units used for the samples in your input signal. So, without calibrating your input signal against a known level of source input (to get Volts per 1 bit change, etc.), the actual units are unknown. If calibrated, you may still need to divide the magnitudes of the FFT output by N (the FFT length), depending on your particular FFT implementation.
To get Decibels, convert by taking 20*log10(abs(...)) of the FFT results, and offset by your 0 dB calibration level.
I would like to plot the softmax probabilities for a neural network classification task, similar to the plot below
However most of the code I've found on SO and the doc pages for matplotlib are using histograms.
Examples:
plotting histograms whose bar heights sum to 1 in matplotlib
Python: matplotlib - probability mass function as histogram
http://matplotlib.org/gallery.html
But none of them match what I'm trying to achieve in that plot. Code and sample figure are highly appreciated.
I guess you are just looking for a different plot type. Adapted from here:
# Import
import numpy as np
import matplotlib.pyplot as plt
# Generate random normally distributed data
data=np.random.randn(10000)
# Histogram
heights,bins = np.histogram(data,bins=50)
# Normalize
heights = heights/float(sum(heights))
binMids=bins[:-1]+np.diff(bins)/2.
plt.plot(binMids,heights)
Which produces something like this:
Hope that is what you are looking for.
I have a two dimensional array representing an image. I have to add background gaussian noise of RMS 2 units to the image. I am unfamiliar with RMS measurement of noise and how to add it. Can you give me an insight on how to do this ?
The way I understand it, you want to add white noise following a Gaussian distribution at every pixel. That could be achieved by something like this
from scipy import stats
my_noise=stats.distributions.norm.rvs(0,2,size=your_array.shape)
your_array+=my_noise
Here, 0 is the mean and 2 the standard deviation of your distribution.