# How to Calculate the Ambiguity Function

(Maybe this should be on Stackoverflow instead ...)

What is the best way to calculate the ambiguity function? There are different implementations out there for Python (like PyTFTB or from TooringAnalytics) and Matlab but there are many difficulties:

## 1. Python - PyTFTB

I am not sure whether the implementation of pytftb is what I am looking for because the plots for 200 Samples of my data always look similar. Here are two examples:

I'd expect more distinct plots. The plots were generated like this:

from tftb.processing import ambiguity
waf, tau, theta = ambiguity.wide_band(signal)
cntr = plt.contourf(tau, theta, np.abs(waf) ** 2, cmap="Greys", antialiased=True)
// even less difference when I use np.abs(waf) ** 2
plt.imsave("filename.jpg", np.abs(waf), cmap="jet")


## 2. Python - TooringAnalytics

Unfortunately I can't make this one work. Maybe this is content for another question.

## 3. Matlab

Is not an option. I tried my best to translate this to R but couldn't make it work.

## 4. R

Unfortunately I couldn't find an implementation yet in R.

I'd really like to ask Dreamcooled how he computed his ambiguity function.

Thanks for your help

• Octave is a free mostly MATLAB compatible application. You shouldn’t rule it out. Also, your signals would look more alike if you removed the low frequency trend obvious in both plots. You may have a valid ambiguity function although I think you may be calculating an ambiguity on signal plus noise not the proper calculation of just signal. – user28715 Aug 20 '18 at 15:10
• Thanks! I forgot to mention Octave. I already used that but some functions used in that MATLAB implementation are not available in Octave. Your second point seems to be it! – ronnyworm Aug 24 '18 at 9:54
• I converted my comment to an answer. Please accept the answer if it actually answered your question because the system will categorize it as answered, otherwise it persists as an unanswered zombie. – user28715 Aug 24 '18 at 13:50
• Could you share what you know about Doppler / Radar processing? Because if you do, generating the Ambiguity function is doing Matched Filter on one direction and DFT (By FFT) on the other direction and that's it. – Royi Aug 24 '18 at 14:49
• Have a look here - dtic.mil/dtic/tr/fulltext/u2/a615308.pdf and en.wikipedia.org/wiki/Ambiguity_function. – Royi Aug 24 '18 at 21:08

## 1 Answer

Octave is a free mostly MATLAB compatible application. You shouldn’t rule it out. Also, your signals would look more alike if you removed the low frequency trend obvious in both plots. You may have a valid ambiguity function although I think you may be calculating an ambiguity on signal plus noise not the proper calculation of just signal.

There is more than one ambiguity function, this is the wide band single transmitter single receiver version. Most people think Doppler is just a frequency shift but it is actually a time dilation, although the frequency shift model is very often sufficient, particularly when looking at steady lines like molecular emission lines.

In acoustics the motion of the propagation media can also cause Doppler.

This code should be ok as long as the interpolation is accurate, which assumes that the signal has sample more than about 5 points per cycle.

 % wide band ambiguity function
clc
clear all
close all
%
tb=-1;
tend=1;
dialation=.8;
%
%signal=[zeros(1,100) randn(1,200) zeros(1,100)];
%signal=[zeros(1,100) exp(1j*2*pi*(4*[0:199]/200)) zeros(1,100)];
signal=[zeros(1,100) exp(1j*2*pi*(4*[0:199]+.01*[0:199].^2)/200) zeros(1,100)];
conj_rev_signal=conj(signal(end:-1:1));
time=linspace(tb,tend,length(signal));
delay_time=linspace(2*tb,2*tend,2*length(signal)-1);
tau=linspace(dialation,1/dialation,512);
out=zeros(length(tau),2*length(signal)-1);
for i=1:length(tau)
out(i,:)=conv(signal,interp1(time,conj_rev_signal,time*tau(i),'spline'));
end
figure(1)
imagesc(delay_time,tau,abs(out)) • Great to see more people using code to explain and solve questions. +1. – Royi Aug 26 '18 at 11:24