Matlab没有绘制确切的傅立叶信号 [英] Matlab not plotting the exact fourier signal

查看:167
本文介绍了Matlab没有绘制确切的傅立叶信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Matlab在傅立叶域中绘制一个简单的信号.它没有绘制正确的信号.这是我的代码:

clc;
clear all;
close all;
x=1:0.001:10;
f1=sin(2*pi*10*x);
f2=sin(2*pi*15*x);
f3=sin(2*pi*30*x);
f=f1+f2+f3;
plot(2*pi*x,fft(f1));
figure
plot(x,fft(f1));

自从频率为10以来,我一直期望在10处出现一个峰值.但是它在其他点处给出了一个峰值.

这是两个情节图像:

这是plot(x,fft(f1))

的图像

的图像

这是plot(2*pi*x,fft(f1))

的图像

的图像

它没有显示10的峰值.我什至尝试使用abs(fft(f1)).没有运气:/

在傅立叶域中绘制信号不是正确的方法吗?

解决方案

fft函数采用单位时间步长.为了校正非单位时间步长,您需要根据奈奎斯特速率定义频率分量.以下代码以正确的频率轴绘制fft的大小.

clc;
clear all;
close all;
x=1:0.001:10;
%     ^ this is your sampling time step
f1=sin(2*pi*10*x);
f2=sin(2*pi*15*x);
f3=sin(2*pi*30*x);

% bounds of fourier transform based on sampling rate
Fs = 1/0.001;
ff = linspace(-Fs/2,Fs/2,numel(x));

F1 = fftshift(fft(f1)/numel(x));
F2 = fftshift(fft(f2)/numel(x));
F3 = fftshift(fft(f3)/numel(x));

figure();
plot(ff,abs(F1),'-r'); hold on;
plot(ff,abs(F2),'-b');
plot(ff,abs(F3),'-k');

要在评论中回答OP的问题.

以归一化的频率单位讲话(假设采样率为1). fft函数将频率响应从0弧度返回到2*pi弧度,但是由于某些信号处理属性以及执行FFT时解释离散信号的方式,该信号实际上是周期性的,因此pi可以2*pi部分与-pi0部分相同.为了显示以直流分量(频率为0)为中心的曲线,我们使用fftshift,该圆周移动等于fft返回的数据上信号长度的1/2.拿ifft之前,请确保使用ifftshift将其放回正确的位置.

Edit2:归一化项(/numel(x))对于使用离散傅立叶变换估计连续时间傅立叶变换是必需的.我不记得确切的数学原因,而是关于MIT OpenCourseWare的讲座.

I'm trying to plot a simple signal in fourier domain using Matlab. It's not plotting the correct signal. Here is my code:

clc;
clear all;
close all;
x=1:0.001:10;
f1=sin(2*pi*10*x);
f2=sin(2*pi*15*x);
f3=sin(2*pi*30*x);
f=f1+f2+f3;
plot(2*pi*x,fft(f1));
figure
plot(x,fft(f1));

I've expected a peak at 10 since the frequency is 10. But it is giving a peak at some other point

Here are the two plot images:

This is the image for plot(x,fft(f1))

This is the image for plot(2*pi*x,fft(f1))

It is not showing the peak at 10.I even tried using abs(fft(f1)). No luck :/

Isn't it the correct way to plot signal in fourier domain?

解决方案

The fft function assumes unit time step. In order to correct for non unit time step you need to define the frequency component based on the nyquist rate. The following code plots the magnitude of the fft with the correct frequency axis.

clc;
clear all;
close all;
x=1:0.001:10;
%     ^ this is your sampling time step
f1=sin(2*pi*10*x);
f2=sin(2*pi*15*x);
f3=sin(2*pi*30*x);

% bounds of fourier transform based on sampling rate
Fs = 1/0.001;
ff = linspace(-Fs/2,Fs/2,numel(x));

F1 = fftshift(fft(f1)/numel(x));
F2 = fftshift(fft(f2)/numel(x));
F3 = fftshift(fft(f3)/numel(x));

figure();
plot(ff,abs(F1),'-r'); hold on;
plot(ff,abs(F2),'-b');
plot(ff,abs(F3),'-k');

Edit: To answer OPs question in the comment.

Speaking in normalized frequency units (assuming sampling rate of 1). The fft function returns the frequency response from 0 to 2*pi radians, but due to some signal processing properties and the way that discrete signals are interpreted when performing an FFT, the signal is actually periodic so the pi to 2*pi section is identical to the -pi to 0 section. To display the plot with the DC component (0 frequency) in the center we use fftshift which does a circular shift equal to 1/2 the length of the signal on the data returned by fft. Before you take the ifft make sure you use ifftshift to put it back in the right place.

Edit2: The normalization term (/numel(x)) is necessary to estimate the continuous time fourier transform using the discrete fourier transform. I don't remember the precise mathematical reason off the top of my head but the examples in the MATLAB documentation also imply the necessity of this normalization.

Edit 3: The original link that I had is down. I may come back to add a more detailed answer but in the mean time I definitely recommend that anyone interested in understanding the relationship between the fundamentals of the FS, FT, DTFT, and DFT watch Professor Oppenheim's hilariously old, but amazingly informative and straightforward lectures on MIT OpenCourseWare.

这篇关于Matlab没有绘制确切的傅立叶信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆