0
votes

Hi I am trying to measure the amount of clipped Samples in audio files with matlab. That means i want to get the number of all Samples that are at the Fullscale Value (at min and max). But it should just count them when there are at least two following samples at this Value.

My code so far:

for i = 1 :20 
    fileName = ['Elektro',num2str(i) '.wav'];
    unclipped = audioread(fileName);
    summeMax = sum(1 ==unclipped); 
    summeMin = sum(-1==unclipped);  
    summe = summeMin +summeMax;
    str=sprintf('%d ',summe);
    disp(str);
end

As you see its counting every sample and I would need a loop and if statements to detect if there are more than one sample at the fullscale Value.

I tried this it with a loop from j = 1 : length(unclipped) but it takes to long with this Method.

Anyone have suggestions how i could do this?

1

1 Answers

1
votes

As @Daniel pointed out in his answer to a previous question of yours, you can find all samples at which the maximum is reached by

maxReached = max(unclipped(:))==unclipped;

To remove all places where the maximum is reached for only one sample, you can use a morphological opening with the structuring element [1,1]:

clippedSamples = imopen(maxReached, [1 1]);

The number of clipped samples is now

sum(clippedSamples);

Of course you'll have to do the same with those samples where the minimum is reached.