i have a erorr with echo when i use soundsc command
조회 수: 1 (최근 30일)
이전 댓글 표시
% 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);
답변 (2개)
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
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
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;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!