Fourier representation in for loop

i want to represent the square wave of 8 bit ASCII char 'b' in Fourier, i already derived the coefficients but i don't know why the square wave is not being represented ! plz support asap.
X = [0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8];
Y = [0 0 1 1 1 1 0 0 0 0 0 0 1 1 0 0];
L = 8/2;
n = 1:2:50;
figure(1);
plot (X,Y);
hold on;
grid on;
%x =linspace(0,2,10000);
%x= 1:0.1:2*pi;
%----Fourier-----
a_zero = 3/8;
f = zeros(1,length(Y));
x = ((2 .* (0:length(Y)-1)) + 1)./2;
x = x .* Y;
x = (x .* pi)./L;
%---For Loop ----
for i = 1:length(Y),
for j= 1:length(n)
a_n = (1/pi*j)*(sin((3*pi*j)/4)- sin((pi*j)/4)+sin((7*pi*j)/4)-sin((6*pi*j)/4));
b_n = (1/pi*j)*(cos((pi*j)/4)- cos((3*pi*j)/4)+cos((6*pi*j)/4)-cos((7*pi*j)/4));
f(i) = f(i) + (a_n *cos((j*pi*X(i))/4)) + (b_n*sin((j*pi*X(i))/4));
end
end
fx = f + a_zero;
plot(fx)

Réponses (0)

Catégories

En savoir plus sur Wavelet Toolbox 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!

Translated by