Azzera filtri
Azzera filtri

fourier synthesis program when given ak

10 visualizzazioni (ultimi 30 giorni)
Tucker Creger
Tucker Creger il 25 Set 2016
Risposto: Zhao Wang il 27 Set 2016
I am trying to write a script for this equation:
X(Ts n) = Summation k=-N to N of Ak*e^(j*k*Wo*Ts*N)
the Ak also called C in my code is a separate matrix I have already generated for the function.
Below is the code I have:
function [ output_args ] = fsynt(C, T, Ts)
% C = a column vector of coefficients where N is the largest integer
% The sampling time = Ts
% the fundamental period = T
% Check that T/Ts is an integer
if rem(T,Ts) ~= 0; % then its an integer
disp('T/Ts not an integer');
% Take C and Create CC
B = conj(C(11:-1:2)); %complex conjugate
CC = horzcat(B,C) %combines negative ak and positive ak.
%Create F and multiply with CC
W0=2*pi/T; %omega
%k = -10:1:10;
for n=0:1:2000;% n
for k = -10:1:10
F= CC*exp(1i*k*W0*Ts*n)
I am a bit lost on what to do. When I run with one period of a square wave I get a lot of matrices for F when I do not multiply it with CC in that same nested four loop, and I believe I need all of the matrices as one?
Any help is much appreciated, Thank you.

Risposte (1)

Zhao Wang
Zhao Wang il 27 Set 2016
I understand that you want to compute Fourier synthesis using 'for' loops. The equation that you use to compute matrix 'F' creates a new matrix every time and then overwrites the previously created matrix.
To compute Fourier synthesis, you only need to use one 'for' loop. Because the 'exp' function can take vector 'n' as its input, you can first define the vector 'n' as:
>> n = 0:1:2000;
Then in the 'for' loop of variable 'k', you can use the following equation (based on what you use in the original script):
>> F = F + CC(k)*exp(1i*k*W0*Ts*n);
There is an example that shows how to approximate a square wave through Fourier synthesis. Refer to the answer provided by Youssef Khmou in the following link:


Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by