Need help with generating an echo for an Audio signal

1 view (last 30 days)
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah on 7 May 2022
Commented: Voss on 12 May 2022
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 Comment
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah on 7 May 2022
Also io there a way to ouput both functions together using "Sound" Command?

Sign in to comment.

Accepted Answer

Voss
Voss on 7 May 2022
Edited: Voss on 7 May 2022
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 Comments

Sign in to comment.

More Answers (1)

Jonas
Jonas on 7 May 2022
Edited: Jonas on 7 May 2022
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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by