Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Implementing Gabor transform

278 views
Skip to first unread message

Andreas Weishaupt

unread,
Oct 18, 2008, 1:07:08 PM10/18/08
to
Hi everybody!

I'm trying to implement the Gabor transform (exercise, I know there are
MATLAB built-in functions or the like that would do the transform), but
what I've written produces an output that is far from what it should be.

I've tried by using convolution (no Short-Fourier-Transform allowed):

% -------------------------- Code -------------------------------------
% omega is a vector of discrete frequencies
% signal is the signal to be analyzed/be Gabor transformed
function [] = timeFreq (signal, sigma, omega)
% calculate the transform and plot it
close all;
gabor = gaborTransformation (signal, sigma, omega);
image (abs (gabor));

% transformation method (nested)
function G = gaborTransformation (signal, sigma, omega)
G = zeros (length(omega), length(signal));
tau = linspace (-pi, pi, length(signal));
% one transformation per frequency
for i=1:length(omega)
gaussian = 1/(2*sqrt(pi*sigma)) .* exp (-tau.^2/(4*omega(i)));
gaborFilter = gaussian .* exp (j*omega(i).*tau);
% I think the fftshift is needed because tau from -pi to pi
GPart = conv (signal, fftshift(gaborFilter));
% cutting the too long vector:
GPart = GPart(1:length(signal));
% inserting it as a line in the resulting
% Gabor transform matrix
G(i,:) = exp (-j*omega(i).*tau) .* GPart;
end
end
end
% ---------------------- End Code -------------------------------------

When I test it using following signal:

t = linspace (0, 20, 200);
signal = cos(t);
omega = linspace (-10, 10, 200);
sigma = 1;
timeTreq (signal, sigma, omega);

The output is crap, just a bizarrely coloured image. Does anyone has an
idea where I'm wrong?

Thank you for your help

Andreas

Rune Allnor

unread,
Oct 18, 2008, 5:38:09 PM10/18/08
to

It seems you are messing up time domain and frequency domain.
You use exp(jw) as you would if you work in frequency domain,
but apply a temporal convolution.

So do *one* of the following:
- Convolve the signal with each of the filters.
You do this with the 'conv' or 'filter' finctions,
but you should never see the complex exponentials
anywhere.
- FFT the signal and the filters, multiply in
frequency domain, IFFT back to time domain.
Here there are complex exponentials all over
the place, but no convolutions.

Rune

Andreas Weishaupt

unread,
Oct 19, 2008, 1:08:06 PM10/19/08
to
Hi Rune!

Rune Allnor wrote:
> It seems you are messing up time domain and frequency domain.
> You use exp(jw) as you would if you work in frequency domain,
> but apply a temporal convolution.
>
> So do *one* of the following:
> - Convolve the signal with each of the filters.
> You do this with the 'conv' or 'filter' finctions,
> but you should never see the complex exponentials
> anywhere.
> - FFT the signal and the filters, multiply in
> frequency domain, IFFT back to time domain.
> Here there are complex exponentials all over
> the place, but no convolutions.


Thanks for your help. I've tried by doing each of your propositions, it
doesn't produce a correct output. It looks that I'm messing up time and
frequency domain. But shouldn't this be the case for a time-frequency
analysis, since I want to display the instantaneous frequencies of the
input signal as a function of time? E.g. for a linear "chirp", cos(t.^2)
, I should obtain a linear function in the time-frequency graph, since
the instantaneous frequency is given by 2t.

Theory of Gabor transform says, that I can calculate it by

Gf(b,w) = int { f(x) * g(x-b) * exp (-jw(x-b)) dx }
(multiplication, no convolution, g is the gaussian window)

This can be rewritten as a convolution of f and (g * exp). Or in other
words, for the time-frequency analysis, we obtain each time-frequency
"cell" of the time-frequency graph with shifts in time (i.e. x-b) or
shifts in frequency (omega - w), that's why the exponential term in the
filter.

But somewhere I'm wrong...

Rune Allnor

unread,
Oct 19, 2008, 2:35:00 PM10/19/08
to
On 19 Okt, 19:08, Andreas Weishaupt <andreas.weisha...@epfl.ch> wrote:
> Hi Rune!
>
> Rune Allnor wrote:
> > It seems you are messing up time domain and frequency domain.
> > You use exp(jw) as you would if you work in frequency domain,
> > but apply a temporal convolution.
>
> > So do *one* of the following:
> > - Convolve the signal with each of the filters.
> >   You do this with the 'conv' or 'filter' finctions,
> >   but you should never see the complex exponentials
> >   anywhere.
> > - FFT the signal and the filters, multiply in
> >   frequency domain, IFFT back to time domain.
> >   Here there are complex exponentials all over
> >   the place, but no convolutions.
>
> Thanks for your help. I've tried by doing each of your propositions, it
> doesn't produce a correct output. It looks that I'm messing up time and
> frequency domain. But shouldn't this be the case for a time-frequency
> analysis, since I want to display the instantaneous frequencies of the
> input signal as a function of time? E.g. for a linear "chirp", cos(t.^2)
> , I should obtain a linear function in the time-frequency graph, since
> the instantaneous frequency is given by 2t.

One would think so, but you work with sampled data, which only
behave intuitively with fairly mild modulations. Using the form
cos(t^2) is like using a sledgehammer to adjust the clockwork
in a wristwatch.

Try some different numbers:

x[n] = cos(2*pi*n*T*f(t))

where f(t) = f0 + a*df*t, T is the sampling f0 ~ 0.1/T and a*df ~ 0.1/
T.

> Theory of Gabor transform says, that I can calculate it by
>
> Gf(b,w) = int { f(x) * g(x-b) * exp (-jw(x-b)) dx }
> (multiplication, no convolution, g is the gaussian window)
>
> This can be rewritten as a convolution of f and (g * exp). Or in other
> words, for the time-frequency analysis, we obtain each time-frequency
> "cell" of the time-frequency graph with shifts in time (i.e. x-b) or
> shifts in frequency (omega - w), that's why the exponential term in the
> filter.

First, it seems you are not aware of the differences between
continuous-time functions and discrete-time data. Matlab only
works with numerical data, and the results will be different
from the analytical expressions one uses for continuous-time
analysis.

Apart from that, try and work the formulation above into a
framework where it is implemented as *either* a time-domain
convolution *or* a frequency-domain multiplication. It doesn't
matter what the theory says, if you want to implement it you
need to choose one of those approaches.

In fact, it might be that it is the formulation of the theory
which confuses you. I've played with the Gabor filter in the
past, without any difficulties. Note that I use the term
Gabor *filter*, not Gabor *transform*. When viewed as a
regular filter bank the implementation is trivial.

Rune

0 new messages