readhead.m

来自「This is a collection of m-files I create」· M 代码 · 共 32 行

M
32
字号
%READHEAD(IN)
%   This function translates a NRZ signal into what a read head
%   from a magnetic disk would read.  It's values are -1, 0, and 1.
%
%   Although it is not necessary to illustrate each possibility,
%   because the array is initialized to zero, they are still
%   shown for clarity.

function out = readhead(in)

a=zeros(1,length(in));
a(1)=in(1);
for i=2:length(in)
    if in(i-1) == 0
        if in(i) == 0
            a(i) = 0;
        end
        if in(i) == 1
            a(i) = 1;
        end
    end
    if in(i-1) == 1
        if in(i) == 0
            a(i) = -1;
        end
        if in(i) == 1
            a(i) = 0;
        end
    end
end

out = a;

⌨️ 快捷键说明

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