注册 登录
编程论坛 Matlab

求大虾reshape错误的问题

lilihong 发布于 2008-09-27 09:34, 1445 次点击
[bo][/bo]clear all;
%********************** preparation part ***************************
para=128;   % Number of parallel channel to transmit (points) %并行信道传输个数
fftlen=128; % FFT length %fft 长度
noc=1024;    % Number of carrier %载波的个数
nd=6;       % Number of information OFDM symbol for one loop%OFDM symbol 循环个数的说明?
ml=2;       % Modulation level : QPSK %调制方式:QPSK
sr=250000;  % Symbol rate  %符号的比特率
br=sr.*ml;  % Bit rate per carrier %每个载波的比特率?
gilen=128;   % Length of guard interval (points)%%保护间隔的长度
ebn0=3;     % Eb/N0  %Eb为单位比特的平均信号的能量;n0为噪声的单边功率普密度
SNR=15;     % ENR  %信噪比
T=10^(-6);   % Sampling time : 1us%%采样时间1us 抽样频率1024kHz
%************************** transmitter发射机 *********************************
%************************** Data generation 数据生成程序****************************
seldata=rand(1,para*nd*ml)>0.5;  %  rand : built in function  %产生1x(128*6*2)=1X1536的数据
M=length(seldata)/noc;
%****************** Serial to parallel conversion串并转换 ***********************
paradata=reshape(seldata,para,nd*ml); %  reshape : built in function
%************************** QPSK modulation %QPSK 调制*****************************
[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); %  sqrt : built in function
ich1=ich.*kmod;%实部的数据
qch1=qch.*kmod;%虚部的数据
%******************* IFFT ************************
x=ich1+qch1.*i;
y=ifft(x);      %  ifft : built in function
ich2=real(y);   %  real : built in function
qch2=imag(y);   %  imag : built in function
%********* cyclic perfix insertion 循环保护间隔**********
[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%giins.m
%Function to insert guard interval into transmission signal
function [iout,qout]=giins(idata,qdata,fftlen,gilen,nd);

%******************************variables******************************
%idata: Input Ich data
%qdata: Input Qch data
%iout: Output Ich data
%qout: Output Qch data
%fftlen: Length of FFT (points)
%gilen: Length of guard interval (points)

%*********************************************************************
idata1=reshape(idata,fftlen,nd);
qdata1=reshape(qdata,fftlen,nd);
idata2=[idata1(fftlen-gilen+1:fftlen,:);idata1];
qdata2=[qdata1(fftlen-gilen+1:fftlen,:);qdata1];
iout=reshape(idata2,1,(fftlen+gilen)*nd);
qout=reshape(qdata2,1,(fftlen+gilen)*nd);

%******************************end of file****************************
%qpskmod.m
%Function to perform QPSK modulation

function [iout,qout]=qpskmod(paradata,para,nd,ml)[/color]%**************************variables********************************
%paradata: input data (para-by-nd matrix)
%iout: output Ich data
%qout: output Qch data
%para: Number of parallel channels
%nd: Number of data
%ml: Number of modulation levels
%(QPSK-2)

%*******************************************************************
m2=ml./2;
paradata2=paradata.*2-1;
count2=0;
for jj=1:nd
    isi=zeros(para,1);
    isq=zeros(para,1);
    for ii=1:m2
        isi=isi+2.^(m2-ii)...
            .*paradata2((1:para),ii+count2);
        isq=isq+2.^(m2-ii)...
            .*paradata2((1:para),m2+ii+count2);
    end
    iout((1:para),jj)=isi;
    qout((1:para),jj)=isq;
    count2=count2+ml;
end
OFDM插循环前缀的程序,第一句reshape就提示错误,idata是128*1矩阵,fftlen*nd是128*6的,因此,二者元素数量不等,提示错误。
我想这个错误是不是在QPSK调制的时候就出现了。那个jj本来是个变量,而它输出的isi是一个128*1的矩阵。而不是ii*jj矩阵,从而导致了idata是128*1的矩阵。
5 回复
#2
lilihong2008-09-27 19:38
求高手,急改,谢谢了!!!
#3
meteora11062008-09-27 22:09
你的程序在我这能运行啊,只不过估计你没注意,第35,57行你有两个子函数,在同一个文件内要调用子函数前提是这个文件本身是一个函数文件(注意是函数文件,不是通常的一般文件),在程序第一行加一句 function myfun(就是随便起一个函数文件名)就好了。
#4
lilihong2008-10-08 09:06
现在能运行了,谢谢了!!!
你也在研究这个算法吗?
可以联系一下,共同研究吗?
#5
meteora11062008-10-08 09:20
呵呵,我不是专门研究什么算法的,就是用matlab编程还比较熟,太专业的算法我也懂的不多。
#6
lilihong2008-10-16 19:52
那我又不会的可以像你请教了。呵呵 。
加我的QQ,174794424。
1