Error showing up then using (:)'
古いコメントを表示
I am a begginer at Matlab. I'm making a feedforward comb filter. It says there is an error on this line:
inputSignal = inputSignal(:)';
inputSignal is supposed to be an audio file. This should be alright syntax wise, so I don't know where exactly is the problem. I also tried using just (:) and ', but it still says there is an error. If anyone could help me, it would mean a lot.
Here is the whole code:
% Shroeder-ov reverberator
% Feedforward comb filtar
function outputSignal = FFCF (inputSignal, delayLength, feedbackGain)
inputSignal = inputSignal(:)';
delayLine = zeros(1, delayLength);
outputSignal = zeros(size(inputSignal));
for n = 1:length(inputSignal)
combOutput = delayLine(end);
delayLine = circshift(delayLine, [0, 1]);
delayLine(1) = inputSignal(n) + feedbackGain * combOutput;
outputSignal(n) = combOutput;
end
outputSignal = outputSignal / max(abs(outputSignal));
end
% All pass filtar
function outputSignal = APF (inputSignal, delayLength, feedbackGain)
inputSignal = inputSignal(:)';
delayLine = zeros(1, delayLength);
outputSignal = zeros(size(inputSignal));
for n = 1:length(inputSignal)
allPassOutput = inputSignal(n) - feedbackGain * delayLine(end);
delayLine = circshift(delayLine, [0, 1]);
delayLine(1) = allPassOutput;
outputSignal(n) = allPassOutput;
end
end
function main
% Citamo audio fajl
audioFileRead = "sample.wav";
[input, Fs] = audioread(audioFileRead);
% Redna veza all pass filtra
allPass1 = APF (input, 1051, 0.7);
allPass2 = APF (allPass1, 337, 0.7);
allPass3 = APF (allPass2, 113, 0.7);
% 4 feed forward comb filtra
feedForward1 = FFCF (allPass3, 4799, 0.742);
feedForward2 = FFCF (allPass3, 4999, 0.733);
feedForward3 = FFCF (allPass3, 5399, 0.714);
feedForward4 = FFCF (allPass3, 5801, 0.697);
% Suma filtara
output = feedForward1 + feedForward2 + feedForward3 + feedForward4;
sound(output)
end
7 件のコメント
Walter Roberson
2023 年 9 月 16 日
When you pressed the green Run button to execute the code, what was your expectation about where it would search to find values for inputSignal?
Nikola
2023 年 9 月 16 日
Nikola
2023 年 9 月 16 日
編集済み: Walter Roberson
2023 年 9 月 16 日
When Stephen asks about "that function", he means where is main() being called? The answer is that it's not.
The error is on line 6. Walter seems to correctly intuited that this file is being executed as a script by hitting the play button. The contents of the first function in the file are executed without any of its input arguments being defined. This immediately results in an error.
In order to make a function do something, you need to call it with the appropriate arguments. The given block of code contains no lines which are not functions, so nothing normally would happen, because nothing calls any of the functions.
If you want to treat the file as a script with functions, call main() somewhere before the first function declaration. Alternatively, move the contents of main() so that they are outside of a function and so that they precede the first function declaration in the script.
Nikola
2023 年 9 月 16 日
DGM
2023 年 9 月 16 日
Excellent. Glad to hear it.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Get Started with Signal Processing Toolbox についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!