Need help with generating an echo for an Audio signal

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

采纳的回答

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
Thank you so much, this is exactly what i did, and it's working fine now, and even did the infinite cancellation too!

请先登录,再进行评论。

更多回答(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)

请先登录,再进行评论。

类别

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