Saturday, June 9, 2012

Simple MATLAB code to add an echo to an audio signal

This code can be used to add an echo to any audio signal.I have used .wav format of the audio signal as it is supported by MATLAB well.Here is the code.


%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.







Some of my Paintings

Poor + Urban + Uneducated 



A Consolidation 



Busy Morning in a Rural Village 



Knight Rider Circuit using PIC16F84A



Hello Friends , This is my very first blog post.


This is a simulation of the knight rider circuit designed using pic16F84A.I used the following C code which was compiled by the mikroC,C compiler for Microchip PIC microcontrollers to generate the .Hex file . I used JDM programmer to write the .Hex file to the microcontroller.


C code

void movedown()
{
     while(PORTB.F7!=1)
     {
                PORTB=PORTB*2;
                delay_ms(100);
     }
}

void moveup()
{
     while(PORTB.F0!=1)
     {
                PORTB=PORTB/2;
                delay_ms(100);
     }
}


void main()
{
     TRISB=0;
     PORTB=0b11111111;
     delay_ms(1000);
     PORTB=1;
     delay_ms(100);
     
     while(1)
     {
              movedown();
              moveup();
     }

}

Schematic of the circuit used