Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc, clear, close all
- [x, Fs1] = audioread('whitenoise2018.wav');
- [y, Fs2] = audioread('whitenoise_rec2018.wav');
- Rxx = xcorr(x,x);
- Rxy = xcorr(x,y);
- dt = 10/length(x);
- T = 10;
- t = 0:dt:T-dt;
- fs = Fs1;
- X = fft(x);
- Y = fft(y);
- subplot(2,1,1);
- plot((-length(Rxx)/2 : length(Rxx)/2-1)/fs*1000, Rxx) %s->ms
- axis tight;
- xlabel('czas [ms]');
- ylabel('Rxx');
- title('Autokorelacja Rxx');
- grid on;
- subplot(2,1,2);
- tR = (-length(Rxy)/2 : length(Rxy)/2-1)/fs*1000;
- plot(tR, Rxy) %s->ms
- axis tight;
- xlabel('czas [ms]');
- ylabel('Rxy');
- title('Korelacja krzyżowa Rxy');
- grid on;
- [peak1, index1] = max(Rxy); %odległość liczona opóźnienia korelacji krzyżowj
- distance1 = abs(tR(index1))*320/1000;
- figure();
- H = Y./X;
- N = length(H);
- absH = abs(H);
- argH = unwrap(angle(H));
- f=(0:length(absH)/2-1)*fs/(length(absH));
- subplot(2,1,1);
- semilogx(f,20*log((absH(1:N/2))));
- axis tight;
- xlabel('częstotliowość [Hz]');
- ylabel('|L|');
- line([fs/2 fs/2], ylim,'Color',[1 0 0],'LineWidth',1);
- title('Ch-ka amplitudowo-częstotliwościowa');
- grid on;
- subplot(2,1,2);
- semilogx(f,(argH(1:N/2)));
- axis tight;
- xlabel('częstotliowość [Hz]');
- ylabel('faza [ ^o]');
- line([fs/2 fs/2], ylim,'Color',[1 0 0],'LineWidth',1);
- title('Ch-ka fazowowo-częstotliwościowa');
- grid on;
- figure();
- h = ifft(H);
- plot(t(1:1500),h(1:1500));
- axis tight;
- xlabel('czas [s]');
- ylabel('A');
- title('Odpowiedź impulsowa');
- grid on;
- [peak2, index2] = max(h); %odległość liczona z opóźniania odp. impulsowej
- distance2 = index2/fs*320;
- [maxRxx,IRxx]=max(Rxx); %odległość liczona z różnicy czasu autokorelacji i korelacji krzyżowej
- [maxRxy,IRxy]=max(Rxy);
- tdiff1=abs(IRxx-IRxy)/fs;
- distance3=tdiff1*320;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement