function [result] = blended_spectrum_bf(s,t,p)
%BLENDED_SPECTRUM_BF
%        -Finds the contiguous subsequence match count between strings s and t
%         by using a brute-force approach, for all substrings of length <= p.
%        -This program does not take into account gap penalties.
%         *(There is also a dynamic programming implementation of this algorithm.
%           Type help blended_spectrum for info.)
%
%         K[p](s,t) = [Summation of h from 1 to p]
%                     [Summation of i from 1 to |s|-p+1]
%                     [Summation of j from 1 to |t|-p+1]
%                         delta(s(i:i+p+1),t(j:j+p+1)),
%
%            (where delta is the identity function, which returns
%             1 if the arguments are equal, and 0 otherwise.)
%
%        -Example: blended_spectrum_bf('abccc','abc', 2) returns a value of 7.
%            (Note that blended_spectrum_bf('abccc','abc',2)=blended_spectrum_bf('abc','abccc',2) since K(s,t,p) = K(t,s,p) ).
%        -Example: blended_spectrum_bf('a','a', 1) returns a value of 1.
%        -Example: blended_spectrum_bf('a','a', 2) returns a value of 4.
%        -Example: blended_spectrum_bf('a','b', 1) returns a value of 0.
%        -Example: blended_spectrum_bf('ab','ab', 1) returns a value of 2.
%         
%
%
%USAGE:   scalar = blended_spectrum_bf('string1','string2', p);    
%                     (where p is the length of the substring )
%
%         [scalar, matrix] = p_spectrum('string1,'string2', p);
%
%

%For more information, visit http://www.kernel-methods.net

%Written and tested in Matlab 6.0, Release 12.
%Copyright 2003, Manju M. Pai 4/2003
%manju@kernel-methods.net
%------------------------------------------------------------------------------------------

%Obtain lengths of strings
[num_rows_s, n] = size(s);
[num_rows_t, m] = size(t);

%Initialize result variable
result = 0;

%Error checking statements:
  %Make sure input vectors are horizontal.
  if (num_rows_s ~= 1 | num_rows_t ~= 1)  
     error('Error: s and t must be horizontal vectors.');
  end;
  
  %If p is less than zero or not a number, program should quit due to faulty variable input.
  if p <= 0 | ischar(p)
      error('Error: p needs to be a number greater than 0.');
  end;
%End of error checking

%Implement the algorithm with double 'for' loops.
for h=1:p
  for i=1:(n-h+1)
      for j=1:(m-h+1)      
          result = result + strcmpi( s(i:(i+h-1)), t(j:(j+h-1)) );
      end;
  end;
end;

%End of algorithm
