lms_flp32.m

来自「基于TS201 Floating Point LMS Filter」· M 代码 · 共 91 行

M
91
字号
%this file takes the content of input.dat, desired.dat files and computes
%the LMS filter. The file output_m.dat must be identical with the file
%outdata.dat .

format long
clear all

T=16;
epsilon=0.3;

fid = fopen('test1\input.dat', 'r');
      [input, count] = fscanf (fid, '%e');
fclose(fid);

[N, x] = size(input); %N=the size of input buffer


fid = fopen('test1\desired.dat', 'r');
      [des, count] = fscanf (fid, '%e');
fclose(fid);

for i=1:T
    xs(i)= 0;
    e(i)=0;
    c(i)=0;
end;

for i=1:N-1
    xs(1)=input(i);
    output=0;
    for j=1:T
        output=output+c(j)*xs(j);
    end
    y(i)=output;
    e(i)=des(i)-y(i);

%c(1) corresponds to h(0) from the assembly program
    for j=1:T
        c(j)=c(j)+epsilon*e(i)*xs(j);
    end;

    for j=T:-1:2
        xs(j)=xs(j-1);
    end;
end;

i=N;
    xs(1)=input(i);
    output=0;
    for j=1:T
        output=output+c(j)*xs(j);
    end
    y(i)=output;
    e(i)=des(i)-y(i);



fin = fopen('test1\output_matlab.dat', 'wt');
for i=1:N
    fprintf(fin, '%f\n', y(i));
end;
fclose(fin);

fin = fopen('test1\coeff_matlab.dat', 'wt');

    fprintf(fin, '%f\n', c(16));
    fprintf(fin, '%f\n', c(12));
    fprintf(fin, '%f\n', c(8));
    fprintf(fin, '%f\n', c(4));
    fprintf(fin, '%f\n', c(15));
    fprintf(fin, '%f\n', c(11));
    fprintf(fin, '%f\n', c(7));
    fprintf(fin, '%f\n', c(3));
    fprintf(fin, '%f\n', c(14));
    fprintf(fin, '%f\n', c(10));
    fprintf(fin, '%f\n', c(6));
    fprintf(fin, '%f\n', c(2));
    fprintf(fin, '%f\n', c(13));
    fprintf(fin, '%f\n', c(9));
    fprintf(fin, '%f\n', c(5));
    fprintf(fin, '%f\n', c(1));

fclose(fin);

%fin = fopen('test1\error_matlab.dat', 'wt');
%for i=1:N
%    fprintf(fin, '%f\n', e(i));
%end;
%fclose(fin);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?