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

2 visualizaciones (últimos 30 días)
Sanat Varasada
Sanat Varasada el 8 de Sept. de 2016
Respondida: Gautam el 7 de Feb. de 2025 a las 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

Respuestas (1)

Gautam
Gautam el 7 de Feb. de 2025 a las 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

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by