Xg1. CpXpvOD
MATLABgpĂ܂Ǎgplezł悤ɁAMATLABŗL̃xNgZ֐̎gp͂Ă܂B̂߁AZԂ̂ŁAMATLABgpĺA̓_ǁiݍ݂conv֐𗘗pjĂgpB



% CpXvO
% MATLAB@@@TDU, Y. Kaneda, 2013.12
 
%%
clear all;close all;
%% -- ݒl
fs=48000; NN=2^15; AA=0.8;
%% -- TSP M̍
kk = 0 : NN-1;                % kkFUgԍ
S(kk+1) = exp(-j*2*pi*NN/2*(kk/ NN).^2 ); % (6)
S( NN/2+2: NN) = conj( S( NN/2: -1: 2));  % (6)
 
ss = real(ifft(S));           % tFFTŎԔg`𓾂
% g`̌㔼1/4擪Ɉړ
ss = [ss(NN/4*3+1: NN), ss(1:NN/4*3 )]; 
ss = ss /(max(abs(ss)) /AA);  % UőAAɂ
 
%% --- TSPM̍ĐƘ^
wavplay(ss,fs,'async')        % TSPM̍Đ
rec = wavrecord(NN*2,fs);     % ĐM^
 
%% --- ^M̕\Ɛ؂o
figure(11); plot(rec,'k'); grid on;  % \
xlabel('ԁif[^j'); ylabel('U');xlim([0,inf]);
% \f[^Ę^M̐؂oJn_ƏI_
% L[{[h
ip1 = input('^M̐؂oJn_́H');
ip2 = input('^M̐؂oI_́H');
% ؂o̕\imFpj
figure(11); hold on;plot([ip1:ip2],rec(ip1:ip2),'r'); grid on; 
recc = rec(ip1:ip2); % ؂oʂ recc ɑ
 
%% --- ttB^̂ݍ(ꍇ܂)
ss_1 = ss(NN:-1:1); % TSP ̋ttB^M
% ^M̑ONN_ 0 f[^t
rec2 = [zeros(NN,1);recc;zeros(NN,1)];
% ݍ݉ZF
% ʂ̑S recc  ss_1 ̘̒a|1
for ii = 1:length(recc)+length(ss_1)-1
    if mod(ii,1000)==0;disp(ii); end % ro߂\
    ir0=0;
    for jj = 1:length(ss_1)
        ir0=ir0+ss_1(jj)*rec2(ii-jj+length(ss_1));
    end
    ir(ii)=ir0;
end


%% --- CpX̕\Ɛ؂o
figure(13); plot(ir,'k'); grid on;  % \
xlabel('ԁif[^j'); ylabel('U')
% \f[^ăCpX̐؂oJn_
% I_L[{[h
ip3 = input('CpX̐؂oJn_́H');
ip4 = input('CpX̐؂oI_́H');
% ؂o̕\imFpj
figure(13); hold on;plot([ip3:ip4],ir(ip3:ip4),'r'); grid on;
irc = ir(ip3:ip4); % ؂oʂ irc ɑ
 
%% --- gǓvZƕ\
% 0 f[^tđSNNƂ
ir1 = [irc,zeros(1,NN-length(irc))];  
 % CpXFFTĎg𓾂
IR = abs(fft(ir1));   
ff = [0:NN/2]/NN*fs;   % ǧvZ
figure(14);semilogx(ff,10*log10(IR(1:NN/2+1).^2));grid on
xlabel('g (Hz)'); ylabel('U (dB)')
 
%% --- cȐ
MM = length(irc);
for ii = 1:MM;
    r0 = 0;
    for jj=ii:MM
        r0 = r0+irc(jj)*irc(jj); % ii  MM ܂ł̓a
    end
    r(ii)=r0;
end
 
r = r/r(1);                      % SԂ̓aŐK
 
figure(15)
tt = (1:length(r))/fs;
plot(tt, 10*log10(r));grid on;
xlabel(' (b)'); ylabel('cGlM[ (dB)')
 
return

