You are on page 1of 2

function y = chisqDCT(B, ProbOfZero); % The value y returned is the value p = 1 - stuff as given on Slide 29, % Lecture 13, of spring

2007. This value of p is large when a message is % present, and small when a message is not present. % The variable B that is input to the function is a column vector that % represents a fixed percent of the total vectorized quantized DCT % coefficients. The coefficients skipped when creating the vector B are: % coefficients with value of zero % coefficients with value of one % DC coefficients % The coefficients are visited in a zig-zag manner in an 8 x 8 block, % as described in class (how they were embedded), and the blocks are % visited in a raster scan method. %default probability of zero in a message bit defaultProbOfZero = .5; if nargin < 1 error('Insufficient arguments'); elseif nargin < 2 ProbOfZero = defaultProbOfZero; end if (ProbOfZero >1 || ProbOfZero <0) error('Incorrect probability given for a 0-bit. and 1.'); end

Must be between 0

%make sure B is double valued!!! this is very important! B= double(B); %everything will be easiest if we make sure everything is positive! % so we don't change the embedded bit value, always choose an even number % to add/subtract things by minVal = min(B)-mod(min(B),2); B=B-minVal; %so now we can assume things go from 0...n, where n is odd maxVal = max(B)-mod(max(B),2)+1; numVal = maxVal+1; counts = zeros(numVal,1); for h=1:length(B) counts((B(h,1)+1),1)=counts(B(h,1)+1,1)+1; end %creates a matrix. First column is actual even values (times -1). Second %column is average of PoV. hist = zeros(numVal/2, 2); for n = 1:(numVal/2) hist(n, 1) = -1*counts(2*n); %actual even values

%note, this line is probably what needs to be changed for question 4 %hist(n, 2) = (counts(2*n) + counts(2*n -1))/2; %estimated values %now, find the expected value of the odd number(s) in each bin hist(n,2) = (counts(2*n) + counts(2*n -1))*(1-ProbOfZero); end %combining bins. First combines a bin with its neighbor to its right until %a bin of atleast 5 is encountered. Then combines a bin with its neighbor %to its left. nbins = numVal/2; k = nbins; m=1; while (hist(m, 2)) < 5 hist(m+1,:) = hist(m, :)+hist(m+1, :); hist(m,:) = [1 -1]; m= m+1; k=k-1; end for l = (nbins-k+1): nbins if hist(l,2) < 5 hist(l,:) = hist(l,:) + hist(l-1,:); hist(l-1,:) = [1 -1]; k=k-1; end end sum = 0; for q = 1:nbins sum = sum + ((hist(q,1) + hist(q,2))^2)/hist(q,2); end y = 1 - (chi2cdf(sum,k-1));

You might also like