# How can I implement a binary chirp signal containing zeros and ones?

I build a signal, $x$, which is linear in the frequency domain as (in MATLAB syntax)

x = 1:0.1:1e3;


Then I do:

y = (ifft(x));


and I would like to build a binary signal (zeros and ones) from $y$, but I can't define any threshold value such that

if y(index) > threshold
y(index) = 1
else y(index) = 0


How can I implement a chirp of zeros and ones in the time domain?

• What do you mean by a "chirp of ones and zeros?" Are you trying to implement a square wave (or pulse train) with a chirped frequency instead of a sinusoid? – Jason R Jan 3 '12 at 13:57

Instead of building the chirp signal in frequency domain you could build it in time domain.

You could generate a sin signal with an increasing frequency.

Then your threshold could be 0.

Eg:

fmin = 0.001;
fmax = 50*fmin;
numOfSamples = 1500;
f = linspace(fmin,fmax,numOfSamples);
t = 1 : numOfSamples;

w = 2 * pi * f;

x = sin(w.*t);
plot(x)
binaryChirp = floor(1 + x);
figure,plot(binaryChirp)


Note: You might be aware of this, but I'd like to point out that the method you described in your question will generate complex samples, so I don't think you can compare them directly to a threshold.

• you are totally right, but why what i have done doesn't work? do you have any clue? – 0x90 Jan 2 '12 at 21:25
• 1. To get real samples, your spectrum(x) should be symmetric. you are giving x values for frequencies between [0 and fs/2], but you ifft expects to recieve values for frequencies between [0 and fs]. You can plot the magnitudes(abs) of ffts of some real signals to see what I mean. 2. The ifft returns a signal that has all the frequency components that you have given to it, all at once. In a chirp signal the different frequencies are present at different moments in time, not all at the same time. – TwoSan Jan 3 '12 at 9:18
• You're generating a square wave chirp by thresholding in the discrete time domain? That's going to produce a lot of aliasing frequency components. Listen to a wav file of your chirp and you will hear frequencies swooping up and down at the same time in the background. Maybe it doesn't matter for this application, but in general it's a bad method; not producing the same thing as sampling a true square wave chirp would produce. See slack.net/~ant/bl-synth – endolith Jun 5 '12 at 14:46

What is a chirp signal?

A chirp signal is a sinusoidal signal of the form $\sin(bt+\frac{1}{2}at^2)$ whose instantaneous radian frequency (the derivative with respect to time of the argument of the sine, viz. $b+ at$, is a linear function of $t$. If the chirp signal is of duration $T$, then the instantaneous frequency at the end is $B=b+aT$. If $a > 0$, the frequency increases with time from the initial value $b$ to its maximum value $B$ at $t = T$, while if $a<0$, the frequency decreases from $b$ downwards to the minimum value $B$ at $t = T$.

Is the Fourier transform of a chirp signal constant over the frequency range $[b,B]$ (or $[B,b]$ for pessimists who choose $a < 0$)?

No, the Fourier transform is not constant over this frequency range. Nor does the DFT have equal amplitude in all bins if we sample the chirp signal and compute its DFT.

What is a fake chirp signal?

A fake chirp signal is one whose instantaneous radian frequency increases in steps of equal height $\Delta = (B-b)/n$ but decreasing durations so that it consists of one full period of $\sin(bt)$ followed by one full period of $\sin((b+\Delta)t)$ followed by one full period of $\sin((b+2\Delta)t)$, $\ldots$, followed by one full period of $\sin((b+(n-1)\Delta)t) = \sin((B-\Delta)t)$. Note that the total duration is $$T = 2\pi\left[\frac{1}{b} + \frac{1}{b+\Delta} + \cdots + \frac{1}{b+(n-1)\Delta}\right]$$ To maintain phase continuity, we insist that each full period start and end at $0$ amplitude and $0$ phase so that, for example, between $t=\frac{2\pi}{b}$ and $t=\frac{2\pi}{b}+\frac{2\pi}{b+\Delta}$ when we have a sinusoid of radian frequency $b+\Delta$, the exact mathematical expression for the signal is $\sin((b+\Delta)t+\theta)$ where $\theta$ is chosen so that $(b+\Delta)\frac{2\pi}{b}+\theta$ is an integer multiple of $2\pi$.

What is a binary chirp signal?

If you create a chirp signal, sample it, and hard-limit it to $\pm 1$ (or, as you prefer, shift the dc level so that the signal is $0$s and $1$s) then you can call it a binary chirp signal, but you shouldn't expect it to have the properties one expects of a chirp signal. In any case, it is necessary to have $b,B \ll f_s$ where $f_s$ is the sampling rate to get something reasonable. If you don't want to go through the hassle of creating a sampled chirp signal, etc. you can get something that can be called a faker binary chirp signal very simply. Here are two examples.

$$111110000011110000111000110010~\text{or}~1111100001110010$$

The first sequence is effectively one period of a sinusoid with $10$ samples per period followed by one period of a sinusoid with $8$ samples per period followed by one period of a sinusoid with $6$ samples per period, etc. The second sequence has half periods of sinusoids with decreasing numbers of samples per period. I call this a faker binary chirp signal because instead of the frequency of the sinusoid increasing in constant steps, it is the period of the sinusoid that is decreasing in constant steps. So we don't have the linear frequency sweep that characterizes chirp signals. But the signal is trivial to synthesize, and if $b, B \ll f_s$, the difference between a fake binary chirp and a faker binary chirp can be small.

I don't read MATLAB but if x = 1:0.1:1e3; means that it is desired that the frequency sweep from $1$ Hz to $1000$ Hz (or by a factor of $1000$ in general), then the digital sequence (whether sampled from a true chirp pr a fake chirp or synthesized as a faker chirp) is going to begin with long strings of $1$s followed by long strings of $0$s. Matters will be even worse if a frequency resolution or step size $\Delta$ of $0.1$ Hz is required.

• Just as a note, in MATLAB, the string x = 1:0.1:1e3; sets x equal to a vector whose first element is $1$, the spacing between elements is $0.1$, and the last element is less than or equal to $1000$. So, $x = [1, 1.1, \ldots , 999.9, 1000]$. – Jason R Jan 4 '12 at 16:54
• @JasonR Thanks, that's what I thought it meant. The OP was taking $x$ to be the DFT of the chirp signal (which makes no sense to me) and I tried to address the issue a little in my answer by talking about the properties that the DFT of a chirp signal does not have. – Dilip Sarwate Jan 4 '12 at 17:09