Created wave files - getting clicking noises

12 views (last 30 days)
Michael
Michael on 17 Jul 2012
Commented: AMB on 13 May 2018
Hi,
I'm trying to create some wavefiles in matlab, and everything seems to be going well except that I'm getting weird clicking sounds at the beginning and end of the wave. Anyone know why this might be?
%%
sf = 22050; % sample frequency (Hz)====== sampling rate
d = .5; % duration (s)=========duration
n = sf * d; % number of samples
silence= zeros(1,n);
% set carrier
cf = 378; % carrier frequency (Hz)
c = (1:n) / sf; % carrier data preparation
c = 2 * pi * cf * c;
% set modulator
mf = 3; % modulator frequency (Hz)===== modulation frequency
mi = 150; % modulator index============= what we call modulation depth
m = (1:n) / sf; % modulator data preparation
m = mi * cos(2 * pi * mf * m); % sinusoidal modulation
% frequency modulation
s = sin(c + m); % frequency modulation
s=[silence s silence];
% sound presentation
sound(s, sf); % sound presentation
pause(d + 0.5); % wating for sound end
wavwrite(s,sf,'fmsound.wav')
  1 Comment
Walter Roberson
Walter Roberson on 17 Jul 2012
... beginning and the end. Possibly exactly matching your "silence", or is it more than 1/2 second?

Sign in to comment.

Answers (1)

Jan
Jan on 17 Jul 2012
Edited: Jan on 17 Jul 2012
Correct, there is a click at the start and the end of the sound. The surrounding silence is not the problem. It's only the sudden start and end of the signal, which causes the clicks. You can draw the signal and use the zoom tool to see the sharp edges.
plot(s)
  1 Comment
AMB
AMB on 13 May 2018
Hi
Consider the following example playing sig produces a click but playing y does not. y has a weight applied which gets rid of the click
fs = 2000; t = 0 : 1/fs : 0.3; sig = 0.7 * chirp(t,0,0.3,10000); nS = length(sig); w = .5*(1 - cos(2*pi*(1:nS)/(nS+1))); y = w.*sig; sound(sig,fs,8) pause(1) sound(y,fs,8) plot(t,sig,t,y)
V/r
amb

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!