How do I use correlation coefficients with two audio samples?

5 ビュー (過去 30 日間)
Taylor Gray
Taylor Gray 2019 年 4 月 5 日
回答済み: Anay 2025 年 6 月 2 日
Hi, I spectrally analysed a machine gun burst sample and used a spectral modelling synthesis model in Max/MSP to procedurally generate it in real-time and now I'm wanting to use correlation to see how close I got. Due to lack of knowledge in MATLAB I'm looking for a little help to gain my metric. I have attached the audio files
A = "Machine_Gun_Burst.wav";
B = "Dry_Synthesized_Machine_Gun_Burst.wav";
R = corrcoef(A,B);
This was my failed attempt and i got the below error message:
Error using corrcoef>getparams (line 296)
Unmatched parameter name/value pair.
Error in corrcoef (line 119)
[alpha,userows] = getparams(varargin{:});

回答 (1 件)

Anay
Anay 2025 年 6 月 2 日
Hi Taylor,
The error occurred because “corrcoef” expects numerical value of the signals and you were passing the filenames as string. “corrcoef” returns a 2x2 matrix which has ones on the diagonal and correlation coefficients on the off-diagonal elements. You can use “audioread” function to load the audio sample into numeric matrices.
% Read audio files
[orig, fs_orig] = audioread('Machine_Gun_Burst.wav');
[synth, fs_synth] = audioread('Dry_Synthesized_Machine_Gun_Burst.wav');
% Compute Pearson correlation coefficient
correlation_matrix = corrcoef(orig, synth);
r = correlation_matrix(1, 2); % Off-diagonal element
You can refer to the documentation to gain more information about “corrcoef” by following the below link:

カテゴリ

Help Center および File ExchangeGet Started with Signal Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by