Skip to content

Commit

Permalink
Added RMS levels of DUT and REF signals at soundcard input.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrennwa committed Dec 30, 2015
1 parent 4b554b5 commit d3fba18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions mataa_tools/mataa_guess_IR_start.m
Expand Up @@ -20,7 +20,7 @@
% EXAMPLE:
% > [h,t] = mataa_IR_demo; % load demo data of an loudspeaker impulse response.
% > mataa_plot_IR(h,t); % plot the fake signal
% > [t_start,t_rise] = mataa_guess_IR_start(h,t,200)
% > [t_start,t_rise] = mataa_guess_IR_start(h,t,20)
%
% This gives t_start = 0.288 ms and t_rise = 0.0694 ms. In this example might therefore safely discard all data with t < t_start. In real-world use (with noise and Murphy's law against us), however, it might be worthwile to add some safety margin, e.g. using t_rise: discard all data with t < t_start - t_rise.
%
Expand Down Expand Up @@ -62,8 +62,8 @@

if ~isempty (fc) % apply high-pass filter to remove low-frequency noise
fn = fs/2; % Nyquist frequency
[b,a]=butter (4,fc/fn,'high'); % 4th order high-pass Butterworth filter
h = filter(b,a,h);
[b,a] = butter (4,fc/fn,'high'); % 4th order high-pass Butterworth filter
h = filter(b,a,h);
end

badShape = 'mataa_guess_IR_start: the signal does not look like a well-shaped impulse response.';
Expand Down
13 changes: 9 additions & 4 deletions mataa_tools/mataa_measure_HD.m
@@ -1,6 +1,6 @@
function [THD,kn,f1] = mataa_measure_HD (f1,T,fs,N);
function [THD,kn,l0DUT,l0REF] = mataa_measure_HD (f1,T,fs,N);

% function [THD,kn] = mataa_measure_HD (f1,T,fs,N);
% function [THD,kn,l0DUT,l0REF] = mataa_measure_HD (f1,T,fs,N);
%
% DESCRIPTION:
% This function measures harmonic distortion using a sine wave with a given frequency.
Expand All @@ -15,6 +15,7 @@
% THD = total harmonic distortion, see below.
% kn: harmonic distortion spectrum, in voltage units (not power). kn is a vector containing the harmonic components (k1, k2, k3, ... kN), where k1 corresponds to f1. The spectrum is normalised such that k1 is equal to one.
% f1: true value of f1 used for analyses (value may be adjusted slightly to fit in the resolution of the fourier spectrum).
% l0DUT, l0REF: RMS level of the DUT and REF signals at the soundcard input (useful for repeated tests at different levels)
%
% NOTE 1: THD is computed WITHOUT the noise in the spectrum ranges between the harmoics.
%
Expand Down Expand Up @@ -74,7 +75,7 @@

%x = [ z ; x ; z ];

[out,in] = mataa_measure_signal_response(x,fs,0.1);
[out,in] = mataa_measure_signal_response(x,fs);

yDUT=out(:,mataa_settings('channel_DUT'));
yREF=out(:,mataa_settings('channel_REF'));
Expand All @@ -95,6 +96,10 @@
yDUT = yDUT.*w;
yREF = yREF.*w;

% pre-normalize signals by their RMS value
l0DUT = sqrt (sum(yDUT.^2)) / length (yDUT); yDUT = yDUT / l0DUT;
l0REF = sqrt (sum(yREF.^2)) / length (yREF); yREF = yREF / l0REF;

% calculate signal spectra (voltages!)
[YDUT,f] = mataa_realFT(yDUT,t);
[YREF,f] = mataa_realFT(yREF,t);
Expand All @@ -120,7 +125,7 @@

i = find(kn < 0);
if any(i)
warning('mataa_measure_HD: some signal harmonics are negative. Is the REF signal clipped or otherwise corrupted?');
warning('mataa_measure_HD: some signal harmonics are negative. Is the REF signal clipped or otherwise corrupted? Too much noise?');
end

THD = sqrt( sum( kn(2:end).^2 ) ) / kn(1);

0 comments on commit d3fba18

Please sign in to comment.