You need to write it into a function and then use it inside the matlab functions block of simulink library.
Convert Matlab code to Simulink Model
8 次查看(过去 30 天)
显示 更早的评论
Hello,
I have just recently finished writing a script for a LMS filter to filter out white noise from an audio file. I would like to know if there is a way for me to convert this script into a Simulink model so I can see how the filter works in real-time. Here is the code:
signal = yes, fs;
noise = white_noise, fs1;
% Define Adaptive Filter Parameters
filterLength = 32;
weights = zeros(1,filterLength);
step_size = 0.004;
% Initialize Filter's Operational inputs
output = zeros(1,length(signal));
err = zeros(1,length(signal));
input = zeros(1,filterLength);
% For Loop to run through the data and filter out noise
for n = 1: length(signal)
%Get input vector to filter
for k= 1:filterLength
if ((n-k)>0)
input(k) = noise(n-k+1);
end
end
output(n) = weights * input'; %Output of Adaptive Filter
err(n) = signal(n) - output(n); %Error Computation
weights = weights + step_size * err(n) * input; %Weights Updating
end
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!