Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
clipping detection

Subject: clipping detection

From: Paul

Date: 26 Nov, 2007 07:06:19

Message: 1 of 3

I have to know if my digitizer is clipping data and
therefore I just need to answer the question:

given the vector x, are N consecutive points anywhere in the
vector within epsilon of each other?
 

Epsilon will be the least count (one or a couples of bits)
of the digitizer.

This must be fast code and any help would be appreciated.

(Not homework as you can tell from my earlier post several
weeks ago).

Subject: clipping detection

From: Khalid Abdulla

Date: 25 Mar, 2010 20:05:20

Message: 2 of 3

Hi Paul,

I needed to write a similar piece of code myself (a copy is included below). It does include 'for' loops but this is so it can check for an arbitrary number 'N' of consectutive data points; and so it can check any number of data columns for clipping. It works by rotating the time trace round by N-1, N-2, N-3,... 1 time-steps and seeing if resulting columns are equal along any row.

Currently looks for exact equality (not within a tolerance); but this feature could be added. It seems to run pretty quick but not sure it suitable for you.

Cheers,

- Khalid.

function ClipDetect(sgl_in)
%ClipDetect - detect if a raw signal has been clipped

% Seek out N consecutive values in a row which are identicle
% NB sgl must be a number of column vectors arranged into a matrix

num_same = 10; % number of consecutive same points to look for

[rows,cols] = size(sgl_in);

for i = 1:cols % Run check on a single column of data at a time
    sgl = zeros(rows,num_same); % to store signal and shifted signals
    sgl(:,1) = sgl_in(:,i); % store unshifted signal in 1st coloumn of 'sgl'

    for i_same = 2:num_same
        % Shift signal by 1, 2, 3, timesteps and save as additional columns of
        % 'sgl'
        k = i_same-1;
        sgl(:,i_same) = sgl([end-k+1:end 1:end-k],1);
    end

    % detect cliping by checking if all shifted signals are equal; if they are
    % max and min will be the same along a row of 'sgl' matrix

    IsClip_ = max(sgl,[],2)==min(sgl,[],2);

    % sum all 'clips' to give number of 'clip' events as single value

    IsClip = sum(IsClip_);

    % Check if clipping has occured and output an error message
    if IsClip > 0
        h = msgbox('WARNING: There appear to be clipping events in the raw data!','Clipping','warn');
        uistack(h, 'top'); % put message box on top layer so its seen
    end

end

end

Subject: clipping detection

From: Khalid Abdulla

Date: 25 Mar, 2010 20:06:02

Message: 3 of 3

Hi Paul,

I needed to write a similar piece of code myself (a copy is included below). It does include 'for' loops but this is so it can check for an arbitrary number 'N' of consectutive data points; and so it can check any number of data columns for clipping. It works by rotating the time trace round by N-1, N-2, N-3,... 1 time-steps and seeing if resulting columns are equal along any row.

Currently looks for exact equality (not within a tolerance); but this feature could be added. It seems to run pretty quick but not sure it suitable for you.

Cheers,

- Khalid.

function ClipDetect(sgl_in)
%ClipDetect - detect if a raw signal has been clipped

% Seek out N consecutive values in a row which are identicle
% NB sgl must be a number of column vectors arranged into a matrix

num_same = 10; % number of consecutive same points to look for

[rows,cols] = size(sgl_in);

for i = 1:cols % Run check on a single column of data at a time
    sgl = zeros(rows,num_same); % to store signal and shifted signals
    sgl(:,1) = sgl_in(:,i); % store unshifted signal in 1st coloumn of 'sgl'

    for i_same = 2:num_same
        % Shift signal by 1, 2, 3, timesteps and save as additional columns of
        % 'sgl'
        k = i_same-1;
        sgl(:,i_same) = sgl([end-k+1:end 1:end-k],1);
    end

    % detect cliping by checking if all shifted signals are equal; if they are
    % max and min will be the same along a row of 'sgl' matrix

    IsClip_ = max(sgl,[],2)==min(sgl,[],2);

    % sum all 'clips' to give number of 'clip' events as single value

    IsClip = sum(IsClip_);

    % Check if clipping has occured and output an error message
    if IsClip > 0
        h = msgbox('WARNING: There appear to be clipping events in the raw data!','Clipping','warn');
        uistack(h, 'top'); % put message box on top layer so its seen
    end

end

end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us