Тёмный

How to do a fast Fourier transform (fft) in MATLAB to calculate the spectrum of data from a mat file 

Mathias Magdowski
Подписаться 2,5 тыс.
Просмотров 29 тыс.
50% 1

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 97   
@user-bg6og7kh8y
@user-bg6og7kh8y 2 года назад
Yank you so much for you Code , that helps ma a lot expecially for the people lacking of coding experiences.🥰
@MathiasMagdowski
@MathiasMagdowski 2 года назад
You are welcome, I' glad that you found the video useful.
@MathiasMagdowski
@MathiasMagdowski Год назад
Here is another question, which I will reproduce here: "Can we do the FFT of a three-axis accelerometer? I am new to MATLAB and engineering. I have the data but I am really confused even after checking the internet. From your example, there is a column for time t, but in my data, there is no t but only x, y and z data." Here is my answer: There is a specific video about accelerometer data. You can find it here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-U0qcDyM6e6w.html If you have no time values given, but if your accelerometer data is sampled at equidistant time steps (called t_step in a time unit like second) using a specific sampling frequency (called f_sample in a frequency unit like hertz, where t_step = 1/f_sample or f_sample=1/t_step), you can create the time vector t yourself. First variant, where t_max is the maximum time of your sampling period: t=0:t_step:t_max; Second variant, where N_steps is the number of time steps or sampling points: t=linspace(0,(N_steps-1)*t_step,N_steps);
@chihieule156
@chihieule156 28 дней назад
Dear Sir, I would like to apply 2D FFT to discrete the airgap magnetic force density in spatial harmonic and temporal harmonic, my target is to get the dominant harmonics of that force. Could you give me some advice about the 2D FFT please
@MathiasMagdowski
@MathiasMagdowski 28 дней назад
@@chihieule156 Thanks for your inquiry. What did you measure in time domain? Do you have two-dimensional data there are well, e.g. the (magnetic) force as a function of time and position?
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Here is another student question that reached me by e-mail, which I will reproduce here: "I had seen your video downloaded fourier.m function. I then applied it to my measurement data for a project. However, when I evaluated it, I was a bit confused because the DC component seemed too high. A test showed that the DC component in the spectrum is shown twice as large as it actually is. In the case of the example, the sine is shifted by 2, but in the spectrum at a frequency of 0, a DC component of 4 is displayed. If you have a moment, I would be glad if you could take a look at it. Here is my test code:" x=linspace(0,2*pi,400); y=10*sin(3*x)+2; figure plot(x, y) [f,X_f]=fourier(x,y, 'sinus'); figure plot(f, abs(X_f))
@MathiasMagdowski
@MathiasMagdowski 2 года назад
And here is my answer: Thanks for asking. This is not a bug, it is a feature. "See also: en.wikipedia.org/wiki/Fourier_series#Common_forms The FFT calculates the double DC component a_0. The factor 2 is then considered as a divisor under a_0 in the formula. The DC component is then a_0/2. PS: The FFT becomes clearly better, if one omits the last point in the definition range and the sine function has then no jump when "putting the values one behind the other". See my version of the script:" x=linspace(0,2*pi,400); % remove last value x=x(1:end-1); y=10*sin(3*x)+2; figure plot(x,y) [f,X_f]=fourier(x,y,'sinus'); figure plot(f,abs(X_f))
@giulianosalerno1203
@giulianosalerno1203 6 месяцев назад
Great function!Could you do something like this to calculate the psd?
@MathiasMagdowski
@MathiasMagdowski 6 месяцев назад
Thanks for your question. By 'psd', you mean the 'power spectral density' (see: en.wikipedia.org/wiki/Spectral_density#Power_spectral_density), right? Maybe I could also record a video for this. To be honest, I have never really used the power spectral density before. Nevertheless, there are existing MATLAB functions readily available for this, see: de.mathworks.com/help/signal/ug/spectral-analysis.html
@giulianosalerno1203
@giulianosalerno1203 6 месяцев назад
@@MathiasMagdowski Hopefully you had already worked with power spectral density (PSD). If you make a video on this it will certainly clarify. Thank you!
@MathiasMagdowski
@MathiasMagdowski 6 месяцев назад
​@@giulianosalerno1203Maybe, but certainly not within the next weeks as I am busy with conferences, international teaching exchange programs and distinguished lecturer talks.
@louispasnik5976
@louispasnik5976 18 дней назад
Thank you for the awesome video and fourier file. I notice the fft function used only takes the signal input = x, that is fft(x). Can you kindly explain when I would want to use fft(x, n) ? I understand if the n is specified, then the fft pads the input sequence with zeros if it is shorter than n, or truncates the sequence if it is longer than n. If n is not specified, it defaults to the length of the input sequence. Can you kindly explain why I would want to ever use fft(x, n) instead of fft(x)? How should one choose n? And, how can this influence results whether I use fft(x) or fft(x,n). I am mainly interested in low frequency signals. Thank you!
@MathiasMagdowski
@MathiasMagdowski 18 дней назад
Thanks for your great question. The idea of specifying this additional number n as an optional argument to the fft function has something to do with how the fft works. In general, the Fourier transform is an integral transform. MATLAB is numerical software, so it deals with discrete sampled data. An integral over discrete sampled data becomes a sum, and an analytic Fourier transform becomes a discrete Fourier transform, or DFT. However, the sum within this DFT is quite expensive to compute, especially for large numbers of samples. This was especially a problem in earlier decades when computers were not that fast. Of course, mathematicians and engineers solved the problem and invented the Fast Fourier Transform, or FFT, which is essentially a DFT but uses a special and very fast algorithm to compute it. However, this fast algorithm only works when the number of samples is a power of 2, so you would normally choose n to be a power of 2. With computers 15 or 20 years ago, it would really make a difference if you did the DFT of 1000 samples or an FFT of 1024 samples. Today, you would not notice the difference in computation time, unless - you have really many samples (billions) - you have a slow computer (e.g. only a microcontroller) - you are trying to calculate many spectra in a short time. In this case, it might help to just cut some of the data or fill in additional zeros to get to the nearest power-of-2 number of samples. I hope this answers your question.
@louispasnik5976
@louispasnik5976 18 дней назад
@@MathiasMagdowski Thank you for your quick response. As I understand from the Matlab documentation on fft(x,n): "If n is not specified, it defaults to the length of the input sequence". If this is true, then the length(x) is likely NOT a power of 2. It is not clear to me if the Matlab fft(x) function internally calculates the closest nextpow2 closest to the length(x) when n is not specified. Should this concern me or might it influence the results if n is not specified as a power of 2? Sometimes very different results are obtained based on the choice of n. For example, fft(x,512) may look different than fft(x,16384), or even if arbitrary values are used such as fft(x,12345). Is this because the dataset is truncated (or zeros added) thus results are expected to be different? Which is the best practice?: - not specifying n and let Matlab default to the length of the input sequence, or - specifying n as close to the nextpow2 as length(x) Thanks again!
@MathiasMagdowski
@MathiasMagdowski 17 дней назад
@@louispasnik5976 Thank you for your further inquiry. If you leave n empty and the length of the input vector is not a power of 2, MATLAB will compute a general discrete Fourier transform that will give you the desired spectrum as a result, but the computation itself will not be "fast". In any case, MATLAB's fft function will NOT truncate or expand your input data to the closest length that is a power of 2. If you don't care about the speed or efficiency of your calculation, don't worry about n and just leave it as is. If you care about speed (because you have a huge vector, a very slow computer like a microcontroller, or if you are calculating many fft functions within a loop), try truncating or zero-padding your data to a length that is a power of 2. When you truncate data, you are of course losing data. If you zero-pad, you do not lose any information, but you still change your time function somehow, because it is no longer clear whether the function value is zero on purpose or just because of the padding. If you care about the speed or efficiency of your calculation, and if you have some control over the length of the input data (e.g., by setting a certain time step in a transient simulation, or by setting a certain sampling rate in a measurement), try to get something as close to a power of 2 as possible, so that you have to truncate or pad as few samples as possible. Of course, depending on x, you might get very different results for n set to 512, 16384, or something else, because many samples might be truncated and discarded, or added as zeros.
@louispasnik5976
@louispasnik5976 17 дней назад
@@MathiasMagdowski Thank you, Professor!
@MathiasMagdowski
@MathiasMagdowski 17 дней назад
@@louispasnik5976 You are welcome.
@giulianosalerno1203
@giulianosalerno1203 6 месяцев назад
Could you please clarify better the difference in the FFT measurement unit in the "pulse" or "sinus" case?
@MathiasMagdowski
@MathiasMagdowski 6 месяцев назад
Thanks for your inquiry. The difference between the two modes 'pulse' and 'sinus' for the fourier.m function is also quite well documented within the source code of the function itself. The purpose of the 'pulse' is to calculate the Fourier transform of a single, non-repetitive pulse or an impulsive signal. In contrast, the idea of the 'sinus' mode is to calculate the Fourier transform of a continuous, repetitive signal like a pulse train. The 'pulse' mode corresponds to the common Fourier transform (en.wikipedia.org/wiki/Fourier_transform) whose result is a continous frequency spectrum or a density spectrum. If the time-domain function has for the example the unit V (volt), the density spectrum will have the unit V/Hz (volt per hertz). In contrast, the 'sinus' mode corresponds to the Fourier series (en.wikipedia.org/wiki/Fourier_series) whose result is a discrete frequency spectrum. Correspondingly, this spectrum will also have the unit V if the time function has the unit V. The main difference between the two modes inside the function 'fourier.m' is that a different scaling or renormalization of the amplitude is used.
@aaroof1361
@aaroof1361 Год назад
Hello Prof, Thank you for this wonderful tutorial. I try to plot the fourier spectrum of my data using your code but I receive this feedback as error: 'Check for incorrect argument data type or missing argument in call to function 'fourier''. What could possibly be the reason? I used this syntax: [f,s_f]=fourier(t,s,'sinus'); A quick reply is much appreciated. Thank you
@MathiasMagdowski
@MathiasMagdowski Год назад
If you obtain an error message stating that the argument data type is incorrect or the argument is missing, you should check if both if your argument variables t and s exist and what their data type is. You should be able to locate these variables in the MATLAB workspace and see their data type there. The data type should be a plain double-precision vector or array, not a cell array, table or something like this.
@aaroof1361
@aaroof1361 Год назад
@@MathiasMagdowski thanks for your prompt reply. I figured it out. It had to do with way I loaded my data. I tweaked it a bit and everything was fine. Thank you very much 😊
@masoncondren4488
@masoncondren4488 2 года назад
I was able to complete the transformation, but it is giving me 500 Hz as the max in the FFT data when I gathered at a frequency of 2000 Hz and a max of 250 Hz when I gathered at a frequency of 1000 Hz. Is this accurate or do I need to adjust the coding? I figured out my problem, my timestep did not begin at 0, changing that fixed the calculations.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Okay, very good. Here is a simple MATLAB code example that shows that for e.g. 2000 Hz sampling frequency, the highest frequency in the spectrum corresponds to 1000 Hz, just like one would expect due to the Nyquist-Shannon sampling theorem (en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem): f_sample=2e3 f_signal=100 t_step=1/f_sample T_period=1/f_signal t=0:t_step:T_period-t_step x_t=5*cos(2*pi*f_signal*t) figure(1) plot(t,x_t) xlabel('time in s') ylabel('signal') [f,X_f]=fourier(t,x_t,'sinus') figure(2) plot(f,abs(X_f)) xlabel('frequency in Hz') ylabel('amplitude spectrum')
@sandeepvinnakota1552
@sandeepvinnakota1552 Год назад
hello professor, Greetings of the day! " I want to do the FFT analysis for the data which is generated by simulation software that contains two columns (time steps with a difference of 0.00625 )in the first column and the no.of particles at the particular time step in the second column. in the simulation, the flow is at a frequency. I want to visualize whether the particles are following the same path of flow. so I want to see the dominant frequency using FFT. will that be possible?"
@sandeepvinnakota1552
@sandeepvinnakota1552 Год назад
i can provide you more details with the generated data if needed.
@MathiasMagdowski
@MathiasMagdowski Год назад
@@sandeepvinnakota1552 Thanks for your inquiry and sorry for the delay in communication, but I was on vacation and on business travel. If you have a time-dependent function, e.g. the number of particles as a function of time, you can apply the Fourier transform and get the corresponding spectrum of this time function. This will allow you to analyse the frequency-dependent behavior of this process. For example, you may also observe dominant frequencies, if they exist. In contrast, I assume that it might be difficult to analyse, whether the particles are following a similar path, if this question is not already answered in your time-domain data. If you like, you may send me your well-described data set and your well-document MATLAB code to mathias.magdowski@ovgu.de and I might have a look.
@ahmedbadawy9520
@ahmedbadawy9520 Год назад
I have an array of time but it’s not uniform. So according to the requirements it must be equidistant.How can I make them equidistant? And if I do so wouldn’t I get less points
@ahmedbadawy9520
@ahmedbadawy9520 Год назад
Can I use linespace(start, end, no of points)?
@MathiasMagdowski
@MathiasMagdowski Год назад
If the timesteps are not equidistant, you need to interpolate them to equidistant time steps, e.g. using the interp1 function built into MATLAB, see: www.mathworks.com/help/matlab/ref/interp1.html You don't lose points or drastically lower the accuracy, if the equidistant (or uniform) time step of the interpolated time function is in the same range as the smallest time step of your non-uniform time steps. The linspace function is indeed useful to create equidistant time steps: t_uniform=linspace(0,t_end,N_steps); You can then interpolate your time function values: x_t_uniform=interp1(t_nonuniform,x_t_nonuniform,t_uniform); I hope this answers the question.
@ahmedbadawy9520
@ahmedbadawy9520 Год назад
Thank you for your quick response. I tried to get the equidistant time step using the linspace() with start and end time but when I checked with plot(diff(time)) I didn’t get a line. I plotted the fft regardless but I am not sure the output (frequencies) is right. Would be great if you can have a look at my data.
@MathiasMagdowski
@MathiasMagdowski Год назад
@@ahmedbadawy9520 Sure, you may send me your data to my OVGU e-mail address.
@albacabanillaspascual276
@albacabanillaspascual276 Год назад
Hi, i have a 3D data matrx tha contains (channel x time x trials), i have to calculate the power spectrum potential of each trial and each channel. Then i have to calculate de power spectrum of all the trials of each trials. How can i do? Thank you very mucho for your video
@MathiasMagdowski
@MathiasMagdowski Год назад
Sorry for the delayed answer. I would suggest to run a for-loop over the channels and trials to calculate the corresponding spectrum separately. I'm not sure what you mean by the "spectrum of all the trials of each trials". Maybe you can explain this a little further. Is the average over all trials meant there or maybe the corresponding maximum? You may also send me your MATLAB code and some sample data via e-mail to: mathias.magdowski@ovgu.de
@vivienne1592
@vivienne1592 8 месяцев назад
hello, prof, I have a question, I use the functions fourier.m but I can't understand this function, Do you have a video description for it? thank you very much !
@MathiasMagdowski
@MathiasMagdowski 8 месяцев назад
Thanks for the question. I don't have such video (yet), but I could record one for sure. Which part of the function is most unclear? There are also some comments in the fourier.m function. Which of them are difficult to understand?
@vivienne1592
@vivienne1592 8 месяцев назад
hello,prof Thank you for your reply. In the function fourier.m, I have two questions: 1.the first one is " XX(1:N)=2/N*fft(x_t)", I can't understand it , for exemple, when I modify '2' to '2.5' in this sentence, the simulation of the image perfectly coincides with the correct image. 2.the second is " X_f(1:N/2+1)=XX(1:N/2+1)". I can't understand this sentence. Thank you very much. @@MathiasMagdowski
@MathiasMagdowski
@MathiasMagdowski 8 месяцев назад
@@vivienne1592 Thanks for your reply. 1. If you change the factor 2 in the formula XX(1:N)=2/N*fft(x_t) to another value, e.g. 2.5, the shape of the spectrum will of course remain the same, because you change all the values of the array by a common factor. Still, the amplitudes given in the spectrum will not fit to the amplitude of the oscillations in the corresponding time function anymore. 2. The ordering of the frequencies in the output vector of the basic 'fft' function is kind of strange. The first entry in the spectrum obtained by the 'fft' function refers to the doubled constant part of the transient signal. It is followed by the positive frequencies in ascending order up the the highest frequency. Then, there are the negative frequencies in descending order. Negative frequencies only make sense for complex-valued time functions, which usually have no physical meaning in the engineering sciences. For real-valued time functions, the spectrum of the negative frequencies is the complex conjugate of the spectrum of the positive frequencies. Therefore, the negative frequencies can be omitted, as they are redundant and do not contain any relevant information in that case. Exactly this is done by the statement X_f(1:N/2+1)=XX(1:N/2+1). If I have time tomorrow, I might record a corresponding video with an explanation.
@MathiasMagdowski
@MathiasMagdowski 8 месяцев назад
The requested video is now finished: "How to scale the result of the fft (fast Fourier transform) and how does fourier.m work in MATLAB?" ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hAbsoXaZ144.html
@vivienne1592
@vivienne1592 8 месяцев назад
Thank you very much! For 1, I can't understand, how to explain....my prof simulate the spectum with his script and I simulate the spectum with your script and my data.I known 2/N is a formula for normalisation... If I do not change the factor 2, the amplitude always different but I don't know if changing the factor from 2 to 2.5 is the correct or not, because in my simulation with the factor 2.5, my result plots and plots of my prof are completely consistent. @@MathiasMagdowski
@sherifkhairy2879
@sherifkhairy2879 Год назад
i want to writ a code for fft with 60 hz fundamental frequency to get the abs and angle in degree for further electrical calculation , in other words i want to build a code just as the fft simulink block that take the voltage or current signal and convert them for further impedance calculation. i hope you understand my question, thanks in advance
@MathiasMagdowski
@MathiasMagdowski Год назад
Thanks for your question. Your task should not be too difficult to solve. If you want to get the amplitude and phase of the spectral component or fundamental frequency of your signal at a frequency of 60 Hz, your need to sample your time-domain signal with a sample rate of at least twice of this, so 120 Hz, but better with the 10-fold or even 100-fold of this frequency, so 600 Hz to 6000 kHz (corresponding to 6000 samples per second). You must also sample for at least one periodic time of this frequency of 60 Hz, so at least for 16.6 ms. Still, is is better to sample longer, up to 10 or even 100 periodic times, so 166.6 ms or even 1.666 s. Then you apply the FFT algorithm as explained in the video using the fourier.m function and just use the 60 Hz-component from the resulting frequency spectrum. I hope this helps. If you have further questions, please let me know. Best regards from Israel.
@sherifkhairy2879
@sherifkhairy2879 Год назад
Thank you, another question , i want to calculate the current and voltage each sample to be able to detect when the disturbance occures for fault analysis, in another word i what to build for loop that calculate the impeadance from current and voltage each sample to monitor the change grahpically from the given rawdata
@MathiasMagdowski
@MathiasMagdowski Год назад
​@@sherifkhairy2879 Thanks for your further inquiry. Impedance is something that is only defined for (complex-valued) phasors of voltage and current, see en.wikipedia.org/wiki/Electrical_impedance Therefore, if you have a time-dependent voltage and time-dependent current function, you need to calculate their respective spectrum first. From the frequency-dependent voltage and current phasors, you can then calculate a frequency-dependent impedance. From this you might monitor some change in the behavior of your system for the detection of some occurence of disturbance or fault analysis.
@hadinaderi7342
@hadinaderi7342 2 года назад
If we have periodic waveforms with different periods and we want to plot their FFT in one diagram, should we consider for each individual waveform only one period data in the time domain?
@hadinaderi7342
@hadinaderi7342 2 года назад
Or this is realised using the introduced function automatically.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
​@@hadinaderi7342 No, this is not done automatically by the provided fourier.m function. In general, for periodic functions (where the periodic time is well known and stable), it is good advice to always use a time range for the input of the FFT that is a multiple of the periodic time. You should keep in mind that the FFT assumes that the input signal always repeats or replicates itself consecutively. Therefore, the last time step of one time period should be omitted for the input so that the first time step of the next virtual replica can directly follow (without introducing a non-existing step, jump or sharp bend). In addition, one should consider that the time step of the time function corresponds to the highest frequency in the spectrum while the time range of the time function corresponds to the frequency step in the spectrum. I hope this helps.
@fluminox13
@fluminox13 8 месяцев назад
Hi, I think they redone the comand, becuase I get the error: Incorrect number or types of inputs or outputs for function fourier. Error in fft_example (line 26) [f,X_f]=fourier(t,x_t,'sinus'); Is there a way to fix this?
@MathiasMagdowski
@MathiasMagdowski 8 месяцев назад
Thanks for your question. Have you also used the fourier.m function from the ZIP file provided via the download link (cloud.ovgu.de/s/yrmZK2BCMW7t6KH) in the video description? This function takes two arguments, the time steps and the corresponding values of the time function. An optional third argument specifies the scaling of the spectrum. If you have another file or function present in your MATLAB workspace that is called fourier.m, this might lead to some confusion.
@fluminox13
@fluminox13 8 месяцев назад
@@MathiasMagdowski yes, First I followed your tutorial with my own numbers and got the error. Than I downloaded your zip from under the video and got the same error. I can try the link you send me now later
@MathiasMagdowski
@MathiasMagdowski 8 месяцев назад
@@fluminox13 Okay, feel free to come back to me at any time.
@xiadu3539
@xiadu3539 2 года назад
Hi, thanks for the tutorial. After the plot, the y value is in dB or in absolute value? And how to plot it in dB vs Frequency? Thank you.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Thanks for your inquiry. After plotting, the y value or amplitude is still an absolute value in linear units, even if plotted on a logarithmic scale. If you want to convert this amplitude into decibels or dB, you need to do this conversion: en.wikipedia.org/wiki/Decibel#Root-power_(field)_quantities Does this answer your question?
@xiadu3539
@xiadu3539 2 года назад
@@MathiasMagdowski Thank you so much for your quick reply. Could you please check if my code is correct as follows? [f_CT,M_CT] = fourier(T,ID_CT_NG,'sinus'); plot(f_CT,20*log(abs(M_CT)),'blue'); Does this work? thank you so much!
@MathiasMagdowski
@MathiasMagdowski 2 года назад
@@xiadu3539 This works not really, as the decibel is defined using the decadic logarithm, i.e. the logarithm with the base of 10. The corresponding function is called log10 and not log in MATLAB.
@Richard-ng2ch
@Richard-ng2ch 2 года назад
Thanks, but I get "Check for incorrect argument data type or missing argument in call to function 'fourier'." error for the [f,X_f] line
@Richard-ng2ch
@Richard-ng2ch 2 года назад
Edit, Oh I am a beginner and didn't realise I had to put the source code files into the same folder as the written program. All sorted now, thank you very much! This has worked much better than the other fft tutorials, and also I am fft'ng a pulse signal so could use the pulse option, happy! :-)
@MathiasMagdowski
@MathiasMagdowski 2 года назад
@@Richard-ng2ch No problem, you are welcome.
@tsehayenegash8394
@tsehayenegash8394 2 года назад
I have time series data and I did the program like this: 1. Temp=xlsread('Addis_Ababa_wholeRS.xlsx',4); 2. Height=Temp(:,1); 3. Temperature=Temp(:,2:end); 4. m=Temperature; 5. N=length(m); 6. fs=1; % sampling frequency 7. subplot(2,1,1) 8. plot(Temperature) 9. title('\bf Temp Variation over Addis Ababa station during 2006 - 2020 at 2 (Km)') 10. ylabel('Amplitude') 11. xlabel('Month') 12. mf=fft(m); % fast Fourier transform 13. ps=abs(mf).^2; % power spectrum density 14. fa=(0:N/2).*(fs/N); % analysis frequency 15. subplot(2,1,2) 16. plot(fa,ps(1:length(fa))) 17. title('\bf Temp Peaks for Addis Ababa station during 2006 - 2020 at 2 (Km)') 19. ylabel('Power Spectrum') 20.xlabel('Frequency') What I need your help is how can I plot anlyze frequency vs amplitude meaning instead of this plot(fa,ps(1:length(fa))) to plot(fa, aAmplitude). Thank you.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Dear Tsehaye Negash, thanks for your further inquiry. There are some issues: 1. As I don't have your Microsoft Excel file "Addis_Ababa_wholeRS.xlsx", I cannot check your proposed MATLAB code. You may send it to me via mathias.magdowski@ovgu.de 2. Why do you not use the provided functions fourier.m and invfourier.m from cloud.ovgu.de/s/yrmZK2BCMW7t6KH, but try to use the more basic fft and ifft functions, where you have to take care about the frequency and time steps and the renormalization of the amplitudes yourself? Why make it difficult, if it can also be easy? 3. I don't really get your question? What shall the variable 'aAmplitude' mean or include? 4. Typically, one would like to plot amplitude vs. frequency, so the frequency on the x-axis or abscisssa and the amplitude on the y-axis or ordinate. Do you really want to plot the 'frequency vs amplitude'?
@masoncondren4488
@masoncondren4488 2 года назад
Thank you so much for the help! Is there anyway I could reference your coding for a research paper I am writing?
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Each reference should have an author (Magdowski, Mathias), a title ("How to do a fast Fourier transform (fft) in MATLAB to calculate the spectrum of data from a mat file"), a year of publication (2021) and a way how to access it, e.g. a URL (ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kUKqrd-lZBk.html or cloud.ovgu.de/s/yrmZK2BCMW7t6KH or ru-vid.com). I think this should be okay.
@hariskhan485
@hariskhan485 Месяц назад
Can you do it for stock market prices.
@MathiasMagdowski
@MathiasMagdowski Месяц назад
@@hariskhan485 Sure, you can do a Fourier transform for almost any time function, so also for market prices as function of time. The question is rather about the purpose of such analysis. As stock market prices behave rather random from my point of view, it will be difficult to perform an extrapolation or prediction for the future.
@jasonzimmermann9860
@jasonzimmermann9860 2 года назад
Hello and Thank you for the Tutorial! After using the fourier command, there come the error Message „Check for missing Argument or incorrect Argument data type in call to function ‚fourier‘. Do i Need a Special Tool Box or what can i do for activate this matlab command? Thank you very much!
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Dear Jason, thanks for your inquiry. You can find the corresponding fourier.m function in a ZIP file, which is linked in the video description: cloud.ovgu.de/s/yrmZK2BCMW7t6KH Does this help and answer your question?
@jasonzimmermann9860
@jasonzimmermann9860 2 года назад
Dear Mr. Dr. Magdowski, thank you very much for the fast respond it was helpful! With best regards Jason
@MathiasMagdowski
@MathiasMagdowski 2 года назад
@@jasonzimmermann9860 You are welcome.
@mandarkadwekar6327
@mandarkadwekar6327 2 года назад
Hello, I am currently doing PIV analysis and would like your help plotting velocity at certain point over the time I have a mat file with generated data from cross correlation. I am not able to code fft for this purpose no matter how hard I think.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Thanks for your question. As far as I understand your problem of particle image velocimetry (en.wikipedia.org/wiki/Particle_image_velocimetry), you have pictures with the positions of particles and want to calculate their velocity, which is the time derivative of the position. What do you need a Fourier transform or FFT for? Which frequency spectrum of which signal do you want to calculate?
@mandarkadwekar6327
@mandarkadwekar6327 2 года назад
@@MathiasMagdowski Yes, that is exactly what I meant by PIV. So, I have already processed the images and as a result I have a matrix of velocity values at different point in the picture. I want to use this matrix of velocity component to do a fft and plot it over time for any specific point in the image. I hope I was able to explain my problem properly.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
@@mandarkadwekar6327 Thanks for the clarification. For me, it is still not clear what you would like to achieve. The result of the FFT will be a spectrum, i.e. the amplitudes and phases of sinusoidal signals with different frequencies. So the results of the FFT will be a function of frequency, not of time. If you want to do an FFT analysis and still plot something over time, you need to consider something like a short-time Fourier transform (en.wikipedia.org/wiki/Short-time_Fourier_transform). Nevertheless, there will always be a trade-off between frequency and time resolution.
@mandarkadwekar6327
@mandarkadwekar6327 2 года назад
@@MathiasMagdowski Hello thanks for your reply. Somehow I was confused while applying the code but now it is clear to me. I applied the source code now, but when I plot the function vs frequency graph, I am getting frequency for values that are higher than the maximum value in the original function matrix.
@MathiasMagdowski
@MathiasMagdowski 2 года назад
@@mandarkadwekar6327 Thanks for your further inquiry. I'm glad to hear that the MATLAB code is working for you. Nevertheless, I do not exactly understand your problem. What do you mean by "frequency for values that are higher than the maximum value in the original function matrix"? What is meant by "values", frequency values or amplitude/magnitude values? Again, as the results of the FFT or Fourier transform, you will get amplitudes and phases as a function of frequency, not the "frequency for values". What is further meant be the "original function matrix"? Why is it a matrix and not just a vector?
@jianyuhua
@jianyuhua 2 года назад
why don't you use fft function?
@MathiasMagdowski
@MathiasMagdowski 2 года назад
The 'fft' function (fast Fourier transform or discrete Fourier transform) is used within the 'fourier' function, which works like an API (application programming interface) or a wrapper to the underlying 'fft' function. The problems or issues with the basic 'fft' function are the following: 1. The 'fft' function only takes one argument as input, the values of the time function, and returns one output variable, the values of the spectrum. 2. Therefore, you have to take care about the corresponding time steps and frequency values yourself. The highest frequency corresponds to the shortest time, while the smallest frequency corresponds to the longest time. The 'fourier' function takes care of this. As a second input argument, you input corresponding time (equidistant) steps and get back the corresponding (equidistant) frequencies as a second output vector. 3. The ordering of the frequencies in the output vector of the basic 'fft' function is kind of strange. The first entry in the spectrum obtained by the 'fft' function refers to the doubled constant part of the transient signal. It is followed by the positive frequencies in ascending order up the the highest frequency. Then, there are the negative frequencies in descending order. Negative frequencies only make sense for complex-valued time functions, which usually have no physical meaning in the engineering sciences. For real-valued time functions, the spectrum of the negative frequencies is the complex conjugate of the spectrum of the positive frequencies. Therefore, the negative frequencies can be omitted, as they are redundant and do not contain any relevant information in that case. 4. The amplitude or magnitude of the spectrum calculated by the basic 'fft' function depends on the number of steps or vector length of the given time function. The wrapper provided by the 'fourier' function takes care of this and renormalizes the amplitude for two different cases, periodic functions (like sums of sine and cosine functions, rectangular pulse trains or clock signals) or aperiodic functions (like single pulses).
@kunalreddy434
@kunalreddy434 2 года назад
what can i do if i have timestamp instead of time as a cloumn?
@MathiasMagdowski
@MathiasMagdowski 2 года назад
Thanks for the question. What do you exactly mean by a timestamp? Something like "2022-03-25 21:20:34.56"? If yes, you need to convert the timestamps into a vector of plain time steps with the unit second. Remember that the first time given in this time vector must be zero and that all other time steps must be equidistant. If they are not equidistant, you need to interpolate them to equidistant time steps, e.g. using the interp1 function.
@kunalreddy434
@kunalreddy434 2 года назад
I am not able to figure out how to convert it into a vector of seconds.. you think you could help with that?
@MathiasMagdowski
@MathiasMagdowski 2 года назад
@@kunalreddy434 I can try. Please send me your data file(s) and your current MATLAB code to my e-mail address mathias.magdowski@ovgu.de!
@kunalreddy434
@kunalreddy434 2 года назад
Sure! Thanks a lot
@kunalreddy434
@kunalreddy434 2 года назад
Any luck sir?
Далее
Mark Rober vs Dude Perfect- Ultimate Robot Battle
19:00
Bike Challenge
00:20
Просмотров 23 млн
▼ЮТУБ ВСЁ, Я НА ЗАВОД 🚧⛔
30:49
Просмотров 421 тыс.
Dropping In from the Clouds 🌁
00:17
Просмотров 1 млн
Fourier Transforms FFT in MATLAB | MATLAB Tutorial
24:03
Denoising Data with FFT [Python]
10:03
Просмотров 172 тыс.
Wavelets: a mathematical microscope
34:29
Просмотров 626 тыс.
Denoising Data with FFT [Matlab]
10:34
Просмотров 83 тыс.
Mark Rober vs Dude Perfect- Ultimate Robot Battle
19:00