Line 54: Line 54:
 
==== % Matlab code: ====
 
==== % Matlab code: ====
  
[y, fs, nbits] = wavread(file); %Reading the file
+
[x,fs,n]=wavread('singing.wav');
  
low_n = round(0.0*fs);       %Creating the vector according to which delay is varied
+
a=2;
  
high_n = round(0.0057*fs);
+
delay=10e-3;
  
delay_vary_p = 8;
+
D=ceil(delay*fs);
  
delay_step = (delay_vary_p/4)/(1/fs);
+
length=size(x);
  
delay_1 = round(linspace(low_n,high_n,delay_step));
+
y=zeros(length);  
  
delay_2 = round(linspace(high_n,low_n,delay_step));
+
for i=1:1:D+1
 +
    y(i)=x(i);
  
delay = [delay_1 delay_2];
+
end
  
no_points = length(y(:,1));
+
for i=D+1:1:xlen
  
n_rep = round(no_points/length(delay));
+
    delay(i)=abs(round(D*cos(2*pi*i/((xlen-D-1)))));
  
delay = repmat(delay,1,n_rep);
+
     y(i)=x(i)+a*x(i-delay(i));
 
+
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
 
end
Line 104: Line 81:
 
==== Referrence ====
 
==== Referrence ====
 
[1] Ingle, V., & Proakis, J. (2000). Digital signal processing using MATLAB. Pacific Grove, CA: Brooks/Cole.
 
[1] Ingle, V., & Proakis, J. (2000). Digital signal processing using MATLAB. Pacific Grove, CA: Brooks/Cole.
 
[2] McGovern, S. (2004, December 30). Flange Effect - File Exchange - MATLAB Central. Retrieved November 30, 2015, from      http://www.mathworks.com/matlabcentral/fileexchange/6656-flange-effect
 

Revision as of 22:19, 29 November 2015

1.Introduction

Sound effects as echo, flanger and chorus 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 effect 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. 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:

  			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


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 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:xlen

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

end

Referrence

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

Alumni Liaison

Prof. Math. Ohio State and Associate Dean
Outstanding Alumnus Purdue Math 2008

Jeff McNeal