傅里叶变换代码matlab
时间: 2023-09-24 20:08:38 浏览: 51
Sure! Here's an example of a MATLAB code for performing Fourier Transform using the built-in function `fft`:
```matlab
% Input signal
t = 0:0.1:10; % time vector
f = 2; % frequency of the input signal
x = sin(2*pi*f*t);
% Perform Fourier Transform
X = fft(x);
% Calculate the corresponding frequencies
Fs = 1/(t(2) - t(1)); % sampling frequency
frequencies = linspace(0, Fs, length(X));
% Plot the magnitude spectrum
figure;
stem(frequencies, abs(X));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum');
```
In this code snippet, we first define the input signal `x` which is a sine wave with a frequency of 2Hz. Then, we use the `fft` function to perform the Fourier Transform and store the result in `X`. We calculate the corresponding frequencies using the sampling frequency `Fs` and plot the magnitude spectrum using the `stem` function.
Note that this is a basic example, and depending on your specific requirements, you may need to modify the code accordingly.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)