[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: auditory scrambling



Attached is some Matlab code written by Keansub Lee in my lab when we were
looking at making "personal audio lifelog" recordings unintelligible while
preserving the statistics needed for classifying environment and speakers.

It chops the sound into overlapping 200ms windows and permutes them
within a 1 second radius.  Basic usage is just y = scrambling(d,sr);
where d is the input audio and sr is the sampling rate.  See comments
in the file for changing the parameters (window length, overlap, scramble
radius etc.).

Also attached are a brief speech sound before and after scrambling.
Apologies to digest readers who will probably see a great deal of
meaningless ascii.

  DAn.
function y = scrambling(x, sr, h, w, wintype, s)

%    
% x is a input signal and sr is samplingrate.  
% Using w-points[200ms] windows every h-points[100ms] over s-points[1 sec] radius, 
% scramble the input signal.  
% Make sure that the length of window should be smaller than 2*(frame's length) 
%
% For example, 
% [x,sr]= wavread('mdwh0_sx305.wav');
% h = sr*.1; 
% w = h*2;
% wintype = 'sinewin';
% s = sr;
% y = scrambling(x, sr, h, w, wintype, s);

% 2004-10-14 kslee@xxxxxxxxxxxxxxx

if nargin < 3
  h = sr*0.1; % 100ms, frame length
end
if nargin < 4
  w = 2*h; % 200ms, window length
end
if nargin < 5
  wintype = 'sinewin'; % window type
end
if nargin < 6
  s = sr; % 1s, segments length
end
  
switch wintype
case 'sinewin'
    wt = sin(pi*([0:(w-1)]' + 0.5)/w);;
case 'hanningwin'
    wt = hanning(w);
end

if (size(x,1) == 1)
  x = x';  % Convert X from row to column
end

%x= x(1:sr*3);
% the points of input signal
npts = length(x);

% the total number of segments within input signal
nsegs = floor(npts/s);

% the total number of frames within each segment
nhops = floor(s/h);

y = [];

for seg = 1:nsegs
    
    % Extract segment of signal
    xx = x((seg - 1)*s + [1:s]);
    
    % points to be scrambled and remained 
    xxs = xx(1:nhops*h,1);
    xxr = xx((nhops*h + 1):end,1);
    
    % Pad x with zeros to extract complete w-length windows from it
    xxs = [zeros((w-h)/2,1);xxs;zeros((w-h/2),1)];
    
    % save the scrambled signal
    yys = zeros((nhops+1)*h,1);
    
    % random permutation
    nrands = randperm(nhops);
    
    for hop = 1:nhops
        
        % Break the signal into w-length windows
        xxsw = xxs((nrands(hop) - 1)*h + [1:w]);
        
        % Apply window
        wxxsw = xxsw .* wt; 
        
        % reverse and save it
%        yys((hop - 1)*h + [1:w],1) = yys((hop - 1)*h + [1:w],1) + wxxsw([end:-1:1]);
        yys((hop - 1)*h + [1:w],1) = yys((hop - 1)*h + [1:w],1) + wxxsw;
        
    end
   
    % trancate the # of zeros padding points to have a same size of original 
    yy = [yys(h/2+1:end-h/2,1);xxr];
    
    y = [y;yy];
    
end

Attachment: mpgr1_sx419.wav
Description: Wave audio

Attachment: scrambled.wav
Description: Wave audio