Need to create a rectangular pulse train in matlab for given figure below
Afficher commentaires plus anciens

So i need to crete this pulse train in matlab. Also, i need help for how I plot the Fourier Series approximation for this pulse train
Réponses (1)
Gautam
le 7 Fév 2025
Hi Sanat
To calculate the Fourier series coefficients and plot the Fourier series approximation for the pulse waveform
- Define the sawtooth function and its range and period.
- Calculate the Fourier series coefficients (an and bn).
- Create a Fourier series approximation using the calculated coefficients.
- Plot and compare the original function with its Fourier series approximation.
Here's the code that follows this. I have takes the fundamental period and "A" both as 1
% Define the period and the range for x
T = 1; % Period of the periodic function
x = linspace(0, T, 1000); % Range of x values
A =1;
% Define the given piecewise function
f = @(x) (A/2*(x >= 0 & x <T/4) + -A/2*(x>=T/4 & x<3*T/4) + A/2*(x>=3*T/4 & x<=T));
% Number of terms in the Fourier series
N = 50;
% Calculate the Fourier series coefficients (an and bn)
a0 = (1/T) * integral(@(x) f(x), 0, T);
an = zeros(1, N);
bn = zeros(1, N);
for n = 1:N
an(n) = (1/T) * integral(@(x) f(x).*cos(n*pi*x/2), 0, T);
bn(n) = (1/T) * integral(@(x) f(x).*sin(n*pi*x/2), 0, T);
end
% Create the Fourier series approximation
F = a0/2;
for n = 1:N
F = F + an(n) * cos(n*pi*x/2) + bn(n) * sin(n*pi*x/2);
end
% Plot the original function and its Fourier series approximation
figure;
plot(x, F);
xlabel('x');
ylabel('f(x)');
This gives me the following the optupt

Catégories
En savoir plus sur Short-Time Fourier Transform dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!