Need to create a rectangular pulse train in matlab for given figure below

2 vues (au cours des 30 derniers jours)
Sanat Varasada
Sanat Varasada le 8 Sep 2016
Réponse apportée : Gautam le 7 Fév 2025 à 11:07
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
Gautam le 7 Fév 2025 à 11:07
Hi Sanat
To calculate the Fourier series coefficients and plot the Fourier series approximation for the pulse waveform
  1. Define the sawtooth function and its range and period.
  2. Calculate the Fourier series coefficients (an and bn).
  3. Create a Fourier series approximation using the calculated coefficients.
  4. 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 Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by