How can I remove the discontinuity in concatenation of wav arrays?
3 views (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
Wayne King
on 15 Sep 2012
Edited: Wayne King
on 15 Sep 2012
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
Wayne King
on 15 Sep 2012
sound1 = detrend(sound1,0);
sound2 = detrend(sound2,0);
Assuming that the two waveforms don't have more complicated trends than a DC shift.
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing 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!