代码之家  ›  专栏  ›  技术社区  ›  hphys

绘图的标准化

  •  2
  • hphys  · 技术社区  · 7 年前

    clf;
    %call importdata() after changing current directory
    B = importdata('sigpros.txt');
    
    d  = 1000; %vertical spacing
    Bs = B;    %copy of the original data
    
    for i = 1 : size(Bs,2)
        %loop adding constant to each column
        Bs(:,i) = Bs(:,i) + (i-1) * d;
    end    
    
    %plot the modified matrix
    plot(Bs);
    

    数据由349行和4007列组成。每列都是完整的a扫描数据(波形)。每个数据都有一个垂直间距,全套这些绘制的数据构成B扫描数据(通过传感器位移获得的波形)。我不确定上面的代码是否正确,但数据应该类似于: B-Scan data .

    这可以通过将上述矩阵图归一化为灰度0到255来实现。目前,我的情节是这样的: My plot

    更新

    这是 normalized b-scan data . 然而,其最初峰值的方式高于上图中的方式。这里可能有什么问题?

    零偏移消除

    clf;
    %call importdata() after changing current directory
    B = importdata('A_scan1.txt');
    Bd = detrend(B,0); %remove the zero offset
    
    d  = 1000; %vertical spacing
    Bs = Bd;    %copy of the original data
    
    for i = 1 : size(Bs,2)
        %loop adding constant to each column
        Bs(:,i) = Bs(:,i) + (i-1) * d;
    end    
    
    minV = min(Bs(:));
    maxV = max(Bs(:));
    Bs_scale = (Bs-minV)*255/(maxV-minV);
    
    %plot the modified matrix
    plot(Bs_scale, 'k');
    

    然而,它仍然不是从0开始。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Aero Engy    7 年前

    这将设置为偏移,使第一行的起点为零,并缩放所有数据,使最小值到最大值的范围为255个单位。

    我去掉了注释,但包含了一些行,这些行可以替代缩放数据,使其从0&开始;峰值在255。但是,由于存在一些负值,因此总范围为>255

    clf;
    %call importdata() after changing current directory
    B = importdata('sigpros.txt');
    
    %NOTE: I am only plotting the first 59 lines as the rest don't look as good
    Bd = detrend(B(:,1:59),0); %remove the zero offset
    
    d  = 1000; %vertical spacing
    Bs = Bd;    %copy of the original data
    
    %Get the initial zero offset from the first line
    initOffset = Bs(1,1);
    %% xxx Alternatively take the mean across all starting points xxx
    % initOffset = mean(Bs(1,:));
    
    for i = 1 : size(Bs,2)
        %loop adding constant to each column
        Bs(:,i) = Bs(:,i) - initOffset + (i-1) * d ; %subtract the offset from each
    end    
    
    minV = min(Bs(:));
    maxV = max(Bs(:));
    
    %This make the RANGE from min to make = 0-255 units.
    Bs_scale = (Bs)*255/(maxV-minV);
    %% xxxx If instead you want the peak to be at 255 xxxxx
    % Bs_scale = (Bs)*255/(maxV);
    
    %plot the modified matrix
    plot(Bs_scale, 'k');
    

    编辑/解释:

    Here is what B looks like Raw. . 它基本上是一系列相互重叠的线条。在你之后 detrend 然而,由于这个信号不是完全对称的,这些线并不完全从零开始。。。它们比以前更接近,但并不完美。 Here is Bd 之后 德特伦德

    下一个你的 for 循环最初将每条线间隔1000,增加了 d so it looked like this . 因为这些线不是从零开始的,这就是你想要的,我添加了初始偏移项。这些基本上取第一行的第一个点,然后从每一行中减去。从而迫使它从零开始。