JQuery XHR Memory Leak Workaro...

Matlab Waveform Deconvolution

3D Printer Unboxing: Wanhao Du...

Flashing Nordic NRF51 With J-L...

Electric Standing Desk

Hardware Controlled LED Lamp

Ultrasonic Digital Signals Pro...

Bluetooth Low Energy Garage Op...

Mini Cast-Iron Deep Dish Pizza

Homebrewed Columbus IPA

Mini Gingerbread Houses

Iced Brownies
Matlab Waveform Deconvolution
This Matlab script takes a real world waveform response containing two overlapping impulses and removes one of them to generate a clean reference waveform via frequency domain deconvolution


This is the real world waveform responses


These are the expected impulse positions that will be used for the deconvolution


This is the two previous images as well as the resultant reference waveform (in blue).



realworldReference = [18 11 7 3 -1 -4 -4 -2 0 1 0 -4 -11 -20 -30 -36 -34 -25 -10 ...
                      3 10 9 0 -10 -18 -22 -20 -15 -10 -4 1 6 10 10 3 -7 -14 -10 ...
                      6 26 36 27 3 -21 -30 -20 -1 10 3 -19 -42 -51 -39 -14 10 21 ...
                      16 3 -6 -3 12 30 41 39 26 6 -19 -43 -59 -59 -41 -9 22 40 43 ...
                      38 36 42 47 45 32 18 12 20 33 42 39 29 17 7 -5 -21 -40 -57 ...
                      -76 -111 -174 -257 -340 -410 -505 -701 -1053 -1499 -1814 -1664 ...
                      -773 889 2992 4903 5903 5499 3681 996 -1632 -3304 -3575 -2675 ...
                      -1372 -525 -595 -1405 -2309 -2635 -2105 -963 235 994 1152 898 ...
                      580 463 598 849 1027 1013 813 525 261 90 14 -11 -34 -81 -147 ...
                      -210 -248 -251 -223 -175 -119 -66 -27 -5 -1 -6 -10 -3 17 45 ...
                      68 73 55 18 -24 -56 -69 -63 -43 -21 -5 2 1 0 6 23 47 67 75 ...
                      66 44 19 4 5 23 51 71 69 32 -37 -124 -201 -243 -234 -176 -87 ...
                      9 91 145 169 165];
			
x = 0:length(realworldReference)-1;
t = 0:1/4:length(realworldReference)-1/4;
realworldReference = spline(x,realworldReference,t);  

ma = max(realworldReference);
mi = min(realworldReference);
if(abs(mi) > ma)
    m = abs(mi);
else
    m = ma;
end

scaleFactor = -1*32768/m;
realworldReference = realworldReference .* scaleFactor;

figure;
hold on;

legd = [];

clipResult = 1;
rollFrontToZero = 1;

sos = 7900; %guess and check until impulses line up
anticipatedEchoTime = round(1/( sos /.001) * (1E9) / 5 * 4 / 2 );

impulse = zeros(1,804);
[minval,minpos] = min(realworldReference);
impulse(minpos) = minval;

impulse( (minpos+anticipatedEchoTime) ) = realworldReference(1, (minpos+anticipatedEchoTime) );
impulse( (minpos+2*anticipatedEchoTime) ) = realworldReference(1, (minpos+2*anticipatedEchoTime) );

impulseFFT = fft(impulse);
FFTrealworldReference = fft(realworldReference);

deconv = FFTrealworldReference ./ impulseFFT;

result = ifft(deconv);

len = length(result);
len2 = length(result)/2;
result = [ result(len2:len) result(1:len2-1) ];

result = result .* -32767;

if(clipResult)

    outgoingResult = [];
    samples = length(result);
    leftPos = 345;

    lastVal = 0;
    targetPosition = leftPos + 100;
    force = 0;
    for j=leftPos:samples*4-1
        outgoingResult(j-leftPos+1) = round(result(j+1));

        if  (j >= targetPosition)
            if( lastVal > 0 && result(j+1) <= 0 || force )
                break
            end
            if( lastVal < 0 && result(j+1) >= 0 || force)
                break
            end
        end

        lastVal = result(j+1);
    end

    if(rollFrontToZero)

        offset = outgoingResult(1);
        prevVal = offset;
        j = 2;
        while outgoingResult(j)-prevVal > 0
            prevVal = outgoingResult(j);
            j = j+1;
        end

        disp(outgoingResult(j-1));
        disp(j);
        inc = ( outgoingResult(j-1) /  (j/2*(j)) );
        increment = 0;

        outgoingResult(1) = 0;
        for k=0:j-1
            disp(increment);
            increment = increment + k*inc;
            outgoingResult(k+1) = increment;
        end

        outgoingResult = round(outgoingResult);

    end

        plot(outgoingResult);

else

    plot(result);

end



plot(impulse);
plot(realworldReference);

hold off;