adding echo to an audio file

3 views (last 30 days)
Perturabo
Perturabo on 15 Feb 2019
Answered: Romelyn Ramos on 18 Mar 2021
I have to create a function
output = echo_gen(input, fs, delay, gain);
Where input is a column vector, fs is sampling rate, delay is delay and gain is the gain of the echo, which is less than 1.
The output vector will be longer than the input vector if the delay is not zero (round to the nearest number of points needed to get the delay, as opposed to floor or ceil). A sound recording has values between -1 and 1, so if the echo causes some values to be outside of this range, you will need to normalize the entire vector, so that all values adhere to this requirement.
I have no idea how to approach this, as I have only ever worked with basic matrices as opposed to actual signals in MATLAB.
  1 Comment
Priyamvada Shankar
Priyamvada Shankar on 25 Mar 2019
If anyone knows the correct code please do reply

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 15 Feb 2019
multiply delay in seconds by sampling frequency in samples per second to get number of samples for delay. floor() to get integer count. Call it ds. if ds is 0 then declare an error .
now [1, zeroes(1,ds-1), gain] are coefficients for a filter you can pass the signal through .
After filtering then if max(abs(signal)) is greater than 1 you need to divide by that value to rescale.
  27 Comments
Walter Roberson
Walter Roberson on 13 Apr 2020
what error are you encountering?
Walter Roberson
Walter Roberson on 13 Apr 2020
You should not be concerned about whether the echo part exceeds +/- 1, you should be concerned about whether the output does. for example original data 0.7 echo 0.4, echo is not outside the range +/- 1 but the sum of the two is outside the range.

Sign in to comment.


Romelyn Ramos
Romelyn Ramos on 18 Mar 2021
function [output]= echo_gen(input,fs,delay,amp)
[r,c] = size(input);
extraEchoTime = round(delay*fs);
echoSignal = zeros(r+extraEchoTime,1);
addEchoSignal = echoSignal ;
for i=1:r
echoSignal(extraEchoTime+i,1) =input(i,1)*amp ;
addEchoSignal(i) = input(i);
end
addEchoSignal = addEchoSignal + echoSignal ;
range = abs(addEchoSignal) ;
maxrange = max(range);
if maxrange>1
addEchoSignal = addEchoSignal/maxrange;
end
output = addEchoSignal ;
end

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!