% file: com8001r3.M % modified: 9-3-02 % Author: MSS/Alain Zarembowitch % %-------------------- % Generates baseband signal for the COM-8001 pattern generator % Format is 2 (complex) * 10-bit (unsigned). % Generate one sinewave and a QPSK modulated signal at frequency reference fc1 and fc2 respectively. %-------------------- fs = 120000; % sampling rate 200 KHz typ. nsamples = 400; % simulation duration, expressed as number of complex samples nsamplespersymbol = 16; % number of samples/symbol. sets the symbol rate = fs/nsamplespersymbol. fc1 = 10000; % sinewave1 in Hz fc2 = 20000; % modulated signal center frequency in Hz gain1 = 0.7 % amplitude scaling factor gain2 = 0.7 % amplitude scaling factor % for long simulations, store results in output file [fid_o1,message] = fopen('com8001r3.bin','w'); if(fid_o1 == -1) message end % initialization last_i = 0; last_q = 0; current_i = 0; current_q = 0; b = dec2bin(0,10); test1 = (1:nsamples); test2 = (1:nsamples); % synthesize square root raised cosine modulation % 25 % rolloff, square root, (INTELSAT) % filter order N = 32 nfilter = 32; symbol_rate = fs/nsamplespersymbol; rolloff = 0.25; coeff_txfil = Firrcos(nfilter, symbol_rate/2., rolloff, fs, 'rolloff', 'sqrt'); % store filter configuration at each sample yii = zeros(nfilter,1); yiq = zeros(nfilter,1); %------------------------------------------------------ % MAIN LOOP %------------------------------------------------------ % loop signal processing (cannot use vectors) for j = 1:nsamples i = j; % simulate the first sinewave phase1 = 2.*pi*fc1*(i-1)/fs; % carrier phase carrier1_cos = cos(phase1); carrier1_sin = sin(phase1); sigt1i = carrier1_cos*gain1; sigt1q = carrier1_sin*gain1; test1(i) = sigt1i; test2(i) = sigt1q; % simulate the second sinewave phase2 = 2.*pi*fc2*(i-1)/fs; % carrier phase carrier2_cos = cos(phase2); carrier2_sin = sin(phase2); test3(i) = carrier2_cos*gain2; test4(i) = carrier2_sin*gain2; % modulated 2nd carrier % generate new random symbol if i = 1 modulo nsamplespersymbol % Generate PULSES, not square waveforms. if(mod(i,nsamplespersymbol) == 1) bi = rand; if(bi > 0.5) ai = 1; else ai = -1; end bq = rand; if(bq > 0.5) aq = 1; else aq = -1; end else ai = 0; aq = 0; end % implement transmit filtering on both in-phase and quadrature channels % uncomment this line [sigt2i, yfi] = filter(coeff_txfil, 1, ai, yii, 1); yii = yfi; [sigt2q, yfq] = filter(coeff_txfil, 1, aq, yiq, 1); yiq = yfq; test5(i) = sigt2i; test6(i) = sigt2q; % QPSK modulation sigt3i = gain2*((carrier2_cos * sigt2i) - (carrier2_sin * sigt2q)); sigt3q = gain2*((carrier2_sin * sigt2i) + (carrier2_cos * sigt2q)); test7(i) = sigt3i; test8(i) = sigt3q; % sum both signals. Scale to prevent overflow sigt4i = (sigt1i + sigt3i)/2.; sigt4q = (sigt1q + sigt3q)/2.; test9(i) = sigt4i; test10(i) = sigt4q; % convert samples to 10-bit unsigned format sigt4i = min(max((floor((sigt4i+1.)*511.5)),0.),1023); sigt4q = min(max((floor((sigt4q+1.)*511.5)),0.),1023); %invert bit order because of pinout a = dec2bin(sigt4i, 10); b(1) = a(10); b(2) = a(9); b(3) = a(8); b(4) = a(7); b(5) = a(6); b(6) = a(5); b(7) = a(4); b(8) = a(3); b(9) = a(2); b(10) = a(1); outputi = bin2dec(b); a = dec2bin(sigt4q, 10); b(1) = a(10); b(2) = a(9); b(3) = a(8); b(4) = a(7); b(5) = a(6); b(6) = a(5); b(7) = a(4); b(8) = a(3); b(9) = a(2); b(10) = a(1); outputq = bin2dec(b); % pack samples into byte-size format % wait until two complex samples are collected before writing into file (makes it easier to % manage the byte alignments): 4 * 10-bits is a multiple of 8. if(mod(j,2) == 0) % even sample current_i = outputi; current_q = outputq; a = bitand(bitshift(last_q,-2), 255); fprintf(fid_o1,'%c',a); a = bitand(bitor(bitshift(last_q,6),bitshift(last_i,-4)),255); fprintf(fid_o1,'%c',a); a = bitand(bitor(bitshift(last_i,4),bitshift(current_q,-6)),255); fprintf(fid_o1,'%c',a); a = bitand(bitor(bitshift(current_q,2),bitshift(current_i,-8)),255); fprintf(fid_o1,'%c',a); a = bitand(current_i,255); fprintf(fid_o1,'%c',a); % keep track of simulation progress if(mod(j,10000) == 0) j/10000 end; else % odd sample % remember last sample last_i = outputi; last_q = outputq; end; end subplot(5,1,1); title('first sine'); plot(test1); hold on; plot(test2,'r'); ylabel('') subplot(5,1,2); title('second sine'); plot(test3); hold on; plot(test4,'r'); ylabel('') subplot(5,1,3); title('modulated second signal'); plot(test5); hold on; plot(test6,'r'); ylabel('') subplot(5,1,4); title('QPSK modulation'); plot(test7); hold on; plot(test8,'r'); ylabel('') subplot(5,1,5); title('sum of first signal and QPSK modulated second signal'); plot(test9); hold on; plot(test10,'r'); xlabel(''); ylabel('') % close opened files fclose(fid_o1);