plot the Fourier-transform of vogeltje

1 次查看(过去 30 天)
I am trying to write the fourier transform for this dataset but I have no idea where to start because I tried and my code isn't working at all.

回答(1 个)

Ashutosh Singh Baghel
Hi Lidia,
I understand you wish to plot fourier transform using function implementation and then calling function over some inputs.
You can start by writing a simple function for some simple expression, for eg 'sum of two numbers'.
Simply uncomment the code snippet below to see the output of the code.
% % define Inputs
% A = 4;
% B = 5;
%
% % call function 'mysum' over the two input arguments
% out = mysum(A,B)
%
% % define function 'mysum'
% function out = mysum(A,B)
% out = A + B;
% end
You can find more details on how to write functions in the link from Mathworks Documentation.
For fourier transform, you can start by plotting fft of a deterministic signal, for eg 'sin' function;
% k, power for number of samples
% changing vale of k will increase/decrease number of sample points due to
% which width of peak is controlled
k = 8;
% N, number of grid points (preferably N=2^k for some integer k)
N = 2^k;
% Ts, scalar of Sample time =
Ts = 1/200;
% t, vector of equidistant sampled time
t = linspace(0,N*Ts,N);
% f, vector of sampled function values 'f(t)'
f = sin(2*pi*20*t);
% % N, number of grid points (preferably N=2^k for some integer k)
[fshift,yshift] = fouriertransform(f,Ts);
% Plot fshift and yshift
plot(fshift,abs(yshift))
% define function for fourier transform
function [fshift,yshift] = fouriertransform(f,Ts)
% fourier transform of f(t)
F = fft(f);
% Sampling frequency
fs = 1/Ts;
% length of input signal
n = length(f);
% row vector of sampled frequencies (0:(N/2-1))*2*pi/T/N
fshift = (-n/2:n/2-1)*(fs/n);
% row vector of sampled Fourier transform 'F(w)'
yshift = fftshift(F);
end
Local functions must always be defined at the bottom of the code.
For more information on how to write and plot 'fourier transform' of signals, refer to the MathWorks Documentation link for fft and fftshift.

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by