%code to add an echo to an audio signal by charitha saumya
function echo_constant
[g,fs] = wavread('signalsExp1.wav');
delay=2*fs;
delayedsignal=zeros(length(g),2);
for n=1:1:length(g)
if(n<=delay )
delayedsignal(n,1)=0;
delayedsignal(n,2)=0;
end
if(n>delay)
delayedsignal(n,1)=0.65*g(n-delay,1);
delayedsignal(n,2)=0.65*g(n-delay,2);
end
end
echosignal=zeros(length(g),2);
for n=1:1:length(g)
echosignal(n,1)=(g(n,1)+delayedsignal(n,1))*0.5;
echosignal(n,2)=(g(n,2)+delayedsignal(n,2))*0.5;
end
wavplay(echosignal,44100);
wavwrite(echosignal,44100,16,'echo_constant.wav');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
you should copy and paste the .wav file that you want to add an echo to, to the matlab working directory and rename it as signalsExp1.wav .unless the code won't work.The generated echoed signal will be saved in the working directory as echo_constant.wav.
How this code works?
Say s(t) is the original audio signal . The code generates a delayed version of the signal by multiplying it by α (α may be a constant or a function of time.but in this code α is just a constant) and delaying it by a fixed time period . So the delayed signal will be of the form,
Finally this delayed signal is added to the original audio signal to generate the echo signal.
Hi!!!
ReplyDeleteI'm trying to test your code, I receive this error:
A(I,J): column index out of bounds; value 2 out of
bound 1
How could I fix it?
Thanks a lot,
Giacomo
Could you please tell me what is A(i,j)??
DeleteI don't know, I've just copy-paste your code and changed the .wav file, but appear that error.
Deletemake sure that you rename it properly as signalsExp1.wav and wav file is in the working dir.
Deletetest these functions seperately
[g,fs] = wavread('filename.wav'); and
wavplay(g,44100);
wavplay should play any .wav file in matlab. test these functions separately. It might help you to figure out the error.
can any on tell me that where is the working directory ?
Deleteworking directory can be anywhere you like. make sure that you are keeping your .m file in working directory.
DeleteI have the same error: A(I,J): column index out of bounds; value 2 out of
Deletebound 1
have you fixed it?
There is no variable named "A" in this code. So i am also confused about your problem. FYI i used matlab 2012a version and it's working fine.
Deletecan you explain the code sir please
ReplyDelete