# QAM for analog and digital waves [closed]

I tried the following code for modulation of two analog waves. Can anyone point to how to modulate and demodulate for an analog and a digital wave? I tried by replacing the second signal (x2) with a digital pulse but I am not able to recover the analog wave after demodulation.

T = 1;
Fs = 44100;
t = 0:1/Fs:T;
Fc = 17000;

f1 = 100;
x1 = sin(2*pi*f1*t);
f2 = 200;
x2 = sin(2*pi*f2*t);

Cs = sin(2*pi*Fc*t);
Cc = cos(2*pi*Fc*t);

%%Modulation
mod_wav = x1.*Cs + x2.*Cc;

%%Demodulation
demod_x1 = mod_wav.*Cs;
demod_x2 = mod_wav.*-Cc;

%%filter
fpass = 10; fstop = 500; N = 30;
b = firls(N,[0 fpass fstop Fs/2]/Fs/2, [1 1 0 0], [1 1]);
filt_x1 = filter(b,1,demod_x1);
filt_x2 = filter(b,1,demod_x2);


In the above code, if i use butter filter, then it is properly working but not if i use FIR like above. Why is that? In a broader sense, when to use butter and and when to use FIR filter?

• It's going to be hard to debug your problem if you've only given a snippet of the part of the code that you say works. Try to give more details showing exactly what is wrong, preferably with a self-contained example. – Jason R Mar 6 '14 at 12:33
• +1 to what Jason said. Also, that is a strange QAM signal. I thought you meant that you had a preamble that was a chirp signal followed by the QAM modulated data, but it looks like the data is your in-phase (I) signal and the chirp is your out-of-phase (Q) signal. That is not QAM. – Jim Clay Mar 6 '14 at 13:36
• OK. Edited the question for more clarity. – BaluRaman Mar 7 '14 at 4:57
• This is a question about MATLAB program debugging and so is off-topic for this stackexchange. Please ask the moderators to move it to stackoverflow.SE or another such site. – Dilip Sarwate Mar 7 '14 at 14:16

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  6.912349e-21.

It turns out that the problem is the "/Fs/2" part. You are trying to normalize the frequencies from $0$ to $\frac{F_s}{2}$ into the range $0$ to $1$. The problem is that Matlab divides the numbers in order, so even though what you want is /(Fs/2) what you are getting is /(Fs*2). Changing the line to the following-
b = firls(N,[0 fpass fstop Fs/2]/(Fs/2), [1 1 0 0], [1 1]);