MC-CDMA.rar

  • Arsy
    了解作者
  • matlab
    开发工具
  • 40KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-04-19 15:17
    上传日期
This folder provides the Matlab codes of MC-CDMA in AWGN and Rayleigh channel
MC-CDMA.rar
  • FFT Based MC-CDMA with Rayleigh Channel
  • berr_result.fig
    3.2KB
  • papr_result.fig
    3.1KB
  • main_body.m
    6.5KB
  • psd_result.fig
    31.7KB
  • spread_code.m
    332B
  • FFT Based MC-CDMA with Noise
  • basic_mc_cdma.m
    5.5KB
  • spread_code.m
    332B
内容介绍
clc clear all close all %% Simulation Parameters % M = input('Enter Number of constellation Points = '); % Constellation Points M = 16; k = log2(M); % Bits per Symbol N = 10400; % Number of Data Bits data_carrier = 52; % Number of Data Carriers zero_carriers = 12; % Number of Zero Carriers cp_carrier = 32; % Number of Cyclic Prefix Carriers t_carrier = data_carrier+zero_carriers+cp_carrier; % Total Carriers l_sub = data_carrier*k; % Number of data bits within a subcarrier nFFTSize = 64; % Size of FFT & IFFT ofdm_data =[]; % Empty Array declared for OFDM data chip_bits = 4; % Number of Chips samp_time = 1e-5; samp = 1/samp_time; chip_duration = 0.1e-4; % Chip duration bit_duration = chip_duration*chip_bits; chip_samp = chip_duration/samp_time; bit_samp = chip_samp*chip_bits; Nsyms_ofdm = chip_bits*N/l_sub; % Total number of OFDM Symbols X = 1000; % Averaging avg_ber = []; Eb_No = 0:3:30; SNR = Eb_No + 10*log10(data_carrier/t_carrier) + 10*log10(log2(M)) - 10*log10(2.7/1.25); x = []; r = []; %% Random Generation of Data data_bits = randint(1,N); % Random data of user data_pulse = rectpulse(data_bits,bit_samp); % Pulse Shaping %% Generation of Code [sp] = spread_code(chip_bits,N,chip_samp,2); sp_code = sp'; %% Spreading spread_data = xor(data_pulse,sp_code); %% Subcarriers for i = 1:Nsyms_ofdm block(i,1:l_sub) = spread_data(((l_sub*(i-1))+1):(l_sub*i)); % Bits in OFDM SYmbol m = block(i,1:l_sub); %% Binary to Decimal Conversion reshaping = reshape(m,length(m)/k,k); conversion = bi2de(reshaping); conversion = conversion.'; %% Modulation modulation = qammod(conversion,M); %% Zero Padding Z_data = [zeros(1,6) modulation zeros(1,6)]; %% IFFT out_ifft = ifft(Z_data,nFFTSize); %% Adding Cyclic Prefix and Cyclic Suffix start = length(out_ifft)- length(out_ifft)/4 + 1; % calculating starting point of cyclic prefix start1 = length(out_ifft)/4; % calculating ending point of cyclic suffix sufix = out_ifft(1:start1); % extracting cyclic suffix from msg. signal prefix = out_ifft(start:end); % extracting cyclic prefix from msg. signal CP = [prefix out_ifft sufix]; %% OFDM Data ofdm_data = [ofdm_data CP]; op_ifft = ifft(Z_data,nFFTSize); meanSquareValue = op_ifft*op_ifft'/length(op_ifft); peakValue = max(op_ifft.*conj(op_ifft)); paprSymbol(i) = peakValue/meanSquareValue; end %% Channel H = 1/sqrt(2)*(randn(1,length(ofdm_data)) + 1i*randn(1,length(ofdm_data))); ofdm_chann = H.*ofdm_data; %% Receiver for avg = 1:X berr = []; for i=1:length(Eb_No) ofdm_n = awgn(ofdm_chann,SNR(i),'measured'); % Adding AWGN received_data = []; %% Channel Estimation ofdm_rcv = ofdm_n./H; %% Subcarriers for j = 1:Nsyms_ofdm blocks(j,1:96) = ofdm_rcv(((96*(j-1))+1):(96*j)); % taking one sub-carrier at a time m_2 = blocks(j,1:96); %% Removing Cyclic Prefix and Cyclic Suffix removing_cp_cs = m_2(:,17:80); %% FFT out_fft = fft(removing_cp_cs,nFFTSize); %% Removing Zero Padding removing_z_padding = out_fft(:,7:58); %% Demodulation demodulation = qamdemod(removing_z_padding,M); %% Conversion Decimal to Binary conversion_2 = de2bi(demodulation); %% Original length reshaping_2 = reshape(conversion_2,1,length(conversion_2)*k); % reshaping to the original length %% Recieved bits received_data = [received_data reshaping_2]; end %% Despreading rxsym = xor(received_data,sp_code); %% Bits Received rxa = intdump(double(rxsym),bit_samp); rxa = round(rxa); %% Calculating Bits in Error [num(i) berr(i)] = biterr(data_bits,rxa); end avg_ber = [avg_ber;berr]; end avg_ber_sum = sum(avg_ber,1)/X; figure; semilogy(Eb_No,avg_ber_sum,'r-*'); title('BER vs Eb/No'); ylabel('BER'); xlabel('Eb/No (dB)'); grid; %% CDF Plot figure; paprSymboldB = 10*log10(paprSymbol); [n x] = hist(paprSymboldB,[0:0.5:10]); plot(x,cumsum(n)/Nsyms_ofdm,'LineWidth',2) xlabel('papr, x dB') ylabel('Probability, X <=x') title('CDF plots of PAPR of OFDM') grid on figure; grid; Fs = 2.7; F = 0:0.001:Fs; P = pwelch(ofdm_data,[],[],length(F),Fs); plot(F,10*log10(P)); title('Power Spectral Density of all OFDM Symbols'); ylabel('Power/Frequency (db/Hz)'); xlabel('Frequency (MHz)'); axis([0 Fs -55 0]); grid;
评论
    相关推荐