이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
adding echo to an audio file
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (2개)
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
2019년 2월 15일
conv(in, [1,zeroes(1,ds-1),gain])
you might need to reverse that so gain then zeroes then 1
Walter Roberson
2019년 2월 15일
oh wait I am not sure this will feed back the echo. Best search Answers to see how other people implement it .
Perturabo
2019년 2월 19일
편집: Perturabo
2019년 2월 19일
here is what i tried
function output = echo_gen(in,fs,delay,gain)
samples = delay*fs;
ds = floor(samples);
s = zeros(length(in)+ds,1);
signal = [in;zeros(length(s)-ds,1)];
echo_signal = [zeros(length(s)-ds,1);in*gain];
output1 = signal + echo_signal;
for i = 1:length(output1)
if output1(i)>1
output1(i) = output1(i)/max(output1);
end
end
output = output1;
end
code to call the function
% Load splat which adds y and Fs to the workspace
load splat
% Call echo_gen to create the new audio data
output = echo_gen(y, Fs, 0.25, 0.6);
% Create a time axis. The time between points is 1/Fs;
dt = 1/Fs;
t = 0:dt:dt*(length(output)-1);
% Plot the new data to see visualize the echo
plot(t, output)
% sound (newY, Fs) % Uncomment in MATLAB to listen to the new sound data
but the vector size is way too off. I have been on it for so many days now and its become too frustrating. What am I doing wrong?
Here are the output and the problem function btw
Jesus Sanchez
2019년 2월 19일
Have you tried to directly generate the echo signal? Following this form:
[input_signal ; delay ; echo signal]. Here I assumed delay is the time you want to wait until the echo is heard.
In code:
samples = delay*fs;
ds = floor(samples);
output = [in ; zeros(ds,1) ; in*gain];
another alternative, if you want to separate the echo signal:
samples = delay*fs;
ds = floor(samples);
echo_signal = in*gain;
output = [in ; zeros(ds,1) ; echo_signal];
Perturabo
2019년 2월 19일
output = [in;zeros(ds,1);echo_signal];
would produce error since vectors don't have same dimensions. i mean the zeros and the other two. That's why the whole [in;zeros(length(a)-length(b),1] thing.
Walter Roberson
2019년 3월 23일
How many channels in your signal? Using zeros(ds,1) implies you are expecting only one channel.
paul mary
2019년 3월 24일
Hello Priyamvada, I finished this task and the total mooc course. I can give you some hints.
- echoSignal = Signal + echo, so think about
for i =
output() = output() + y * amp;
end
- if the echo causes some values to be outside of this range, you will need to normalize the entire vector, That is, if there is a value greater than one, divide every element of that signal by the maximum value.
if max(output)>1
end
- round to the nearest number of points needed to get the delay, as opposed to floor or ceil. It's very important.
I hope you can solve it
Walter Roberson
2019년 3월 25일
You have not replied to my repeated questions about the shape of the input. You have not posted any error messages. You have not indicated how you know that this is not a correct solution.
Priyamvada Shankar
2019년 3월 25일
function output = echo_gen(x,fs,delay,gain)
d= delay*fs;
y=zeros(size(x));
y(1:d)=x(1:d);
for i=d+1:length(x)
y(i)=x(i)+gain*x(i-d);
end
for j = 1:length(y)
if max(y)>1
y(j) = y(j)/max(y);
end
output=y;
end
can you please check this code...this is the error showing here
Variable output must be of size [5 1]. It is currently of size [4 1]. Check where the variable is assigned a value.
Tested with the vector [-0.5; 0; 0.5; 0] and the following parameters: fs = 1, delay: 1.0 seconds, amp = 0.5
Assessment result: incorrectUsing splat sound file
If you get an error stating that your output vector is the wrong size, and the size differs by 1 from the expected value, you're probably very close. Check
That you are rounding to the nearest number of points required to create the delay
The echo signal begins after the delay has completed
paul mary
2019년 3월 25일
I suggest you read carefully the hints of our tutor in the discussion forum. which part use round(). test with
v = (1:9)'/10;
Fs = 2;
delay = 0.5
amp = 0.5;
out = echo_gen(v, Fs, delay, amp)
out =
0.0769
0.1923
0.3077
0.4231
0.5385
0.6538
0.7692
0.8846
1.0000
0.3462
Walter Roberson
2019년 3월 25일
Reminder: I am almost always helping multiple people simultaneously -- when, that is, I am not off to cook or eat, or doing housework, or shopping for food, or doing household repairs, or out for medical appointments, or keeping up with the news, or taking a bit of time to myself to watch Netflix, or ...
Priyamvada Shankar
2019년 3월 26일
I'm sorry @Walter ,i'm bothering a lot....but i worked for a whole day and my brain really gave up...so it's a request, please please help me because i don't think this code gonna work....for me it's kind of frustating now
function output = echo_gen(x,fs,delay,gain)
d= round(delay*fs);
y=zeros(size(x+1));
y(1:d)=x(1:d);
for i=d+1:length(x)
y(i)=x(i)+gain*x(i-d);
end
for j = 1:length(y)
if max(y)>1
y(j) = y(j)/max(y);
end
output=y;
output=normalize(output,'range',[-1 1]);
end
this is the ASSESSMENT i got
Variable output has an incorrect value.
Tested with the vector [-0.5; 0; 0.5; 0] and the following parameters: fs = 1, delay: 0.0 seconds, amp = 0.5
Assessment result: incorrectUsing splat sound file
Variable output must be of size [10820 1]. It is currently of size [10001 1]. Check where the variable is assigned a value.
Tested with the splat file and the following parameters: fs = 8192, delay: 0.1 seconds, amp = 0.0
Walter Roberson
2019년 3월 26일
They want you to generate the output for (original length + delay) samples. After the original length you can treat the input as 0.
You ignored what I told you about normalization.
Walter Roberson
2019년 3월 26일
Reminder: "Walter Roberson" is a solo operation, not a multi-person company. I assist multiple people as best I can until I burn out for the night, and then I read or play computer games, and then I sleep. If you need priority service from me, then you can get your university to hire me to assist you; my rates for 24 hour service contracts start at only $US30000 per day.
Walter Roberson
2019년 3월 26일
I explained normalization at https://www.mathworks.com/matlabcentral/answers/451977-add-echo-to-audio-signal-in-matlab#comment_685188
Walter Roberson
2019년 4월 3일
Hint:
A = zeros(1,15)
A(1:10) = sqrt(1:10)
B = zeros(1,15)
B(5+(1:10)) = sqrt(1:10)
Priyamvada Shankar
2019년 4월 3일
function output = echo_gen(in,fs,delay,gain)
samples = round(fs*delay) ;
ds = floor(samples);
signal = zeros(length(in)+ds,1);
signal(1:length(in))=in;
echo_signal =zeros(length(in)+ds,1);
echo_signal(1+(1:length(in*gain)))=in;
output= signal + echo_signal;
p= max(abs(output));
if p>1
output=output ./ p;
else
output = output;
end
end
A few simple cases
Assessment result: incorrectUsing splat sound file
Variable output has an incorrect value.
Tested with the splat file and the following parameters: fs = 8192, delay: 0.1 seconds, amp = 0.0
Walter Roberson
2019년 4월 3일
function output = echo_gen(in,fs,delay,gain)
samples = round(fs*delay) ;
ds = floor(samples);
signal = zeros(length(in)+ds,1);
signal(1:length(in))=in;
echo_signal =zeros(length(in)+ds,1);
echo_signal(ds+(1:length(in*gain)))=in*gain;
output= signal + echo_signal;
p= max(abs(output));
if p>1
output=output ./ p;
else
output = output;
end
end
Walter Roberson
2019년 4월 3일
We gave you lots of hints. We should not have had to give you this code, but it was getting too frustrating watching you thrash as we described what you had to do in more and more detail. I worry that you are now just going to get as badly stuck on the next assignment.
Grace Matassa
2020년 4월 11일
is it possible to play the delayed sound outloud using the sound function?
if yes would it be sound(output) be the command?
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
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 Center 및 File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)