argument should be a vector

조회 수: 8 (최근 30일)
Razan Al Hakim
Razan Al Hakim 2021년 11월 28일
댓글: Razan Al Hakim 2021년 11월 28일
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
Jan
Jan 2021년 11월 28일
What dimensions does Noisy_thiefAudio have? Maybe the imported sound file is recoreded in stereo?
Walter Roberson
Walter Roberson 2021년 11월 28일
Noisy_thiefAudio= x2 + noiseAmplitude*rand(audiolength2,1)-noiseAmplitude/2;
x2 is not defined. audiolength2 is not defined.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 11월 28일
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
Razan Al Hakim
Razan Al Hakim 2021년 11월 28일
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 2021년 11월 28일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by