Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Generate signals from trigonometric

1 vue (au cours des 30 derniers jours)
triet tran
triet tran le 13 Nov 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
te=1e-5;
fe=1/te;
c=3e8;
lambda= c/fe;
time =((-lambda/2):1:(lambda/2))*te;
a = -1*(sign(time)) ;
%rect= 1*[zeros(0,1) ones(1,(lambda/2)-1) zeros(1,1) -ones(1,(lambda/2)-1) zeros(1,1)];
figure(1);
hold on
plot(a, 'k');
xlim([0 lambda]);
set(gca,'XTick',0:lambda/2:lambda);
set(gca,'XTickLabel',{'0','\lambda/2','\lambda'},'Fontsize',11);
xlabel('Lambda \lambda');
ylabel('A');
n=[2 4 6 8 10];
e=0;
for i=1:n
an= (1/lambda)*(integral(a,0,lambda));
bn= (2/lambda)*(a*(integral(sin(2*pi*fe*i*te),0,lambda)));
cn= (2/lambda)*(a*(integral(cos(2*pi*fe*i*te),0,lambda)));
xn=an+bn*sin(2*pi*fe*i*te)+cn*cos(2*pi*fe*i*te);
e=e+xn;
end
figure (2)
plot(e)
Hello,
I have generated a square signal f (z) (code a)
f (z) can be written
In practice, m varies from 1 to n
I want to generate signals according to trigonometric formula. However, my code is not very correct. Can you check for me where am I wrong?
Thank you

Réponses (1)

Alan Stevens
Alan Stevens le 14 Nov 2020
More like this perhaps
lambda= 1000;
dz = 1;
z = 0:dz:lambda;
f = @(z) (z<lambda/2) - (z>lambda/2);
n= 6; %[2 4 6 8 10];
SN = zeros(numel(n),numel(z)); % pre-allocate storage space
CS = zeros(numel(n),numel(z));
A = zeros(1,numel(n));
B = zeros(1,numel(n));
B0 = (1/lambda)*sum(f(z)*dz);
for m=1:n
SN(m,:) = sin(2*pi*m*z/lambda);
CS(m,:) = cos(2*pi*m*z/lambda);
A(m) = (2/lambda)*sum(f(z).*SN(m,:))*dz;
B(m) = (2/lambda)*sum(f(z).*CS(m,:))*dz;
end
F = B0 + A*SN + B*CS;
figure(1);
plot(z,f(z), 'k',z,F),grid;
xlim([0 lambda]);
set(gca,'XTick',0:lambda/2:lambda);
set(gca,'XTickLabel',{'0','\lambda/2','\lambda'},'Fontsize',11);
xlabel('Lambda \lambda');
ylabel('Amplitude');
legend('step','fourier')
  1 commentaire
triet tran
triet tran le 14 Nov 2020
THANK YOU, your code, it's more correct.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by