1
$\begingroup$

I need help by adding an echo in to a 8kHz, 1 channel, 8 bit voice signal. I need to use this equation to add the signal x(n)=s(n)+r1s(n-k1)+r2s(n-k2) where r1=.6,r2=.3, k1=5 seconds, and k2=12 seconds.

[y,fs]=audioread('voice.wav');             
t=[1/fs:1/fs:length(y)/fs];      
sound(y,fs);       
figure     
plot(t,y)  
y1=y+.6*y*(40000)+y*.3*(96000);  
sound(y1)    
plot(y1)

when I play it back it does not have an echo. any help on this would be appreciated.

$\endgroup$
2
  • $\begingroup$ Where are you putting the delays of 5 seconds and 12 seconds? $\endgroup$ – Peter K. Feb 1 '17 at 2:16
  • $\begingroup$ the 40000 and 96000. I changed from time to Hz. 8000Hz*5s=40000 and 12*8000=96000 $\endgroup$ – keith Feb 1 '17 at 4:08
1
$\begingroup$

You have not followed the very equation that you posted:

$x[n] = s[n] + r_1 s[n - k_1] + r_2 s[n - k_2]$

Rather you have implemented

$x[n] = s[n] + r_1 k_1 s[n] + r_2 k_2 s[n]$

$\endgroup$
7
  • $\begingroup$ s(n) is the signal. what do I put in for n? what does the code look like? $\endgroup$ – keith Feb 1 '17 at 3:51
  • 1
    $\begingroup$ You will need to create two new signals, one for each echo. You need to decide whether you want the final signal to be the same length as the original or whether it will be longer so as to include all of the echoes. Then your two new signals will be delayed (and scaled) versions of the original signal, which you can then add together to get a final signal. $\endgroup$ – lxop Feb 1 '17 at 4:09
  • $\begingroup$ I sorry I am not that good at matlab. I just need an example. all the examples I have seen are not like the ones have. can you at least give me an example to go with. $\endgroup$ – keith Feb 1 '17 at 4:46
  • $\begingroup$ I know the delay should be 5 seconds and 12 seconds. what code do I need to use to delay these by 5 seconds and 12 seconds? My professor told use we needed to convert the given values of k1 and k2 in seconds to the values in the unit of samples when you synthesize the signal. I don't want anyone to do the project for me I am just stuck at this point and would like a little push to help me get going in the right direction. This is the only part of the project that I am having problems. $\endgroup$ – keith Feb 1 '17 at 4:57
  • 1
    $\begingroup$ You have already done the bit your professor said you needed to do. Do you want a result signal that is the same length as your original or that includes all of the echo? $\endgroup$ – lxop Feb 1 '17 at 5:23
1
$\begingroup$

I figured out the problem I was having. Thanks for the help. here is the code that I will use.

[sn,Fs] = audioread('voice.wav');  %loads recorded wave file   
 figure  
 plot(sn)  %plots the orginal signal with out echoes.  
 pause(10); %pauses the signal 10 seconds   
 k1 = 5; % 5s delay                         
 r1 = 0.6; % echo strength        
 D = k1*Fs; %multiplies k1 with Fs which equals 40000Hz   
 y = zeros(size(sn)); %adds zeros at the begining of the  echo signal   
 y(1:D) = sn(1:D); %makes the  1st echo signal the same as sn    
 k2=12; %12s delay   
 r2=.3; %echo strength   
 D2=k2*Fs;% multiplies k2 with Fs which equals 96000Hz  
 y1=zeros(size(sn)); %adds zeros to the begining of the echo signal  
 y1(1:D2)=sn(1:D2); %makes 2nd echo the same length as sn   

 %the following 2 for loops adds 1 to the D example: first pass through  
 %the loop 1 is added to 40000 it continues to add 1 to D until   
 %the length of the signal is reached. the same thing happens on second   
 %loop only it adds 1 to D2.   

 for i=D+1:length(sn)  
   y(i) = sn(i) + r1*sn(i-D);   
 end  
 for i=D2+1:length(sn) 
   y(i) = sn(i) + r2*sn(i-D2);  
 end  

 sound(y,Fs); %plays the sound file with both echoes.   
 figure
 plot(y) %plots file with echoes.  
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.