Revision as of 21:25, 29 November 2015 by Xiang6 (Talk | contribs)

1.Introduction

In this section, you will learn how to use the signal processing technique in Matlab to add several sound effects to music. I will introduce three basic sound effects, namely, echo, flanger and chorus.


2.Echo effect

The fundamental theory behind the echo effect is that the original music signal combines with its repeated signal with a fixed delay period. This effect can be achieved by implementing a comb filter. The difference equation for this simple comb filter can be written as follows:

  			Y[n] = X[n] + a * X[n – D]

Where:

X[n] : input signal

Y[n]: output signal

D : number of samples during delay

a : attenuation coefficient. |a| < 1


% Matlab code

[x,fs] = wavread(‘singsing.wav’);  % load the music and get the sampling frequency

length = size(x);  % get the length of the music file

a = 0.3;  % set the attenuation factor

delay = 0.38;

D = delay*fs;  % set the delay time in s

y = zeros(length);  % initialize the output music signal

for i = D + 1 : 1 : length;

	y(i) = x(i) + a*x(i-D);

end;

sound(y, fs);  % play the echo


Example:


3.Flanger effect

The flanging effect is produced by mixing two identical music signals with a varying delay function. Unlike the fixed delay D in the comb filter, the flanger filter has a non-constant delay D, which changes periodically. The difference equation for this simple comb filter can be written as follows:

                                  Y[n] = X[n] + a * X[ n – D[n] ]

% Matlab code:

[y, fs, nbits] = wavread(file);  %Reading the file

low_n = round(0.0*fs);  %Creating the vector according to which delay is varied

high_n = round(0.0057*fs);

delay_vary_p = 8;

delay_step = (delay_vary_p/4)/(1/fs);

delay_1 = round(linspace(low_n,high_n,delay_step));

delay_2 = round(linspace(high_n,low_n,delay_step));

delay = [delay_1 delay_2];

no_points = length(y(:,1));

n_rep = round(no_points/length(delay));

delay = repmat(delay,1,n_rep);

delay = [delay delay(1:no_points-length(delay))];

out_wav(:,1) = zeros(1,no_points);

out_wav(:,2) = zeros(1,no_points);

for i=1:no_points

   n = i-delay(i);
   if n>0
       out_wav(i,1) = y(i,1)+y(n,1);
       out_wav(i,2) = y(i,2)+y(n,2);
   else
       out_wav(i,1) = y(i,1);
       out_wav(i,2) = y(i,2);
   end

end

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett