xcorr command makes mistake at 10^-5 order.
2 ビュー (過去 30 日間)
古いコメントを表示
function t = xcoor_time_interval(s1, s2, Fs, tit, plot_wanted)
%XCOOR_TİME_İNTERVAL Summary of this function goes here
% Detailed explanation goes here
% Xcoor is put cross correlation of two signals
[c,lags] = xcorr(s1,s2);
% If it wanted xcoor is plotted
if plot_wanted
figure
plot(lags,c);
title(tit);
grid on
end
[~,iLag] = max(abs(c));
t = -(1/Fs)*(lags(iLag));
end
This was my function and main function is:
clc;
clear all;
close all;
addpath('functions');
% Import audio file
filename = '481583__malatestiniccom__gun-3.wav';
% Get audio signal and signals sampling frequancy in Hz
[s1,Fs] = audioread(filename);
s1 = s1(:,1);
s2 = delayseq(s1, -0.00120612644267, Fs);
s3 = delayseq(s1, 0.00102887528457, Fs);
s4 = delayseq(s1, -0.00023602278035, Fs);
s5 = delayseq(s1, 0.00003558800237, Fs);
% Fs = 44100;
% w = 10;
%
% x1 = 0:1/Fs:1;
% x2 = x1 + 0.00120612644267;
% x3 = x1 - 0.00102887528457;
% x4 = x1 + 0.00023602278035;
% x5 = x1 - 0.00003558800237;
%
% s1 = sin(2*pi*x1);
% s2 = sin(2*pi*x2);
% s3 = sin(2*pi*x3);
% s4 = sin(2*pi*x4);
% s5 = sin(2*pi*x5);
plot_wanted = input("Should I plot the figures[true/false]: "); % Determine function should be plot the figure
% if plot_wanted
% figure
% plot(s1);
% hold on
% plot(s2);
% hold on
% plot(s3);
% hold on
% plot(s4);
% hold on
% plot(s5);
% end
% Get time difference by using xcoor refernce is s1 signal
t12 = xcoor_time_interval(s1, s2, Fs, 's1-s2', plot_wanted);
t13 = xcoor_time_interval(s1, s3, Fs, 's1-s3', plot_wanted);
t14 = xcoor_time_interval(s1, s4, Fs, 's1-s4', plot_wanted);
t15 = xcoor_time_interval(s1, s5, Fs, 's1-s5', plot_wanted);
% t12 = vpa(-0.00120612644267,12);
% t13 = vpa(0.00102887528457,12);
% t14 = vpa(-0.00023602278035,12);
% t15 = vpa(0.00003558800237,12);
% t12 = -0.0012;
% t13 = 0.0010;
% t14 = -2.2676e-04;
% t15 = 4.5351e-05;
and like it is shown here the xcorr command makes mistake at the 10^-5 order and it effects my solution much. How can i solve that?
0 件のコメント
採用された回答
Pratyush
2023 年 9 月 26 日
I understand that 'xcorr' command is not accurate enough at 10^-5 order.
The discrepancy you're experiencing with the `xcorr` command at the 10^-5 order may be due to the limited precision of floating-point arithmetic. To mitigate this issue, instead of using the `xcorr` function, you can try using other cross-correlation methods that might provide better accuracy. One such method is the Fourier Transform-based cross-correlation (`xcorr_fft`). You can also use the Variable Precision Arithmetic (VPA) toolbox in MATLAB to increase the precision of your calculations. See if it helps improve the accuracy of your solution.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!