DSPRelated.com
Forums

Cross-correlation by convolution (unexpected results)

Started by Michel Rouzic January 28, 2006
"Michel Rouzic" <Michel0528@yahoo.fr> wrote in message 
news:1138579611.652105.276500@g47g2000cwa.googlegroups.com...
>
<prune>
> I'm not sure I got what you meant... Frequency is axis Y. Just like for > any other spectrogram.
But when you convolve the original chirp with your time reversed sequence of received samples you just get one long string of real numbers which is the impulse response , one value for each time step. How can that can translate into the many values per timestep I see in your final spectrogram? In the earlier spectrograms (of the chirp and the return) I assume that your display program took your original long chirp and chopped it into a set of (possibly overlapping) shorter windows so that it could calculate the spectrum over a short interval of chirp and display as a vertical line of pixels, spectral estimate for next window goes in the next line of pixels etc. , if the chirp frequency doesn't change much during the window length then you get a fairly good peak and a nice thin straight line on the spectrogram - if it's doing the same thing with the channel impulse response I don't see how you will be able to make any sense of it at all. Best of luck - Mike
did you try to time-reverse second signal?

impaler@tut.by wrote:
> did you try to time-reverse second signal?
As you can see on the spectrogram, it's already time reversed (that's why it's in the opposite position of the first chirp)
Andreas Schwarz wrote:
> Michel Rouzic schrieb: > > Andreas Schwarz wrote: > > > >>Michel Rouzic schrieb: > >> > >>>Since an image is word ten thousand words, here's what sums up what i'm > >>>trying to do http://www.geocities.com/michel0528/correlation.jpg > >>> > >>>As you can see, I'm trying to correlate the first signal by the second > >>>by correlation. The problem is, I didn't really expect the result you > >>>can see on the picture, I expected more something looking like from not > >>>too close like a delta function right in the middle. > >> > >>Take a look at the result in the time domain, and you will see a delta > >>function. It looks that way in a spectrogram, your convolution function > >>is working correctly. > > > > > > Oh yeah damn, i'm feeling dumb for not having noticed that. My result > > is stored on floats and as you can see by the magnitude it was too big > > for me to see that. > > > > However, what do I do with my result? > > Depends on what you *want* to do. > > > The "delta function" I got isn't > > even really a delta function, but a 6400 bins chirp, surrounded by all > > the noise you can see. > > As I wrote above, forget the spectrogram, it's making things much more > complicated than they are. Take a look at your convolution result in the > time domain. I'm sure you will see a pretty sharp peak at the center. > Try to shift one of the input signals and look at the result again, you > will see the peak shifted too, etc. > > > Do I keep only the 6400 bins of interest? Do I > > convolve that one little chirp with another to make it at last > > straight? Why isn't it even straight in the first place?? Does it mean > > that the recorded chirp lasted about 0.066% longer that the original > > one for some reason? > > Sorry, I don't understand. Why don't you post a more detailed > description of what you are trying to accomplish and what you have tried > so far?
Sure. I have a linear system. I send the second signal (reversed) through this system and obtain the first signal. What I am trying to do here is to get rid of the surrounding noise in the first signal. To do so, someone told me to cross-correlate the two signals in order to get a delta function representing the frequency response of the linear system i am trying to study. However, the result is not exactly a delta function, but a 6400 bins long chirp, surely due to the fact that for some reason the first signal was 0.066% longer than the second. So that's why I think I should convolve it again with another 6400 bins long chirp to make it at last straight vertical. The next question is how to get rid of the noise. My guess is that I should only keep the highest bin and a few hundreds or thousands of surrounding bins, and maybe eventually window them, in order to get a proper impulse response of my linear system, without the noise. What do you think about that?
Mike Yarwood wrote:
> "Michel Rouzic" <Michel0528@yahoo.fr> wrote in message > news:1138579611.652105.276500@g47g2000cwa.googlegroups.com... > > > <prune> > > I'm not sure I got what you meant... Frequency is axis Y. Just like for > > any other spectrogram. > > But when you convolve the original chirp with your time reversed sequence > of received samples you just get one long string of real numbers which is > the impulse response , one value for each time step. How can that can > translate into the many values per timestep I see in your final spectrogram?
I understood something about convolving with a chirp, it just displaces each band of frequency differently. Here, it's in order to bring a chirp vertical. It actually does it, but I had yet to normalize my result signal to see that the kinda of delta function was there (actually more like a shortened chirp, due to the fact that my first chirp is 0.066% longer than my second one). The rest of what you can see is the noise of the first signal inclined according to the inclination of the second chirp
> In the earlier spectrograms (of the chirp and the return) I assume that your > display program took your original long chirp and chopped it into a set of > (possibly overlapping) shorter windows so that it could calculate the > spectrum over a short interval of chirp and display as a vertical line of > pixels, spectral estimate for next window goes in the next line of pixels > etc. , if the chirp frequency doesn't change much during the window length > then you get a fairly good peak and a nice thin straight line on the > spectrogram - if it's doing the same thing with the channel impulse response > I don't see how you will be able to make any sense of it at all.
The problem was that the final signal is so big (almost 20 million bins I think) that the spectrogram display program made the almost continuous 6400 bins long line almost disappear. But it's there.
"Michel Rouzic" <Michel0528@yahoo.fr> wrote in message 
news:1138711496.407992.178200@f14g2000cwb.googlegroups.com...
> >> <prune> > > I understood something about convolving with a chirp, it just displaces > each band of frequency differently. Here, it's in order to bring a > chirp vertical.
I'm tempted to say that I disagree completely but I still don't know what you mean by 'bring a chirp vertical' so all I can say is I strongly doubt it.
> It actually does it, but I had yet to normalize my > result signal to see that the kinda of delta function was there > (actually more like a shortened chirp, due to the fact that my first > chirp is 0.066% longer than my second one).
It's normal that your second chirp is longer than the original as it is(hopefully) just the superposition of a lot of copies of your original chirp with different relative delays and amplitudes. When you convolve these with the time reversed replica of your transmitted original chirp you should see a wiggly line representing the amplitude of all of those echoes/different delay paths, neatly separated out to within the resolution of your pulse compression scheme + more ripply stuff due to edge effects. If you are really seeing something that looks like a chirp near where you expect your echo reponse to be then I suspect that you have a lot of dispersion in your system or some substantial non-linearities or both.
>The rest of what you can > see is the noise of the first signal inclined according to the > inclination of the second chirp >
Best of Luck - Mike
"Michel Rouzic" <Michel0528@yahoo.fr> wrote in message 
news:1138502806.658790.269740@g47g2000cwa.googlegroups.com...
> Since an image is word ten thousand words, here's what sums up what i'm > trying to do http://www.geocities.com/michel0528/correlation.jpg
It looks like: - You're trying to do a bunch of 1D convolutions instead of a 2D convolution; - Your 3rd image has twice the resolution on the X axis, and you rescaled it without telling us; and - Your convolution function is broken. Image 3 looks like the image 2 convolved row-by-row with something like the background noise from image 1, and then added to image 1. Perhaps you got some buffers mixed up? -- Matt
Matt Timmermans wrote:
> "Michel Rouzic" <Michel0528@yahoo.fr> wrote in message > news:1138502806.658790.269740@g47g2000cwa.googlegroups.com... > > Since an image is word ten thousand words, here's what sums up what i'm > > trying to do http://www.geocities.com/michel0528/correlation.jpg > > It looks like: > > - You're trying to do a bunch of 1D convolutions instead of a 2D > convolution;
Only one 1D convolution
> - Your 3rd image has twice the resolution on the X axis, and you rescaled it > without telling us; and
yeah, oops
> - Your convolution function is broken. Image 3 looks like the image 2 > convolved row-by-row with something like the background noise from image 1, > and then added to image 1. Perhaps you got some buffers mixed up?
I'm convolving sounds, not images. Those are the spectrograms of these signals. My convolution function apparently works, I just didn't know how to deal with the result. Confusing thing tho is why does image 1 appear on the first part of image 3
Mike Yarwood wrote:
> "Michel Rouzic" <Michel0528@yahoo.fr> wrote in message > news:1138711496.407992.178200@f14g2000cwb.googlegroups.com... > > > >> <prune> > > > > I understood something about convolving with a chirp, it just displaces > > each band of frequency differently. Here, it's in order to bring a > > chirp vertical. > I'm tempted to say that I disagree completely but I still don't know what > you mean by 'bring a chirp vertical' so all I can say is I strongly doubt > it. > > > It actually does it, but I had yet to normalize my > > result signal to see that the kinda of delta function was there > > (actually more like a shortened chirp, due to the fact that my first > > chirp is 0.066% longer than my second one). > It's normal that your second chirp is longer than the original as it > is(hopefully) just the superposition of a lot of copies of your original > chirp with different relative delays and amplitudes. > When you convolve these with the time reversed replica of your transmitted > original chirp you should see a wiggly line representing the amplitude of > all of those echoes/different delay paths, neatly separated out to within > the resolution of your pulse compression scheme + more ripply stuff due to > edge effects. If you are really seeing something that looks like a chirp > near where you expect your echo reponse to be then I suspect that you have a > lot of dispersion in your system or some substantial non-linearities or > both.
I'm tempted to say that for some reason signal 1 was longer than signal 2, don't know what to blame tho, I thought about blaming my ADC but that would mean it plays and samples at about 44,085 Hz instead of 44,100, idk if it's possible. For you to see how my small chirp looks like, here is a zoom on it http://www.geocities.com/michel0528/chirp.jpg You can see clearly that it does look as a small chirp. The only explanation I can see is that the output signal was longer than the input signal, and that thus I should do one further convolution by a chirp to bring that small chirp vertical.

Michel Rouzic wrote:

> > I'm tempted to say that for some reason signal 1 was longer than signal > 2, don't know what to blame tho, I thought about blaming my ADC but > that would mean it plays and samples at about 44,085 Hz instead of > 44,100, idk if it's possible.
Yes, I've seen that much deviation and more between generating and sampling devices. You should play by the rule that the same clock must generate the stimulus that samples the response.
> For you to see how my small chirp looks like, here is a zoom on it > http://www.geocities.com/michel0528/chirp.jpg
I've never tried generating a chirp and an inverse slightly different in length nor doing any kind of formal analysis of what one would get but a small chirp instead of an impulse intuitively seems to be a good possibility.
> You can see clearly that it does look as a small chirp. The only > explanation I can see is that the output signal was longer than the > input signal, and that thus I should do one further convolution by a > chirp to bring that small chirp vertical.
Dunno how that could be made to work even if it could be. I'd make sure the generating D/A clock was the same one as the sampling A/D clock. I.e. same sound card on the same computer with its clock being internally generated. Working with a stimulus and response that don't use a common time base is pretty much out of bounds. There was a DX plugin from Sound Forge once upon a time called Acoustic Modeler which allowed asynchronous operation. Somehow it was able to very accurately determine the relative clock rate of the response sampling clock and analytically generated the inverse stimulus at that rate before doing the convolution. The implementor was closed mouth about how that rate determination was done (possibly by first generating a little chirp the way you have and adjusting the inverse rate based on its length for a second pass.) Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein