rf_noise#

Analyze, generate and filter noise.

Functions

calc_psd(data, fs[, bit, plot])

Calculate the power spectral density of the input waveform (nominal sampling).

calc_psd_coherent(data, fs[, bit, n_noniq, plot])

Calculate the power spectral density of the input waveform (coherent sampling).

calc_rms_from_psd(freq_vector, pn_vector, ...)

calculate the rms value from PSDs.

design_notch_filter(fnotch, Q, fs)

Design the notch filter (return a discrete filter).

filt_step(Afd, Bfd, Cfd, Dfd, in_step, state_f0)

Apply a step of the filter.

gen_noise_from_psd(freq_vector, pn_vector, fs, N)

generate noise series from DSB PSD.

moving_avg(wf_in, n)

Moving average without compensating the group delay.

notch_filt(wf, fnotch, Q, fs[, b, a])

Apply notch filter to the signal.

rand_unif([low, high, n])

produce random number within a certain range.

calc_psd(data, fs, bit=0, plot=False)[source]#

Calculate the power spectral density of the input waveform (nominal sampling).

Refer to LLRF Book section 6.1.2.

Parameters:
  • data – numpy array, 1-D array of the raw waveform

  • fs – float, sampling frequency, Hz

  • bit – int, number of bit of data. If bit = 0, do not scale data

  • plot – boolean, True for plot the spectrum

Returns:
  • freq – numpy array, frequency waveform, Hz

  • amp_resp – numpy array, amplitude response, dBFS/Hz

  • pha_resp – numpy array, phase response, degree

  • signal_freq – float, signal frequency, Hz

  • signal_mag – float, signal level, dBFS

  • noise_flr – float, noise floor, dBFS/Hz

  • snr – float, signal-to-noise ratio, dB

  • bin_db – float, offset for an FFT bin freq space, dB

  • enbw_db – float, offset for an FFT bin freq space (correct windowing), dB

  • status – boolean, success (True) or fail (False)

Note

The unit dBFS is for ADC raw data, if for phase in radian, it should be replaced by dBrad^2; if for relative amplitude, should be replaced by dB

calc_psd_coherent(data, fs, bit=0, n_noniq=1, plot=False)[source]#

Calculate the power spectral density of the input waveform (coherent sampling).

Refer to LLRF Book section 6.1.2.

Parameters:
  • data – numpy array, 1-D array of the raw waveform

  • fs – float, sampling frequency, Hz

  • bit – int, number of bit of data. If bit = 0, do not scale data

  • n_noniq – int, non-I/Q parameters (n samples cover a full cycle)

  • plot – boolean, True for plot the spectrum

Returns:
  • freq – numpy array, frequency waveform, Hz

  • amp_resp – numpy array, amplitude response, dBFS/Hz

  • pha_resp – numpy array, phase response, degree

  • signal_freq – float, signal frequency, Hz

  • signal_mag – float, signal level, dBFS

  • noise_flr – float, noise floor, dBFS/Hz

  • snr – float, signal-to-noise ratio, dB

  • bin_db – float, offset for an FFT bin freq space, dB

  • status – boolean, success (True) or fail (False)

Note

The unit dBFS is for ADC raw data, if for phase in radian, it should be replaced by dBrad^2; if for relative amplitude, should be replaced by dB.

calc_rms_from_psd(freq_vector, pn_vector, freq_start, freq_end, fs, N)[source]#

calculate the rms value from PSDs.

Parameters:
  • freq_vector – numpy array, offset frequency from carrier, Hz

  • pn_vector – numpy array, DSB noise PSD, dBrad^2/Hz for phase noise

  • freq_start – float, starting frequency for integration, Hz

  • freq_end – float, ending frequency for integration, Hz

  • fs – float, sampling frequency, Hz

  • N – int, number of points in the freq integration range

Returns:
  • status – boolean, success (True) or fail (False)

  • freq_p – numpy array, interpreted freq_vector input

  • pn_p – numpy array, interpreted pn_vector input

  • jitter_p – numpy array, integrated jitter starting from freq_start to different freq_p element values

design_notch_filter(fnotch, Q, fs)[source]#

Design the notch filter (return a discrete filter).

Parameters:
  • fnotch – float, frequency to be notched, Hz

  • Q – float, quality factor of the notch filter

  • fs – float, sampling frequency, Hz

Returns:
  • status – boolean, success (True) or fail (False)

  • Ad, Bd, Cd, Dd – numpy matrix, discrete notch filter

filt_step(Afd, Bfd, Cfd, Dfd, in_step, state_f0)[source]#

Apply a step of the filter.

Parameters:
  • Afd – numpy matrix, discrete filter model

  • Bfd – numpy matrix, discrete filter model

  • Cfd – numpy matrix, discrete filter model

  • Dfd – numpy matrix, discrete filter model

  • in_step – float or complex, input of the time step

  • state_f0 – numpy matrix, state of the filter of last step

Returns:
  • status – boolean, success (True) or fail (False)

  • out_step – float or complex, filter output of this time step

  • state_f – numpy matrix, state of the filter of this step, should input to the next execution

gen_noise_from_psd(freq_vector, pn_vector, fs, N)[source]#

generate noise series from DSB PSD.

Parameters:
  • freq_vector – numpy array, offset frequency from carrier, Hz

  • pn_vector – numpy array, DSB noise PSD, dBrad^2/Hz for phase noise

  • fs – float, sampling frequency, Hz

  • N – float, number of samples

Returns:
  • status – boolean, success (True) or fail (False)

  • pn_series – numpy array, time series of phase/amplitude noise

  • freq_p – numpy array, interpreted freq_vector input

  • pn_p – numpy array, interpreted pn_vector input

moving_avg(wf_in, n)[source]#

Moving average without compensating the group delay.

Parameters:
  • wf_in – numpy array, input waveform

  • n – int, point number of moving average

Returns:
  • status – boolean, success (True) or fail (False)

  • wf_out – numpy array, output waveform

notch_filt(wf, fnotch, Q, fs, b=None, a=None)[source]#

Apply notch filter to the signal.

Parameters:
  • wf – numpy array, the waveform to be notch filtered

  • fnotch – float, frequency to be notched, Hz

  • Q – float, quality factor of the notch filter

  • fs – float, sampling frequency, Hz

  • b – numpy arrays filter coefficients. Note that the user can either input b, a, or fnotch, Q, fs

  • a – numpy arrays filter coefficients. Note that the user can either input b, a, or fnotch, Q, fs

Returns:
  • status – boolean, success (True) or fail (False)

  • wf_f – numpy array, filtered waveform

  • b, a – numpy array, filter coefficients. If the same filter is used to filter multiple waveforms, we can use it to avoid repeat the filter synthesis

rand_unif(low=0.0, high=1.0, n=1)[source]#

produce random number within a certain range.

Parameters:
  • n – int, number of output

  • low – float, low limit of the data

  • high – float, high limit of the data

Returns:

val – if n = 1, it is a float number, if n > 1, it is a np array