Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Integration in MATLAB

Status
Not open for further replies.

David83

Advanced Member level 1
Advanced Member level 1
Joined
Jan 21, 2011
Messages
410
Helped
45
Reputation
92
Reaction score
45
Trophy points
1,308
Visit site
Activity points
3,639
Hello all,

I have this received signal v(t) and I want to find the following integration in MATLAB:

\[\int_{kT_s+\tau_p}^{(k+1)T_s+\tau_p}v(t)\,dt\]

How can I do that?

Note: v(t) was generated with oversampling factor of nsamp, which implies that the sample time is Ta=Ts/nsamp.

Thanks
 

syms t; % declares t as the variable of integration
vpa( int( v(t), lower limit, upper limit ))

If the limits are variables, use loops to increment the value of limits each time before performing integration.
Hope this helps.
 

syms t; % declares t as the variable of integration
vpa( int( v(t), lower limit, upper limit ))

If the limits are variables, use loops to increment the value of limits each time before performing integration.
Hope this helps.

Thanks for replying.

I am working in a digital communication system, where v(t) is the received signal due to transmitting the N-by-1 vector d over the channel h(t). So, the vector t=0:Ta:(N-1)*Ta, where Ta=Ts/nsamp is the sample time, and nsamp is the number of samples per symbol.

Does the above still hold correct?
 

I suppose you want to integrate v(t) between two successive sampling periods and add the results. Consider the attachment below. Do you intend to do that?
 

Attachments

  • IMG00056-20140508-2200.jpg
    IMG00056-20140508-2200.jpg
    196.6 KB · Views: 85

I suppose you want to integrate v(t) between two successive sampling periods and add the results. Consider the attachment below. Do you intend to do that?

Yes, exactly.

- - - Updated - - -

I suppose you want to integrate v(t) between two successive sampling periods and add the results. Consider the attachment below. Do you intend to do that?

But the integration limits are multiple of Ts (the symbol time) not Ta (the sample time).
 

Ok now consider the following:

1. Define the duration of T ie. the sampling time.
2. Define an accumulator and initialize it to zero. Eg A = 0;
3. Create a "for loop" that will run N times. Where N is the total number of sampling periods. Let n (small n) be the loop variable. Each loop will perform one definite integration. (Note that n should starts from 1)
4. Inside the loop you have to dynamically update the integration limit. For this create two variables.
L1 = (n-1)*T % Lower limit. ( to make the first limit 0, we use (n-1))
L2 = L1 + T % Upper limit
5. Perform integration and store in a variable. For example
x = vpa( int( v(t), L1, L2 ))
6. Store result in an accumulator.
A = A + x;
After the loop breaks, A is the final answer.

- - - Updated - - -

Oh just realized, since you are not addressing any array from the loop variable (n) directly, you may start the loop from 0 instead of one, and then use n instead of (n-1)
 

Ok now consider the following:

1. Define the duration of T ie. the sampling time.
2. Define an accumulator and initialize it to zero. Eg A = 0;
3. Create a "for loop" that will run N times. Where N is the total number of sampling periods. Let n (small n) be the loop variable. Each loop will perform one definite integration. (Note that n should starts from 1)
4. Inside the loop you have to dynamically update the integration limit. For this create two variables.
L1 = (n-1)*T % Lower limit. ( to make the first limit 0, we use (n-1))
L2 = L1 + T % Upper limit
5. Perform integration and store in a variable. For example
x = vpa( int( v(t), L1, L2 ))
6. Store result in an accumulator.
A = A + x;
After the loop breaks, A is the final answer.

- - - Updated - - -

Oh just realized, since you are not addressing any array from the loop variable (n) directly, you may start the loop from 0 instead of one, and then use n instead of (n-1)

int Alternative entry to the symbolic integration function.

It gives me error in my program that "Undefined function 'int' for input arguments of type 'double'."
 

The code will be worth something! (post it)

OK, let us start from the beginning to understand the code:

I have a transmit vector

\[\mathbf{d}=[d_{-L} ... d_0 d_1 ... d_{N-1}]\]

where L is the cyclic prefix length, and N is the data block length. The passband transmit signal is given by:

\[d(t)=\Re\left\{e^{j 2 pi f_c t}\sum_{k=-L}^{K-1}d_kg(t-kT_s)\right\}\]

where f_c is the carrier frequency. The linear time invariant channel impulse response is given by:

\[h(\tau)=\sum_{p=1}^{N_p}h_p\delta(\tau-\tau_p)\]

So, the baseband received signal is given by:

\[v(t)=\sum_{k=-L}^{K-1}d_k\sum_{p=1}^{N_p}h_pe^{-j2 pi f_c \tau_p}g(t-kT_s-\tau_p)+w(t)\]

I will post the code up to here to see if it is correct or not:

Code:
clear all;
clc;

SNRdB=0:1.5:25;                          %SNR in dB               
SNR=10.^(SNRdB./10);

N=128;                                       %Number of symbols per block
fc=30*10^3;                               %Carrier frequency
B=1000;                                      % Bandwidth
Ts=1/(2*B);                                 %Symbol Time
nsamp=10^3;                                %#of samples per symbol
Ta=Ts/nsamp;                                %Sample time
K=N*nsamp;                                   %Total number of samples

tau=[0 5 7 20].*10^-3;                    %Paths' Delays

h=[1 1 1 1];                                    %Channel gains
h=h/sqrt(h*h');
Np=length(tau);


CP_ms=30*10^-3;                            %CP length
CP_Ta=round(CP_ms/Ta);                   %CP in sample time
CP_Ts=round(CP_ms/Ts);                    %CP in symbol time

t=-CP_Ta*Ta:Ta:(K+CP_Ta-1)*Ta;       %t vector that includes the CP and postfix

nErr=zeros(1,length(SNR));
Count=zeros(1,length(SNR));

eNum=10;

for ii=1:length(SNR)
    N0=1/(SNR(ii));
    while nErr(ii)<eNum
        
        Count(ii)=Count(ii)+N;
       
        bs=rand(N,1)>0.5;               
        ds=2.*bs-1;
        
        da= reshape(repmat(ds(:).',nsamp,1),1,[]);
        dCP=[da(end-CP_Ta+1:end) da da(1:CP_Ta)];
        
        y=zeros(size(t));
         
        for pp=1:Np
            yTemp=interp1(t,dCP,t-tau(pp),'linear');
            y=y+yTemp*h(pp)*exp(-1i*2*pi*fc*tau(pp));
        end   
    end
end

Is using interpolation is correct in this context? Because I get NaN when use flag 'linear' but I get some results when using the flag 'cubic'.

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top