Convert Matlab code to Simulink Model

8 ビュー (過去 30 日間)
Alex Harbach
Alex Harbach 2017 年 5 月 4 日
編集済み: KL 2017 年 5 月 5 日
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

回答 (1 件)

KL
KL 2017 年 5 月 5 日
編集済み: KL 2017 年 5 月 5 日
You need to write it into a function and then use it inside the matlab functions block of simulink library.

カテゴリ

Help Center および File ExchangeSources についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by