adding echo to an audio file

8 次查看(过去 30 天)
Perturabo
Perturabo 2019-2-15
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.

回答(2 个)

Walter Roberson
Walter Roberson 2019-2-15
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 个评论
Walter Roberson
Walter Roberson 2020-4-13
what error are you encountering?
Walter Roberson
Walter Roberson 2020-4-13
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.

请先登录,再进行评论。


Romelyn Ramos
Romelyn Ramos 2021-3-18
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

类别

Help CenterFile Exchange 中查找有关 Time-Frequency Analysis 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by