减少傅里叶系数计算的迭代运行时间?

时间:2015-07-12 17:22:51

标签: matlab iteration signals signal-processing

下面提供用于计算傅里叶系数和生成原始信号的代码。问题是程序正常运行没有任何问题,但它产生输出的运行时间太长(N = 25时接近10-15秒)。有没有办法减少运行时间??

function [a,x,t] = square1(N)

j = 0 + i;
L = -N:N;
%a = zeros(size(k));
t = -7:0.01:7;

%Signal Generation
for k = 1:length(t)
    if( t(k) >= -5 & t(k) <= -3) | (t(k) >= -1 & t(k) <= 1) | (t(k) >=3 & t(k) <= 5)
        x(k) = 1;
    else
        x(k) = 0;
    end
end

subplot(3,1,1);
xlabel('Time');
ylabel('Value');
title('Continuous Periodic Signal');
plot(t,x);

%Fourier Series Coefficient Plot
a = zeros(size(L));
for k = 1:length(L)
    syms time;
    a(k) = 1/4*int(exp(-j*L(k)*2*pi/4 * time),-1,1);
end
subplot(3,1,2);
stem(L,a);
xlabel('Discrete Value');
ylabel('Fourier Values');
title('Fourier Series Coefficient');

%Generation of the original signal 
time_duration = -10:0.01:10;
y = zeros(size(time_duration));
for m = 1:length(time_duration)
    y(m) = sum(a.*exp(j*L*2*pi/4*time_duration(m)))
end
subplot(3,1,3);
plot(time_duration,y);
xlabel('Time');
ylabel('Value');
title('Original Signal Constructed');

0 个答案:

没有答案