Matlab: echo generator question

  • Context: MATLAB 
  • Thread starter Thread starter binbagsss
  • Start date Start date
  • Tags Tags
    Echo Generator Matlab
Click For Summary
SUMMARY

The discussion centers on creating an echo generator function in MATLAB that adds an echo effect to an input signal based on specified parameters: sampling rate (fs), delay, and amplification (amp). The output vector must account for the delay by extending its length and scaling the amplitude if values exceed the range of -1 to 1. The user provided a code snippet that correctly processes a specific test case but struggles with the amplitude scaling logic, particularly in the use of an arbitrary variable 'a' for checking the norm of the input vector.

PREREQUISITES
  • MATLAB programming skills
  • Understanding of signal processing concepts, particularly echo effects
  • Familiarity with vector operations in MATLAB
  • Knowledge of amplitude normalization techniques
NEXT STEPS
  • Review MATLAB's vector manipulation functions to improve the echo implementation
  • Learn about MATLAB's 'norm' function and its applications in signal processing
  • Explore techniques for amplitude scaling in audio signals
  • Investigate MATLAB's built-in functions for handling audio signals and effects
USEFUL FOR

Audio engineers, MATLAB developers, and anyone interested in implementing audio effects in MATLAB will benefit from this discussion.

binbagsss
Messages
1,291
Reaction score
12
The task is to given an input column vector (with values between -1 and 1 representing the digitized data), fs the sampling rate, delay to represent the delay of the echo in seconds, amp specifying the amplification of the echo, to add this echo to the original signal after delay seconds.

Other information given is:
  • the output vector will be longer than the input vector when the delay is nonzero- round to the nearest number of points needed to get the delay, as opposted to floor or ceil.
  • if the echo causes some values to be outside of the range -1 to 1, scale the entire vector retaining their relative amplitudes.
Below is the code I have so far. One simple test for the assignment which my code fails is the case:
input= [-0.5; 0; 0.5; 0] and the following parameters: fs = 1, delay: 0.0 seconds, amp = 0.5
For this, I thought the answer should be: [-0.25;0;0.25;0] which my code DOES yield. So I'm wondering if I've mis understood the task also tbh?
Aside from that, for the amplitude rescaling, where I've put 'if norm(input(a)) > 1', from playing around in MATLAB outside of this function in the live script, I don't think how I've wrote it, in terms of a, some arbitary variable, works? But I'm unsure how to write it without this? thanks
This is what I have wrote so far...

Matlab:
[I]function [output]=echo_gen(input,fs,delay,amp)N = length(input); % sample lenth
%time = N/fs ;% total time span of audio signaltif
%dt * d=delay

lowerlimit=floor(delay*fs);M=N+lowerlimit;

%implementingtheecho
length(((lowerlimit+1):M));
length((1:N));
input((lowerlimit+1):M)=amp*input(1:(N));

%condition to check amps and scale relative amps if over

a=[];
if norm(input(a)) > 1
    %conditiontoscale
    c=max(abs(input))
    %solve for the sf s.t c*sf=1
    sf=1/c
    input=input*sf;
else
  
    output=input;
   
end
output=input;
end[/I]
 
Last edited by a moderator:
Physics news on Phys.org
bump, much appreciated
 
anyone ? :(
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K