?? spacefrequencytime1.m
字號:
clear all;
close all;
clc;
% Basic MIMO OFDM system parameters
NTX=3; %no of transmit antennas
NRX=3; %no of receive antenna
IFFT_bin_length = 64; % IFFT bin count for Tx and Rx
carrier_count = 12; % number of carriers
bits_per_symbol = 2; % bits per symbol
symbols_per_carrier = 8; % symbols per carrier
SNR = 10; % channel signal to noise ratio (dB)
% Binary data generation
sourcedata_length = carrier_count * symbols_per_carrier * bits_per_symbol;
sourcedata = round(rand(1,sourcedata_length));
%plot of first 30 binary data
% figure(1);
% subplot(2,1,1);
% stem(1:30,sourcedata(:,1:30),'r');
% axis([0 30 0 1]);
% xlabel('time');
% ylabel('amplitude');
% title('Binary data stream');
% Convert binary data to 'modulo N' integers where N = 2^bits_per_symbol
convert_matrix = reshape(sourcedata, bits_per_symbol, length(sourcedata)/bits_per_symbol);
for k = 1:(length(sourcedata)/bits_per_symbol)
modulo_data(k) = 0;
for i = 1:bits_per_symbol
modulo_data(k) = modulo_data(k) + convert_matrix(i,k)*2^(bits_per_symbol-i);
end
end
% plot of first 15 modulo-4 symbols
% figure(1);
% subplot(2,1,2);
% stem(1:15,modulo_data(:,1:15),'b');
% axis([0 15 0 5]);
% xlabel('time');
% ylabel('amplitude');
% title('modulo-4 symbols');
% differential coding the data symbols
% carrier_matrix = reshape(modulo_data, carrier_count, symbols_per_carrier)';
% carrier_matrix = [zeros(1,carrier_count);carrier_matrix];
% for i = 2:(symbols_per_carrier + 1)
% carrier_matrix(i,:) = rem(carrier_matrix(i,:)+carrier_matrix(i-1,:),2^bits_per_symbol);
% end
% PSK modulation
carrier_phase = modulo_data * ((2*pi)/(2^bits_per_symbol));
carrier_phase=(carrier_phase+pi/4);
[X,Y] = pol2cart(carrier_phase, ones(size(carrier_phase,1),size(carrier_phase,2)));
complex_carrier = complex(X,Y);
complex_carrier=complex_carrier(1:72);
% Constellation diagram of 4-psk modulated symbols
% scatterplot(complex_carrier);
%space time coding of modulated symbols
%first row of space time data
y=length(complex_carrier)/3;
stlenr1=length(complex_carrier)+y;
for x=1:4:(stlenr1-3)
for i=1:3:(length(complex_carrier)-2)
stdata1(x)=complex_carrier(i);
stdata1(x+1)=-conj(complex_carrier(i+1));
stdata1(x+2)=conj(complex_carrier(i+2));
stdata1(x+3)=0;
% end
% end
%
% second row of space time data
% for x=1:4:(stlenr1-3)
%
% for i=1:3:(length(complex_carrier)-2)
%
stdata2(x)=complex_carrier(i+1);
stdata2(x+1)=conj(complex_carrier(i));
stdata2(x+2)=0;
stdata2(x+3)=conj(complex_carrier(i+2));
% end
% end
% third row of space time data
stdata3(x)=complex_carrier(i+2);
stdata3(x+1)=0;
stdata3(x+2)=-conj(complex_carrier(i));
stdata3(x+3)=-conj(complex_carrier(i+1));
end
end
%space frequency coding
stdata1=[stdata1];
ns=8;
% step=((ns/2)+ns);
for i=1:12:length(stdata1)
% for i=1:((ns/2)+ns):
sfdata(i)=stdata1(i);
sfdata(i+1)=stdata1(i+1);
sfdata(i+2)=stdata1(i+2);
sfdata(i+3)=stdata1(i+3);
sfdata(i+4)=stdata1(i+ns);
sfdata(i+5)=stdata1((i+1)+ns);
sfdata(i+6)=stdata1(ns+(i+2));
sfdata(i+7)=stdata1((ns+i+3));
sfdata(ns+i)=stdata1((ns/2)+i);
sfdata(ns+(i+1))=stdata1((ns/2)+(i+1));
sfdata(ns+(i+2))=stdata1((ns/2)+(i+2));
sfdata(ns+(i+3))=stdata1((ns/2)+(i+3));
end
sfdata1=sfdata;
sf1=reshape(sfdata1,8,12);
% %creating matrix for IFFT carriers for Antenna1
carrier_matrix=sf1;
% carrier_matrix = reshape(sfTx1,carrier_count, symbols_per_carrier)';
carriers = (1:carrier_count) + (floor(IFFT_bin_length/4) - floor(carrier_count/2));
conjugate_carriers = IFFT_bin_length - carriers + 2;
% %Mapping of carriers for ifft
IFFT_matrix = zeros(symbols_per_carrier, IFFT_bin_length);
IFFT_matrix(:,carriers) = carrier_matrix;
IFFT_matrix(:,conjugate_carriers) = conj(carrier_matrix);
% % frequency domain representation of modulated data
% figure (2);
% subplot(2,1,1);
% stem(0:IFFT_bin_length-1, abs(IFFT_matrix(2,1:IFFT_bin_length)),'r*-')
% grid on;
% axis ([0 IFFT_bin_length -0.5 1.5]);
% ylabel('Magnitude');
% xlabel('IFFT Bin');
% title('OFDM Carrier Frequency Magnitude');
%
% subplot(2,1,2);
% plot(0:IFFT_bin_length-1, (180/pi)*angle(IFFT_matrix(2,1:IFFT_bin_length)), 'go')
% hold on
% stem(carriers-1, (180/pi)*angle(IFFT_matrix(2,carriers)),'b*-')
% stem(conjugate_carriers-1, (180/pi)*angle(IFFT_matrix(2,conjugate_carriers)),'b*-')
% axis ([0 IFFT_bin_length -200 +200])
% grid on
% ylabel('Phase (degrees)')
% xlabel('IFFT Bin')
% title('OFDM Carrier Phase')
% time domain waveform thro. IFFT for Antenna1
%
time_wave_matrix = ifft(IFFT_matrix');
time_wave_matrix = time_wave_matrix';
% % ofdm signal for one symbol(one row of ifft output)
% figure (4);
% plot(0:IFFT_bin_length-1,time_wave_matrix(2,:))
% grid on
% ylabel('Amplitude')
% xlabel('Time')
% title('OFDM Time Signal, One Symbol Period');
% title('Separated Time Waveforms Carriers')
colors = ['r' 'g' 'b' 'k' 'r' 'g' 'b' 'k' 'r' 'g' 'b' 'k' 'r' 'g' 'b' 'k'];
for f = 1:carrier_count
temp_bins(1:IFFT_bin_length)=0+0j;
temp_bins(carriers(f))=IFFT_matrix(2,carriers(f));
temp_bins(conjugate_carriers(f))=IFFT_matrix(2,conjugate_carriers(f));
temp_time = ifft(temp_bins');
% plot of carriers used in ofdm
% figure(5);
% % plot(1:(IFFT_bin_length/2), (temp_time/2), colors(f));
% plot(0:20, temp_time(1:21), colors(f));
% hold on
% end
% grid on
% ylabel('Amplitude')
% xlabel('Time')
% title('Separated Time Waveforms Carriers')
%
%-----------------------------------------------------------------------
% Apply a Window Function to each time waveform
% - NOTE THAT WINDOWING IS CURRENTLY COMMENTED OUT, i.e. NO WINDOWING
% - each time waveform (row of time_wave_matrix) represents one symbol
% period for all carriers
% - the IFFT result has discontinuities at each end
% - when the time waveforms are serialized (concatenated), the discontinuites
% will introduce unwanted frequency components
% - the window function deemphasizes the signal at the end
% points (at the discontinuites)
% - this reduces the effects of the discontinuities
% - it also distorts the desired frequency response (undesired side effect)
% - between Blackman, Hanning, and Hamming: Hamming introduces less distortion
% - note that the transpose of the Hamming function is
% used (because a row vector is needed)
%
% Since all imaginary values of time_wave_matrix are practically equal to zero,
% only the real part is retained for windowing.
for i = 1:symbols_per_carrier
% for i = 1:symbols_per_carrier + 1
windowed_time_wave_matrix(i,:) = real(time_wave_matrix(i,:)).* hamming(IFFT_bin_length)';
% windowed_time_wave_matrix(i,:) = real(time_wave_matrix(i,:));
end
%
% Serialize the modulating waveform
% - sequentially take each row of windowed_time_wave_matrix and construct a row vector
% - the row vector will be the modulating signal
% - note that windowed_time_wave_matrix is transposed, this is to account for the way the
% Matlab 'reshape' function works (reshape takes the columns of the target matrix and
% appends them sequentially)
%
ofdm_modulation = reshape(windowed_time_wave_matrix', 1, (IFFT_bin_length*(symbols_per_carrier)));
%ofdm_modulation = reshape(windowed_time_wave_matrix', 1, IFFT_bin_length*(symbols_per_carrier+1));
% PLOT OFDM SIGNAL (time)
%
% temp_time = IFFT_bin_length*(symbols_per_carrier+1);
temp_time = IFFT_bin_length*(symbols_per_carrier);
% figure (6)
% % plot(0:temp_time-1,ofdm_modulation)
%
% plot(0:temp_time-1,ofdm_modulation)
% grid on
% ylabel('Amplitude (volts)')
% xlabel('Time (samples)')
% title('OFDM Time Signal')
% %
% PLOT OFDM SIGNAL (spectrum)
symbols_per_average = ceil(symbols_per_carrier/5);
avg_temp_time = IFFT_bin_length*symbols_per_average;
averages = floor(temp_time/avg_temp_time);
average_fft(1:avg_temp_time) = 0;
for a = 0:(averages-1)
subset_ofdm = ofdm_modulation(((a*avg_temp_time)+1):((a+1)*avg_temp_time));
subset_ofdm_f = abs(fft(subset_ofdm));
average_fft = average_fft + (subset_ofdm_f/averages);
end
average_fft_log = 20*log10(average_fft);
figure (6)
plot((0:(avg_temp_time-1))/avg_temp_time, average_fft_log)
hold on
plot(0:1/IFFT_bin_length:1, -35, 'rd')
grid on
axis([0 0.5 -40 max(average_fft_log)])
ylabel('Magnitude (dB)')
xlabel('Normalized Frequency (0.5 = fs/2)')
title('OFDM Signal Spectrum')
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -