How to reconstruct a square signal by determining the Complex Fourier Coefficients and using those N coefficients in exponential form?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to determine the Fourier Series Complex Coefficients of the signal x(t), based on the below formula and to plot the amplitude spectre.

Also, I want to rebuild the initial signal using the determined Fourier Coefficients, and I want to plot on the same graph the initial signal and the rebuild one so that I can compare them. Unfortunately, haven't got the expecte results. Formula for the rebuilt signal:

%My code:
%Type of signal: square
T = 40; %Period of the signal [s]
F=1/T; % fr
D = 23; % length of signal(duration)
dt=(D/T)*100;
N = 50; %Number of coefficients
w0 = 2*pi/T; %signal pulse
t1= 0:0.002:T; % original signal sampling
x1 = square((2*pi*F)*(t1),dt);%initial square signal
t2= 0:0.002:D; %modified signal sampling
x2 = zeros(1,length(t2)); %initializing the modified signal with null values.
dif=T-D;
x2(t1<=D)=x1(t1<=D);% modify the null values with values from the original signal.
x2(1,dif:D)=x2(1,dif:D); %modify for values of t1>=T-D.
x2(t1>=T-D)=x1;
subplot(2,1,1)
plot(t2,x2),title('x(t)+ reconstructed signal)');
hold on
for k = -N:N %k represents the variable after which the sum is achieved
x3 = x1; %x3 represents the signal obtained after the Fourier Series formula;
x3 = x3 .* exp(-1i*k*w0*t1);
X(k+N+1) = 0; %initialise with null value
end
for i = 1:length(t1)-1
X(k+N+1) = X(k+N+1) + (t1(i+1)-t1(i)) * (x3(i)+x3(i+1))/2; %reconstruction using the coefficients
end
for i = 1:length(t1)
x_rec(i) = 0; %initialise with null value
% x_rec is the reconstructed signal using N Coefficients
end
for k=-N:N
x_rec(i) = x_rec(i) + (1/T) * X(k+51) * exp(1i*k*w0*t1(i)); %reconstruction using the coefficients ( the integral being calculated as a sum)
end
plot( t1, x_rec, '--')
subplot(2,1,2)
w=-50*w0:w0:50*w0; %w is the vector which allows displaying the spectre of the function
stem(w/(2*pi),abs(X));
My result:

0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!