i have a erorr with echo when i use soundsc command

1 visualización (últimos 30 días)
Mohammed Alqahtany
Mohammed Alqahtany el 25 de Nov. de 2023
Respondida: Walter Roberson el 25 de Nov. de 2023
% Step 1: Load the audio file echo.mat
load('echo.mat');
% Step 2: Run the audio file using soundsc function
fs = 22050; % Sampling frequency
soundsc(echo, fs);
% Step 3: Plot the audio file
t = (0:length(echo)-1) / fs;
figure;
plot(t, echo);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Audio File');
% Step 4: Generate impulse response
impulse_response = zeros(size(echo));
impulse_response(1) = 1;
impulse_response(round(3/4 * length(impulse_response))) = 0.25;
% Step 5: Convolve the audio signal with the impulse response
convolved_signal = conv(echo, impulse_response);
% Step 6: Plot the signals
figure;
subplot(3, 1, 1);
plot(t, echo);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Audio File');
subplot(3, 1, 2);
plot(t, impulse_response);
xlabel('Time (s)');
ylabel('Amplitude');
title('Impulse Response');
subplot(3, 1, 3);
convolved_t = (0:length(convolved_signal)-1) / fs;
plot(convolved_t, convolved_signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Convolved Signal');
% Step 7: Play the convolved signal
soundsc(convolved_signal, fs);
  1 comentario
Mohammed Alqahtany
Mohammed Alqahtany el 25 de Nov. de 2023
this (Error using echo
Too many output arguments.) come out when i evaluate soundsc

Iniciar sesión para comentar.

Respuestas (2)

Stephen23
Stephen23 el 25 de Nov. de 2023
Editada: Stephen23 el 25 de Nov. de 2023
MATLAB has a function named ECHO, which has no output arguments:
This is what your script is calling.
You think that you are accessing a variable named ECHO, but that is not what is happening (in fact MATLAB's code parser finds your reference to ECHO, looks to see if you have defined a variable with that name, cannot find one... and so searches for functions with that name. And it finds the function ECHO). This is explained here:
There are several ways to resolve this, the best approach is to call LOAD with an output argument:
S = load(..)
and then access the fields of S, e.g. if there really is a field named ECHO:
S.echo
  2 comentarios
Mohammed Alqahtany
Mohammed Alqahtany el 25 de Nov. de 2023
Sorry, but I don't understand what you mean
Stephen23
Stephen23 el 25 de Nov. de 2023
"but I don't understand what you mean"
Okay, here is another solution (without any explanation). Replace this:
load('echo.mat');
with this:
load('echo.mat','echo');
Try it.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 25 de Nov. de 2023
% Step 1: Load the audio file echo.mat
filename = 'echo.mat';
datastruct = load(filename);
if ~isfield(datastruct, 'echo')
error('file "%s" does not contain variable named echo', filename);
end
echo = datastruct.echo;

Categorías

Más información sobre Audio Processing Algorithm Design en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by