-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab6_tut2.m
50 lines (39 loc) · 1.37 KB
/
lab6_tut2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% Define the discrete Fourier series coefficients
N = 100; % Number of coefficients
t = linspace(0, 2*pi, N+1); % Time vector
t = t(1:end-1); % Remove the last element to have N points
f = sin(t); % Sampled function values (Example: sine function)
% Compute the discrete Fourier series coefficients
F = fft(f)/N; % Normalize by dividing by the number of points
% Reconstruct the function from the Fourier coefficients
reconstructed_f = ifft(F)*N;
% Use Heaviside function
heaviside_f = heaviside(t - pi); % Heaviside function applied at t = pi
% Multiply Fourier coefficients by Heaviside function
F_heaviside = F .* heaviside_f;
% Reconstruct the function with Heaviside function applied
reconstructed_f_heaviside = ifft(F_heaviside)*N;
% Compute the cumulative sum of the reconstructed function with Heaviside function applied
cumulative_sum = cumsum(reconstructed_f_heaviside);
% Plotting
figure;
subplot(2,2,1);
plot(t, f);
title('Original Function');
xlabel('Time');
ylabel('Amplitude');
subplot(2,2,2);
stem(abs(F));
title('Fourier Coefficients');
xlabel('Frequency');
ylabel('Magnitude');
subplot(2,2,3);
plot(t, reconstructed_f);
title('Reconstructed Function');
xlabel('Time');
ylabel('Amplitude');
subplot(2,2,4);
plot(t, cumulative_sum);
title('Cumulative Sum of Reconstructed Function');
xlabel('Time');
ylabel('Cumulative Sum');