How can I remove the discontinuity in concatenation of wav arrays?

Hello, I'm a beginner in matlab. I have a question: I have tried to concatenate two wav arrays, and I have played the result of the concatenation. There's a small discontinuity between the two sounds in the reproduction, although I have eliminated a number of samples at the end of the first sound and the beginning of the second. I can't remove other samples without damaging the information contained in the signals. How could I solve this problem? I wish the final sound seemed as natural as possible (the two initial sounds are syllables, and the final one is the word formed by the two syllables). This is a piece of the code:
%The two sounds have the same sampling frequency.
[sound1,Fs]=wavread('ca.wav');
sound2=wavread('ne.wav');
sound1=sound1(1:(size(sound1,1)-500));
sound2=sound2(50:end);
sound3=[sound1' sound2'];
sound(sound3,Fs);

 Accepted Answer

How big is the discontinuity? I'm assuming the two waveforms are both essentially zero-mean waveforms. If not, you'll want to shift them to make them zero mean.
Then, one thing you can do is to apply a moving average filter to smooth out the discontinuity. I'll use a 5-point moving average filter here. I would try a low order filter first, because you probably don't want to filter your signal too much (it is a lowpass filter). The larger the magnitude of the discontinuity, the higher order you would need.
t = 0:0.01:1;
x = cos(2*pi*t).*(t<=0.5)+cos(2*pi*t-pi/8).*(t>0.5);
plot(t,x,'r'); hold on;
h = 1/5*ones(5,1);
y = filtfilt(h,1,x);
plot(t,y,'b')

3 Comments

The discontinuity is not very big, but it's really annoying. I want to follow your advice, but the waveforms aren't zero mean. How can I shift them? Thank you in advance.
sound1 = detrend(sound1,0);
sound2 = detrend(sound2,0);
Assuming that the two waveforms don't have more complicated trends than a DC shift.
Ok, now the final sound is really better. Thanks a lot!

Sign in to comment.

More Answers (0)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!