calculateSNR
Signal-to-noise ratio based on in-band bins of windowed FFT and location of input
Since R2026a
Description
Examples
Define a second-order delta-sigma modulator and the system parameters for the simulation.
order = 2; % The "Order" of the modulator OSR = 64; % Oversampling Ratio (fs / 2*BW) nlev = 2; % Number of quantizer levels (2 = Binary: +1 or -1) N = 2^14; % Number of points for the FFT simulation (16,384) test_freq = 5; % The bin index for our test sine wave (must be an integer)
Determine the in-band frequency range for SNR calculation.
fB = floor(N/(2*OSR));
Synthesize the noise transfer function (NTF). This creates a mathematical filter that pushes noise to high frequencies.
ntf = synthesizeNTF(order, OSR);
Realize the NTF as a CIFB circuit topology.
[a, g, b, c] = realizeNTF(ntf, 'CIFB');Create the state-space matrix for the simulator.
abcd = stuffABCD(a, g, b, c, 'CIFB');Scale the ABCD matrix so that the internal voltages stay within the range of the quantizer.
[abcd_scaled, umax] = scaleABCD(abcd, nlev);
To set up the simulation, define a range of input amplitudes to test, from very quiet to loud. Run simulation.
amp_db = -110:10:-10; % Decibels relative to Full Scale (dBFS) amp_lin = 10.^(amp_db/20); % Convert dB to linear voltage snr_sim = zeros(size(amp_db)); % Pre-allocate space for results for i = 1:length(amp_db) % Generate a test sine wave at the current amplitude t = 0:N-1; u = amp_lin(i) * sin(2*pi*test_freq/N * t); % Run the Delta-Sigma Modulator Simulation % Returns 'v', which is the high-speed 1-bit output bitstream. v = simulateDSM(u, abcd_scaled, nlev); % Spectral Analysis: % 1. Apply a Hann window to prevent spectral leakage w = ds_hann(N); % 2. Perform the FFT V = fft(v .* w); % 3. Calculate SNR of the in-band portion % calculateSNR sums signal power at 'test_freq' and noise in remaining bins. snr_sim(i) = calculateSNR(V(1:fB), test_freq); end
Predict the theoretical SNR. Calculate a peak value to anchor the predicted SNR curve.
peak_snr_theory = 10*log10( ((2*order+1)/(2*pi^(2*order))) * (OSR^(2*order+1)) ); snr_pred = peak_snr_theory + amp_db;
Plot the predicted and simulated SNR.
figure('Color', 'w', 'Name', 'Delta-Sigma Performance'); % Plot the Theoretical Limit (The Blue Line) plot(amp_db, snr_pred, 'b-', 'LineWidth', 2); hold on; % Plot the Actual Simulated Results (The Red Dots) plot(amp_db, snr_sim, 'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 8); % Formatting the plot grid on; axis([-125 5 -20 120]); % Set fixed view for comparison xlabel('Input Amplitude (dBFS)'); ylabel('SNR (dB)'); title(sprintf('Order %d Delta-Sigma Modulator (OSR=%d)', order, OSR)); legend('Predicted Theory (Ideal)', 'Simulated Bitstream', 'Location', 'SouthEast');

Input Arguments
Input spectrum data, specified as a vector or array containing the frequency-domain
coefficients. hwfft represents the in-band bins of the FFT of the
output signal of the delta-sigma modulator.
Data Types: double
Input signal frequency adjusted to be an FFT bin, specified as a real scalar.
f represents the location of the input test tone within the
hwfft vector.
Data Types: double
Number of signal bins, specified as a positive integer scalar.
nsig determines how many bins surrounding the peak index
f are treated as signal power rather than noise. By default, the
function assumes the signal power is contained within a three-bin window where
nsig is set to 1. Increasing nsig by 1 adds
one extra bin to each side of this window.
Data Types: double
Output Arguments
Signal-to-noise ratio (SNR) of the delta-sigma modulator within the frequency range provided by the input spectrum, returned as a scalar.
Version History
Introduced in R2026a
See Also
calculateTF | synthesizeNTF | realizeNTF | stuffABCD | mapABCD | scaleABCD | predictSNR | simulateSNR | simulateDSM
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)