(Created page with "== 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 s...")
 
m
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== 1.Introduction ==
 
== 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.
+
Sound effects such as echo and flanger are largely implemented in sound productions. In this section, you will learn the fundamental ideas of each sound effect and use the signal processing technique in Matlab to create these sound effects to your music.
 
+
  
 
== 2.Echo effect ==  
 
== 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:
+
The echo effect can be simply considered as a delay of music signal. It is produced by repeating the original music signal after a fixed amount of time period [1]. This effect is extremely applied in microphones and stereos. A FIR filter with a single delay will achieve this effect. The difference equation for the FIR filter can be written as follows [3] :
 
   Y[n] = X[n] + a * X[n – D]
 
   Y[n] = X[n] + a * X[n – D]
 
Where:
 
Where:
 +
 
X[n] : input signal
 
X[n] : input signal
 +
 
Y[n]: output signal
 
Y[n]: output signal
D :  number of samples during delay
+
 
 +
D :  number of samples during delay, fixed value
 +
 
 
a :  attenuation coefficient.  |a| < 1
 
a :  attenuation coefficient.  |a| < 1
  
  
 
==== % Matlab code ====
 
==== % Matlab code ====
[x,fs] = wavread(‘singsing.wav’);   % load the music and get the sampling frequency
+
[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
+
length = size(x);           % get the length of the music file  
 +
 
 +
a = 0.3;         % set the attenuation factor
 +
 
 
delay = 0.38;   
 
delay = 0.38;   
D = delay*fs;      %  set the delay time in s
 
  
y = zeros(length);   % initialize the output music signal
+
D = delay*fs;            %  set the delay time in s
 +
 
 +
y = zeros(length);         % initialize the output music signal
 +
 
 
for i = D + 1 : 1 : length;
 
for i = D + 1 : 1 : length;
 +
 
  y(i) = x(i) + a*x(i-D);
 
  y(i) = x(i) + a*x(i-D);
 +
 
end;
 
end;
sound(y, fs);  % play the echo
 
  
Example:
+
sound(y, fs);        % play the echo
  
  
== 3.Flanger effect ==
+
==== Example: ====
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:
+
original music:
                                  Y[n] = X[n] + a * X[ n – D[n] ]
+
  
==== %Matlab code: ====
+
[[File:Singing.wav|thumbnail|singing]]
  
[y, fs, nbits] = wavread(file);  %Reading the file
+
Echo music:
  
            low_n = round(0.0*fs);  %Creating the vector according to which delay is varied
+
[[File:Echo.wav|thumbnail]]
high_n = round(0.0057*fs);
+
  
            delay_vary_p = 8;
 
  
delay_step = (delay_vary_p/4)/(1/fs);
+
== 3.Flanger effect ==
 +
The flanging effect is produced by mixing two identical music signals with a varying delay function [2]. Unlike the fixed delay D in the echo effect design, the flanger filter has a non-constant delay D, which changes periodically. The difference equation for this flanger filter can be written as follows:
 +
                        Y[n] = X[n] + a * X[ n – D[n] ]
  
delay_1 = round(linspace(low_n,high_n,delay_step));
+
Where:
  
delay_2 = round(linspace(high_n,low_n,delay_step));
+
X[n] : input signal
  
delay = [delay_1 delay_2];
+
Y[n]: output signal
  
no_points = length(y(:,1));
+
D : periodic delay function
  
n_rep = round(no_points/length(delay));
+
a :  attenuation coefficient.  |a| < 1
  
delay = repmat(delay,1,n_rep);
+
==== % Matlab code: ====
  
delay = [delay delay(1:no_points-length(delay))];
+
[x,fs,n]=wavread('singing.wav');
  
out_wav(:,1) = zeros(1,no_points);
+
a=2;
  
out_wav(:,2) = zeros(1,no_points);
+
delay=10e-3;
  
for i=1:no_points
+
D=ceil(delay*fs);
  
    n = i-delay(i);
+
length=size(x);
  
    if n>0
+
y=zeros(length);
  
        out_wav(i,1) = y(i,1)+y(n,1);
+
for i=1:1:D+1
 +
    y(i)=x(i);
  
        out_wav(i,2) = y(i,2)+y(n,2);
+
end
  
    else
+
for i=D+1:1:length
  
        out_wav(i,1) = y(i,1);
+
    delay(i)=abs(round(D*cos(2*pi*i/((length-D-1)))));
  
        out_wav(i,2) = y(i,2);
+
    y(i)=x(i)+a*x(i-delay(i));
 
+
    end
+
  
 
end
 
end
 +
 +
==== 4. Referrence ====
 +
[1] Ingle, V., & Proakis, J. (2000). Digital signal processing using MATLAB. Pacific Grove, CA: Brooks/Cole.
 +
 +
[2] Michalski, A. (n.d.). Sound effect. Retrieved November 29, 2015, from http://sound.eti.pg.gda.pl/student/eim/synteza/adamx/eindex.html#wstep
 +
 +
[3] Montero, E., & Romero, J. (2007, December 6). Multi-Effect Processor for Acoustic Guitar. Retrieved November 30, 2015, from http://vbn.aau.dk/ws/files/13379353/Multi-Effect_Processor_for_Acoustic_Guitar.pdf

Latest revision as of 22:49, 29 November 2015

1.Introduction

Sound effects such as echo and flanger are largely implemented in sound productions. In this section, you will learn the fundamental ideas of each sound effect and use the signal processing technique in Matlab to create these sound effects to your music.

2.Echo effect

The echo effect can be simply considered as a delay of music signal. It is produced by repeating the original music signal after a fixed amount of time period [1]. This effect is extremely applied in microphones and stereos. A FIR filter with a single delay will achieve this effect. The difference equation for the FIR filter can be written as follows [3] :

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

Where:

X[n] : input signal

Y[n]: output signal

D : number of samples during delay, fixed value

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:

original music:

File:Singing.wav

Echo music:

File:Echo.wav


3.Flanger effect

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

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

Where:

X[n] : input signal

Y[n]: output signal

D : periodic delay function

a : attenuation coefficient. |a| < 1

% Matlab code:

[x,fs,n]=wavread('singing.wav');

a=2;

delay=10e-3;

D=ceil(delay*fs);

length=size(x);

y=zeros(length);

for i=1:1:D+1

   y(i)=x(i);

end

for i=D+1:1:length

   delay(i)=abs(round(D*cos(2*pi*i/((length-D-1)))));
   y(i)=x(i)+a*x(i-delay(i));

end

4. Referrence

[1] Ingle, V., & Proakis, J. (2000). Digital signal processing using MATLAB. Pacific Grove, CA: Brooks/Cole.

[2] Michalski, A. (n.d.). Sound effect. Retrieved November 29, 2015, from http://sound.eti.pg.gda.pl/student/eim/synteza/adamx/eindex.html#wstep

[3] Montero, E., & Romero, J. (2007, December 6). Multi-Effect Processor for Acoustic Guitar. Retrieved November 30, 2015, from http://vbn.aau.dk/ws/files/13379353/Multi-Effect_Processor_for_Acoustic_Guitar.pdf

Alumni Liaison

To all math majors: "Mathematics is a wonderfully rich subject."

Dr. Paul Garrett