I'm trying to convolve audio signal with impulse response but every time it's giving error as "A & A must be in vector forms"
[sig1, fs] = audioread('mysong1.wav'); % import the song
t = [1:length(sig1)]/fs;
subplot(3,1,1)
plot(t, sig1) % plot the song
xlabel('t (second)')
ylabel('Relative signal strength')
title('Song')
[sig2, fs] = audioread('StNCh.wav'); % import the song
t1 = [1:length(sig2)]/fs;
subplot(3, 1, 2)
plot(t1, sig2) % plot the song
xlabel('t1 (second)')
ylabel('Relative signal strength')
title('Impulse Response')
w = conv(sig1,sig2);
t2 = 0:1:10;
subplot(3,1,3);
plot(t2,w);
xlabel('t2 (second)')
ylabel('Relative signal strength')
title('Convolved Signal')
Please help me to figure out this.

5 commentaires

Walter Roberson
Walter Roberson le 23 Avr 2020
you read two songs of different lengths with two different sample frequency. You convolve them, which is going to give you a result that one fewer samples than the sum of the two lengths; for example conv(4 samples, 9 samples) would result in 4+9-1 = 12 samples.
What time is each of the output samples if the inputs were different frequency?
You then assume that the result has exactly 11 samples, times 0:10. But it is not.
You need to reconsider this process.
Also I recommend reading the options for conv() and thinking about whether one of them is appropriate.
convolution of signals is effectively using one of the signals as a filter on the other signal, where each additional element of the second signal acts like a further time delay. The second signal is roughly deciding how much echo to add to the first signal, and remember that the adding echo makes a signal longer.
Shubhra Sinha
Shubhra Sinha le 23 Avr 2020
Thank you for your assistance Walter. But what I need to do about the vector error?
Walter Roberson
Walter Roberson le 23 Avr 2020
the error now is because your plot has exactly 11 x values, 0 1 2 3 4 5 6 7 8 9 10, but your convolution has many more.
You need to bring the two songs to the same sampling frequency then do the convolution. then construct the x as (0:(length(results)-1))/sampling frequency
Shubhra Sinha
Shubhra Sinha le 23 Avr 2020
Okay, Thank you Walter...
Ricardo Reyes
Ricardo Reyes le 13 Oct 2020
do you have the code fixed up?

Connectez-vous pour commenter.

 Réponse acceptée

Michael Ndungi
Michael Ndungi le 8 Juin 2021

0 votes

[sig1, fs] = audioread('mysong1.wav'); % import the song
t = [1:length(sig1)]/fs;
subplot(3,1,1)
plot(t, sig1) % plot the song
xlabel('t (second)')
ylabel('Relative signal strength')
title('Song')
[sig2, fs] = audioread('StNCh.wav'); % import the song
t1 = [1:length(sig2)]/fs;
subplot(3, 1, 2)
plot(t1, sig2) % plot the song
xlabel('t1 (second)')
ylabel('Relative signal strength')
title('Impulse Response')
w = conv(sig1,sig2);
t2 = 0:1:10;
subplot(3,1,3);
plot(t2,w);
xlabel('t2 (second)')
ylabel('Relative signal strength')
title('Convolved Signal')

3 commentaires

Nurafiqah Mukhtar
Nurafiqah Mukhtar le 21 Déc 2021
i cant use this coding.. may i know why?
wave convolution not came out.
Walter Roberson
Walter Roberson le 21 Déc 2021
I described some reasons in the comments I posted earlier.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by