argument should be a vector

12 views (last 30 days)
Razan Al Hakim
Razan Al Hakim on 28 Nov 2021
Commented: Razan Al Hakim on 28 Nov 2021
figure(1)
subplot (5,1,1)
suspect1=audioread('Bashar.wav'); %importing audio
audiolength1=length(suspect1) %length of audio
[x1,fs1]=audioread('Bashar.wav'); %vector, fs
xFFT1=fft(x1);
f1=-fs1/2:fs1/length(x1):fs1/2-fs1/length(x1);
plot (f1, fftshift(abs(xFFT1)))
noiseAmplitude=0.09;
Noisy_thiefAudio= x2 + noiseAmplitude*rand(audiolength2,1)-noiseAmplitude/2;
noisylength=length(Noisy_thiefAudio)
subplot(5,1,5);
plot(x2,'r-');
WHENEVER I TRY TO CORRELATE, THE ERROR IS "Error using matlab.internal.math.parseXcorrOptions (line 71)
%%%Second argument must be a vector.
%%%Error in xcorr (line 72)
%%% matlab.internal.math.parseXcorrOptions(varargin{:});
I know my Noisy_thiefAudio should be a vector but im not finding a way to convert it. Help please
  3 Comments
Jan
Jan on 28 Nov 2021
What dimensions does Noisy_thiefAudio have? Maybe the imported sound file is recoreded in stereo?
Walter Roberson
Walter Roberson on 28 Nov 2021
Noisy_thiefAudio= x2 + noiseAmplitude*rand(audiolength2,1)-noiseAmplitude/2;
x2 is not defined. audiolength2 is not defined.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 28 Nov 2021
I suspect that your x2 is the output of an audioread(), and that your audio file has two channels (stereo). Your code is expecting that your .wav files only have one channel (mono)
  2 Comments
Razan Al Hakim
Razan Al Hakim on 28 Nov 2021
Walter, this the whole code.
figure(1)
subplot (5,1,1)
suspect1=audioread('Bashar.wav'); %importing audio
audiolength1=length(suspect1) %length of audio
[x1,fs1]=audioread('Bashar.wav'); %vector, fs
xFFT1=fft(x1);
f1=-fs1/2:fs1/length(x1):fs1/2-fs1/length(x1);
plot (f1, fftshift(abs(xFFT1)))
title('Voice of Bashar: Suspect #1 using FFT')
ylabel('Amplitude')
xlabel('Hz')
subplot (5,1,2)
suspect2=audioread('Razanne.wav'); %importing audio
audiolength2=length(suspect2) %length of audio
[x2,fs2]=audioread('Razanne.wav'); %vector, fs
xFFT2=fft(x2);
f2=-fs2/2:fs2/length(x2):fs2/2-fs2/length(x2);
plot(f2, fftshift( abs(xFFT2)))
title('Voice of Razanne: Suspect #2 using FFT')
ylabel('Amplitude')
xlabel('Hz')
subplot (5,1,3)
suspect3=audioread('Aya.wav'); %importing audio
audiolength3=length(suspect2) %length of audio
[x3,fs3]=audioread('Aya.wav'); %vector, fs
xFFT3=fft(x3);
f3=-fs3/2:fs3/length(x3):fs3/2-fs3/length(x3);
plot(f3, fftshift( abs(xFFT3)))
title('Voice of Aya: Suspect #3 using FFT')
ylabel('Amplitude')
xlabel('Hz')
subplot (5,1,4)
suspect4=audioread('Malak.wav'); %importing audio
audiolength4=length(suspect4) %length of audio
[x4,fs4]=audioread('Malak.wav'); %vector, fs
xFFT4=fft(x4);
f4=-fs4/2:fs4/length(x4):fs4/2-fs4/length(x4);
plot(f4, fftshift( abs(xFFT4)))
title('Voice of Malak: Suspect #4 using FFT')
ylabel('Amplitude')
xlabel('Hz')
%Now, I am going to generate the noisy sound signal of the actual thief which is suspect 2 :p
noiseAmplitude=0.09;
Noisy_thiefAudio= x2 + noiseAmplitude*rand(audiolength2,1)-noiseAmplitude/2;
noisylength=length(Noisy_thiefAudio)
subplot(5,1,5);
plot(x2,'r-');
title('The noisy signal of the thief')
ylabel('Amplitude')
xlabel('Hz')
soundsc(Noisy_thiefAudio,fs2);
%Noisy_thiefAudio, audiolength2,and audiolength3 have the same length, so
%zero padding is done using one of them .
figure(2)
Newaudiolength1=audiolength2-audiolength1;
padaudio1=cat(1,suspect1(:,1),zeros(Newaudiolength1,1));
Newaudiolength4=audiolength2-audiolength4;
padaudio4=cat(1,suspect4(:,1),zeros(Newaudiolength4,1));
[Corr1,lag1] = xcorr(f1,x2,'none');
subplot (5,3,1);
plot(lag1,Corr1)
ylabel('Amplitude');
title('Cross-correlation between noisy sound and padaudio1')
[Corr2,lag2] = xcorr(f2,Noisy_thiefAudio,'none');
subplot (5,3,2);
plot(lag2,Corr2)
ylabel('Amplitude');
title('Cross-correlation between noisy sound and padaudio1')
[Corr3,lag3] = xcorr(f3,Noisy_thiefAudio,'none');
subplot (5,3,3);
plot(lag3,Corr3)
ylabel('Amplitude');
title('Cross-correlation between noisy sound and padaudio1')
Razan Al Hakim
Razan Al Hakim on 28 Nov 2021
I messed up in the correlation part. My goal is to correlate the noisy signal with each of the previous 4 signals. Can you help with this?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!