How to complete the fourier Analysis using Matlab ?

조회 수: 5 (최근 30일)
Megh
Megh 2015년 1월 11일
댓글: Katherine Zheng 2022년 3월 18일
Hello !!
I have tried using the Matlab tutorial for FFT and DFT but I'm having extreme difficulty understanding the code and how I can use it in my question. My experience with matlab is only in data manipulation and plotting, so I'm struggling with the concepts.
So here is the question...
To compute the Cn coefficient given by
  • Cn = 1/T * ∫ f(t)*e^(-2*pi*n*t/T) dt,
in which T is the period, and then Amplitude is
  • sqrt(Re(Cn)^2 + Im(Cn)^2)
  • F = n/T
then... how can I plot Amplitude vs Frequency using matlab functions. So far I have this function and req as mentioned above.
  1. f(t) = e^-t from -3 to 3
  2. T = 6
  3. F = -10:1:10
I would like to plot using matlab, but so far I'm doing integral manually and then just iterating values, and plotting them in matlab, can I use fft function or any other function to speed up the process ??
Many thanks
Megh
  댓글 수: 1
dpb
dpb 2015년 1월 11일
There's a complete example of computing/plotting the one-sided PSD at
doc fft
that should be pretty easy to follow what it's doing.

댓글을 달려면 로그인하십시오.

채택된 답변

Rick Rosson
Rick Rosson 2015년 1월 11일
편집: Rick Rosson 2015년 1월 11일
doc fft
doc fftshift
doc abs
doc angle
doc plot
doc stem
doc xlabel
doc ylabel
doc grid
doc xlim
doc ylim

추가 답변 (2개)

Youssef  Khmou
Youssef Khmou 2015년 1월 11일
Try to study and alter this example :
Fs=10;
t=-3:1/Fs:3;
x=exp(-t);
plot(t,x)
N=1000; % N points for frequency computation
fx=fftshift(fft(x,N))/sqrt(N);
fx=fx.*conj(fx);
% frequency axis
f=(-N/2:N/2-1)*Fs/(2*N);
figure; plot(f,fx);

Megh
Megh 2015년 1월 13일
편집: Megh 2015년 1월 13일
Ughhh I tried using above answers but It felt unsure about lots of operation (Since I have yet to understand many of the FFT properties and theorems) ... Well I chose the following code which I'm more confident about the mathematical operations.
This code works for now, well I still need to figure out the better way.
% clear the memory and workspace
clc, clear, close all
syms t fr
g_t = sin(2*pi*t); % function
T = 10; % period of the function
a = -5; b = 5; % to integrate from a to b
n = -100:1:100; % n is an integer by DEFINATION
freq = n./T;
% Integrate function
f = g_t*exp(-2*pi*fr*i*t);
Cn = 1/T * int(f,t,a,b);
% get the amplitude and phase spectra function
Amp = sqrt(real(Cn)^2 + imag(Cn)^2);
Pha = atan(imag(Cn)/real(Cn));
% Do this to combat datapoints/frequency in which function yields
% infinty or division by zero error, take the limit
% NEED TO FIND BETTER Way
AmpV = zeros(1, length(freq));
for n = 1:length(AmpV)
try AmpV(n) = subs(Amp, 'fr', freq(n));
catch AmpV(n) = limit(Amp, fr, freq(n));
end
end
% Plot the discrete Amplitude spectrum
figure(1)
stem(freq,AmpV)
xlim([-10 10])
xlabel('\bfFrequency in Hz')
ylabel('\bfAmplitude')
title('\bfAmplitude spectra of F_{t}')
Note this image is for function exp(-t)*sin(2*pi*t) from 0 to 5, with T of 10s.
  댓글 수: 1
Katherine Zheng
Katherine Zheng 2022년 3월 18일
I just really appreciate such poster who figure out their issue and give a detailed answer about it!!! Thanks!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by