Elimination of for loops

조회 수: 1 (최근 30일)
Howard Wilton
Howard Wilton 2022년 11월 17일
편집: Bruno Luong 2022년 11월 17일
I am learning how to optimize code in MATLAB.
I have the following mathematical experession, where is a unit pulse of length T, and is a constant.
I am looking to eliminate the for loops for n and l but I am struggling with how to apply the unit pulse.
Would welcome any input folks may have.
  댓글 수: 4
Howard Wilton
Howard Wilton 2022년 11월 17일
Sorry, here is the definition, .
Bruno Luong
Bruno Luong 2022년 11월 17일
편집: Bruno Luong 2022년 11월 17일
Then if I'm mot mistaken you don't need any loop at all. For given t
  • There is at most only one l that make sp(t-lT) = 1. The inner sum has only one term that is not 0.
  • The outer term is a sum of geometric series, you have a formula for it.

댓글을 달려면 로그인하십시오.

답변 (2개)

Matt J
Matt J 2022년 11월 17일
편집: Matt J 2022년 11월 17일
L=2;
T=1;
w0=2*pi;
N=3;
ts=linspace(0,T,101)'; ts(end)=[];
w=w0+(0:N-1)/T;
s=repmat(sum(exp(1j*ts*w) ,2).',1,L);

Bruno Luong
Bruno Luong 2022년 11월 17일
편집: Bruno Luong 2022년 11월 17일
L=2;
T=1;
w0=2*pi;
N=3;
% Any t as you like without restriction
t = linspace(0,L*T,500);
l = floor(t / T);
dt = mod(t, T); % dt = t-lT
s = exp(1j*dt.*w0).*(1-exp(1j*dt*N/T))./(1-exp(1j*dt/T));
s(l < 0 | l >= N) = 0; % inner sum has 0 term for these conditions
plot(s)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by