% This script generates a m/c wav files contaoninh a sequence 
% of 84 Dirac Pulses - for feeding the SPCMIC program
clear all
close all
N = 4096; % length of each Dirac Pulse buffer
p = 512;  % position of the pulse inside the buffer
M = 84;   % number of channels
Dirac=zeros(N,1); % buffer of zeros
Dirac(p)=1.0; % unit pulse at sample p = 512
Output=zeros(N*(M+2),M); % Length increased by 2 buffers, one before and one after the data
L=length(Output);
% Copy the Dirac pulse to each of the 84 channels, with temporal shift
for i=1:M
    for j=1:N
        Output(i*N+j,i)=Dirac(j);
    end
end
% plot the multichannel Dirac Delta diagonal matrix
figure 
plot(Output(:,1)+1);
hold on
for i=2:M
    plot((Output(:,i)+i));
end   
hold off
xlabel('samples')
ylabel('channel n.')
xlim([0 L])
ylim([0 M+1])
% save the result in a WAV file
audiowrite('Dirac_84ch.wav',Output,48000,'BitsPerSample',24);