Filter löschen
Filter löschen

Need help with generating an echo for an Audio signal

2 Ansichten (letzte 30 Tage)
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah am 7 Mai 2022
Kommentiert: Voss am 12 Mai 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 Kommentar
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah am 7 Mai 2022
Also io there a way to ouput both functions together using "Sound" Command?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 7 Mai 2022
Bearbeitet: Voss am 7 Mai 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 Kommentare
Abdelrhman Abdelfatah
Abdelrhman Abdelfatah am 12 Mai 2022
Thank you so much, this is exactly what i did, and it's working fine now, and even did the infinite cancellation too!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jonas
Jonas am 7 Mai 2022
Bearbeitet: Jonas am 7 Mai 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 Kommentare
Jonas
Jonas am 7 Mai 2022
Bearbeitet: Jonas am 7 Mai 2022
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 am 10 Mai 2022
Thank you so much for taking the time to explain!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Signal Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by