# How to find a know signal in another signal which contains other signals along with the signal i need in python

I am working on BPSK with sound waves a carrier waves.

Actually I am modulating my data with some known sync bits along with the information I need to send. So the things I will be having at demodulation side is these sync bits and carrier wave.

So I am modulating these sync bits with carrier and cross correlating this modulated (over sync bits) wave with received wave at the transmiter. By doing this I want to find the exact time position (where these sync bits appear in received wave).

For this I am first crosscorelating received wave and my sync wave then, when I plot it I wil surely get a maximum where the sync wave in both signals coincide.

But I am not sure if this maximum is the position I need (when there is a DC offset or large amplitudes in the received signal, it can also create an extreme value)

So to overcome this, I autocorelated my sync wave with itself and took the absolute difference between the all the values of crosscorelated matrix and autocorelated value. Then I assumed which ever value has the least value as the synced location.

This is also not working (I think as iam not sure that the location iam getting is midpoint of sync or starting of sync). Is this approach correct?

Or are there any other approaches to find the starting sync position in received wave?

I also needed help in knowing whether if we use the first method (wher evr maxima comes in crosscorelation taking tht as sync location) is this location I got, is sync starting location or midpoint of sync?

• Sai Teja- How long can your sync bit sequence be? See this posting, perhaps that can help you? dsp.stackexchange.com/questions/30824/… – Dan Boschen Jun 13 '16 at 2:30
• Dan Boschen- yesterday i found that my sync bit sequence is too short to give a significant peak in cross correlation, now i increased my sync bits to 1000 (where my data bits are 7000) which is giving me exact sync location, just by finding the max value of cross correlation will give mid point of my sync sequence, as i knew the sync sequence length i can figure out data start time stamp (as my data begins right after sync ends). thanks – Sate Jun 14 '16 at 4:49
• Very good. Generally if your noise is white, you are getting a 10Log10(N) advantage in SNR due to the correlation processing, where N is the number of sync bits. Knowing your SNR conditions and probability of detection you can then design how long your sync bit sequence would need to be. – Dan Boschen Jun 14 '16 at 4:54

I made a little research on detecting the sync_start location on my received signal.

First I modulated the bits (sync_start bits + data bits + sync_end bits) with a sine signal as my carrier, with a frequency of $20 \text{ kHz}$ and a total length of 10000 bits (including both sync_start and sync_end).

I then converted this modulated wave into a .wav file and played it on my PC, while recording simultaniously on an another PC, using Pyaudio (Python). That gave me a recorded .wav - my received signal.

Now as I knew my sync bits value, I modulated them on the same carrier wave and cross correlated this with the received wave.

# Case 1:

$\text{bit length} = 10000$ (including sync_start and sync_end),

$\text{number of sync_start bits} = \text{sync_end} = 2287$

The plot of cross correlation is as shown :

# Case 2:

$\text{bit length} = 15000$

# case 3:

$\text{bit length} = 20000$

As the data length increases(keeping our sync_start and sync_end same in all cases), the exact time stamps of sync_start_mid index and sync_end_mid index gets more accurate.

Note : For data bits here, I took all of them as $1$'s -- that might be the reason for the smaller amplitudes in the middle. I will add random data and see if I am getting the same inference.

Please correct me if there is any mistake in my inference. As far as now I am now able to exactly pinpoint the synchronization between transmitted and received waves.

I also wanted to know the limitations of length of the sync bits (because when my sync bits length gets smaller, the dominant peak location cannot be found from cross correlation).

And I am using a BPSK scheme.

• Sai Teja- See my comment above on SNR vs length. This holds assuming the noise from one symbol to the next are independent: When you sum two symbols for example, the signal of interest doubles (in magnitude) but the noise standard deviation will only increase by the square root of 2. Hence the 10Log10(N) increase in SNR. – Dan Boschen Jun 14 '16 at 12:50