# Downconverting real signal to IQ baseband

Despite reading various answers on this site and on other sites I am still confused about how to convert a real-valued signal back down to its original IQ baseband values. Note I am still a beginner at this.

I have a very minimal prototype in Matlab but I'm getting stuck. I begin by generating some IQ data and modulating it onto a carrier signal, ready to be sent as a stream of real valued numbers.

% constants
f = 100; % carrier frequency
Fs=500; % sampling frequency
t=(1/Fs:1000)*T; % time domain

% generate 1000 raw I/Q values to *transmit*
I=randi([0 1],1000,1)';
Q=randi([0 1],1000,1)';

% modulate I/Q values onto a carrier wave
Iwave = I.*cos(2*pi*f*t);
Qwave = Q.*sin(2*pi*f*t);


I assume that adding the two waves together is correct (and not subtracting them like I've seen in some notations)

% add up I/Q. and transmit this stream of real-valued numbers
tx=Iwave+Qwave;


Now the receiver mixes the signals with cos and sin waves

rxI = tx .* (cos(2*pi*f*t));
rxQ = tx .* (sin(2*pi*f*t));


Below is an FFT of the received real-valued signal in black peaking at 100Hz. And the mixed I and Q signals on the receiver, peaking at 200Hz (I know the red peak is hard to see, but it's there at 200Hz).

Now comes the tricky part. Every resource I've read mentions I should low pass filter this I and Q, and I'll be able to get back my baseband data.

cutoff=200/Fs;
order=32;

% a 32 order low-pass FIR filter with cutoff at 200Hz
filter=fir1(order,cutoff);

filtI=filter(filter,1,rxI);
filtQ=filter(filter,1,rxQ);


Here's the FFT of the I and Q signals after low-pass filtering Now the sent and received I channel as shown below obviously look nothing alike and simply cannot be demodulated.

What am I doing wrong here? The ideal answer would specify exactly what filter I need to get back my baseband data in Matlab. This I think is reasonable since the example I provided is ideal and simple.

Please also correct any misunderstandings in this post aside from the obviously incorrect filter I am using.

• Try with a less ugly signal as original. Randi is a really bad choice - take a pencil, sketch its spectrum. Shift that spectrum. Shift it back. Low-pass filter the result. Is it the same spectrum? Note that you need to bandlimit your signals to a bandwidth much smaller than the carrier frequency before mixing. Aug 15 '17 at 8:11
• Can you provide a concrete example or refer me to a resource with a concrete example, and not just general advice/equations? A concrete example speaks a 1000 words. I ultimately want to transmit random bits. Presumably it is possible to transmit random bits. How would I make this work? Aug 15 '17 at 8:37
• As I said, your baseband signal needs to be band-limited. Yours isn't. Change that. Aug 15 '17 at 11:20
• The example you're looking for is really the drawing I asked you to make - when you make that drawing, you should see multiple ways of solving your problem. You must take care when drawing a discrete signal's spectrum - they are periodic! Aug 15 '17 at 11:22
• As I said, I am a beginner, it would be much more illustrative if you could explain in greater detail or with code how to band-limit baseband signals, and what shift you're referring to exactly. I asked this question for an expert to sketch out an example, if I knew how to do that I would have done that already. Aug 15 '17 at 22:47