Connect with us

Qestion about ofdm

Discussion in 'Microcontrollers, Programming and IoT' started by engineer61, Oct 5, 2012.

Scroll to continue with content
  1. engineer61


    Oct 5, 2012
    this is program coded ofdm pam raleigh fading for M=4 i try change the M from M=4 to M=2 or M=8 the program don't work i need any person help me in change the M and help me in run the program

    clear all;
    nCPLen = nFFT/4;
    nSamples = nFFT+nCPLen;
    nDSC = 52; % number of data subcarriers
    nBitPerSym = 52; % number of bits per OFDM symbol (same as the number of subcarriers for BPSK)
    nSym = 10^4; % number of symbols
    EbN0dB = 0:40; % bit to noise ratio
    EsN0dB = EbN0dB + 10*log10(nDSC/nFFT) + 10*log10(nFFT/nSamples); % converting to symbol to noise ratio
    N = 10^6; % number of bits or symbols
    M=4; % Constellation order
    % multipath channel
    nTap = 10;
    ht = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + 1i*randn(nSym,nTap));
    % computing and storing the frequency response of the channel, for use at recevier
    hF = fftshift(fft(ht,nFFT,2));
    % Transmitter
    % conv coder
    ipBit_bin = randi([0 1],1,nBitPerSym*nSym);
    trellis = poly2trellis(7,[171 133]);
    coded = convenc(ipBit_bin,trellis);
    ipBit = bi2de(reshape(coded,2,[])');
    % Modulator
    ipMod = pammod(ipBit,M);
    ipMod = reshape(ipMod,nBitPerSym,nSym).'; % grouping into multiple symbolsa
    % Assigning modulated symbols to subcarriers from [-26 to -1, +1 to +26]
    xF = [zeros(nSym,(nFFT-nDSC)/2) ipMod:),1:nBitPerSym/2) zeros(nSym,1) ipMod:),nBitPerSym/2+1:nBitPerSym) zeros(nSym,(nFFT-nDSC)/2-1)] ;
    % Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the power of transmit symbol to 1
    xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';
    % Appending cylic prefix
    xtcp = [xt:),(end-nCPLen+1):end) xt];
    % convolution of each symbol with the random channel
    xht = zeros(nSym,nTap+nSamples-1);
    for jj = 1:nSym
    xht(jj,:) = conv(ht(jj,:),xtcp(jj,:));
    % Concatenating multiple symbols to form a long vector
    xt = reshape(xht.',1,nSym*(nTap+nSamples-1));
    % Gaussian noise of unit variance, 0 mean
    nt = 1/sqrt(2)*randn(1,nSym*(nTap+nSamples-1)) + 1i*randn(1,nSym*(nTap+nSamples-1));
    nErr = zeros(size(EbN0dB));
    for ii = 1:length(EbN0dB)
    % Adding noise, the term sqrt(80/64) is to account for the wasted energy due to cyclic prefix
    yt = sqrt(nSamples/nFFT)*xt + 10^(-EsN0dB(ii)/20)*nt;
    % Receiver
    yt = reshape(yt.',nSamples+nTap-1,nSym).'; % formatting the received vector into symbols
    yt = yt:),(nCPLen+1):nSamples); % removing cyclic prefix
    % converting to frequency domain
    yF = (sqrt(nDSC)/nFFT)*fftshift(fft(yt.')).';
    % equalization by the known channel frequency response
    yF = yF./hF;
    % extracting the required data subcarriers
    yMod = yF:),[((nFFT-nDSC)/2+1):nFFT/2 (nFFT/2+2):nFFT/2+1+nBitPerSym/2]);
    % PAM demodulation
    % converting modulated values into bits
    ipBitHat = reshape(ipBitHat.',nBitPerSym*nSym,1);
    ipBitHat_bin = reshape(de2bi(ipBitHat)',[],1);
    tblen = 12;
    ipBitHat_dec = vitdec(ipBitHat_bin,trellis,tblen,'cont','hard',[],[],[])';
    % couting the number of errors
    nErr(ii) = size(find(ipBitHat_dec(13:end) - ipBit_bin(1:end-12)),2);
    simBer = nErr/(nSym*nBitPerSym);
    EbN0Lin = 10.^(EbN0dB/10);
    theoryBer = 0.5.*(1-sqrt(EbN0Lin./(EbN0Lin+1)));
    close all; figure;
    hold on;
    axis([0 35 10^-5 1]);
    grid on;
    legend('Rayleigh-Theory', 'Rayleigh-Simulation');
    xlabel('Eb/No, dB');
    ylabel('Bit Error Rate');
    title('BER for PAM using OFDM in a 10-tap Rayleigh channel');
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Electronics Point Logo
Continue to site
Quote of the day