Need help with generating an echo for an Audio signal

조회 수: 6 (최근 30일)
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022년 5월 7일
댓글: Voss 2022년 5월 12일
Hello, I want to generate an echo for an audio signal, then output both signals (the orginal, and the delayed( and attenuated) version).
Here is my code
%Reading the main audio
......
%Definding time
N = length(y);
t = (0:N-1)/Fs;
%Definding the echo
delay = 10000
Z = zeros(delay,1);
Ynew = [Z;y(1:end-delay)];
%Plotting both functions
subplot(2,1,1);
plot(t,y);
subplot(2,1,2);
plot(t,0.1*Ynew);
Now my problem that when i run the code, the echo functino stops at the same instance as the orginal one, but what i want is i want the domain of the echo signal to be more than the original one by the delay value. ( I want the Echo function to contiune after 3).
  댓글 수: 1
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022년 5월 7일
Also io there a way to ouput both functions together using "Sound" Command?

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 5월 7일
편집: Voss 2022년 5월 7일
Avoid cutting off the echo, i.e., use y instead of y(1:end-delay)
%Definding the echo
delay = 10000
Z = zeros(delay,1);
% Ynew = [Z;y(1:end-delay)];
Ynew = [Z; y];
And, to combine them (so you play them together at once or do anything else), you can add them together, but they need to be the same length, so append zeros to the end of original signal first:
y_combined = [y; Z] + 0.1*Ynew; % with attenuated Ynew (probably define Ynew to be attenuated in the first place instead)
For clarity, here's a complete piece of code doing those things with a random signal:
% some random signal y
y = 0.002*randn(100000,1).*exp(1.5*mod(-(1:100000).'/20000,1)).*repelem(randi(10,5,1),20000,1);
Fs = 50000;
%Defining time
N = length(y);
t = (0:N-1)/Fs;
%Defining the echo
delay = 10000;
Z = zeros(delay,1);
% Ynew = [Z;y(1:end-delay)];
Ynew = [Z; 0.1*y]; % with attenuation built-in
% combining original and echo
y_combined = [y; Z] + Ynew;
% new time vector, for the new signal length:
t_new = (0:numel(Ynew)-1)/Fs;
%Plotting all signals
subplot(3,1,1);
plot(t,y);
xlim(t_new([1 end]))
ylabel('Original')
subplot(3,1,2);
plot(t_new,Ynew);
xlim(t_new([1 end]))
ylabel('Delayed')
subplot(3,1,3);
plot(t_new,y_combined);
xlim(t_new([1 end]))
ylabel('Combined')
xlabel('Time')
  댓글 수: 6
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022년 5월 12일
Thank you so much, this is exactly what i did, and it's working fine now, and even did the infinite cancellation too!
Voss
Voss 2022년 5월 12일
Excellent!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jonas
Jonas 2022년 5월 7일
편집: Jonas 2022년 5월 7일
just append zeros to the original signal, prepend the same amount to a copy of your original to generate the echo and add them up then
[originalSig; delay]+myAttenuation*[delay; originalSig]
you can add the signals up like above to hear the combined version or you concatenate both arrays horizontally to hear the original on one ear and the delayed signal on the other.
  댓글 수: 3
Jonas
Jonas 2022년 5월 7일
편집: Jonas 2022년 5월 7일
ok you have your original signal y, which you want to overlay with an echo of itself. to prepare the echo addition, append the wanted zeros matrix called delay
preparedOriginal=[y;delay];
the echo has a specific delay, and attenuation and we add the delay before
attenuation=0.2;
echo=attenuation*[delay;y];
to hear the combined version use
sound(preparedOriginal+echo,fs)
with fs being the sampling frequency of your original signal
to hear the original on the left ear and the echo on the right, use
sound([preparedOriginal, echo],fs)
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah 2022년 5월 10일
Thank you so much for taking the time to explain!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by