フィルターのクリア

i have a erorr with echo when i use soundsc command

1 回表示 (過去 30 日間)
Mohammed Alqahtany
Mohammed Alqahtany 2023 年 11 月 25 日
回答済み: Walter Roberson 2023 年 11 月 25 日
% 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 件のコメント
Mohammed Alqahtany
Mohammed Alqahtany 2023 年 11 月 25 日
this (Error using echo
Too many output arguments.) come out when i evaluate soundsc

サインインしてコメントする。

回答 (2 件)

Stephen23
Stephen23 2023 年 11 月 25 日
編集済み: Stephen23 2023 年 11 月 25 日
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 件のコメント
Mohammed Alqahtany
Mohammed Alqahtany 2023 年 11 月 25 日
Sorry, but I don't understand what you mean
Stephen23
Stephen23 2023 年 11 月 25 日
"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.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2023 年 11 月 25 日
% 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;

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by