作业帮 > 综合 > 作业

求解一个MATLAB的有关傅里叶变换、FFT函数的问题,求具体的MATLAB程序.

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/06/28 17:24:33
求解一个MATLAB的有关傅里叶变换、FFT函数的问题,求具体的MATLAB程序.
在百度百科词条“傅里叶变换”中,“MATLAB变换”一栏中,讲了一个例子:S=2+3*cos(2*pi*50*t-pi*30/180)+1.5*cos(2*pi*75*t+pi*90/180).以256Hz的采样率对这个信号进行采样,总共采样256点.最后得到结果在第1点、第51点、和第76点附近有比较大的值.我自己编的程序:
Fs = 256; % 采样频率
T = 1/Fs; % 采样时间
L = 256; % 总的采样点数
t = (0:L-1)*T; % 时间序列(时间轴)
S=2+3*cos(2*pi*50*t-pi*30/180)+1.5*cos(2*pi*75*t+pi*90/180);
aa=fft(S,256);
但很遗憾,结果与文中的不符,第1点、第51点、和第76点并不是最大.求神人解答,给出正确的MATLAB程序.
求解一个MATLAB的有关傅里叶变换、FFT函数的问题,求具体的MATLAB程序.
function test
Fs = 256; % 采样频率
T = 1/Fs; % 采样时间
t = (0:Fs-1)*T; % 时间序列(时间轴)
S=2+3*cos(2*pi*50*t-pi*30/180)+1.5*cos(2*pi*75*t+pi*90/180);
f= Fs*linspace(0,1,Fs);
Y=2*abs(fft(S,Fs)/Fs); %得到正确的峰值
plot(f,Y)
再问: 你好,想再问下f= Fs*linspace(0,1,Fs);为什么要加这行命令?
再答: 重写了一下, 这个版本更好一点. function myFFT %Dummy input signal %S=2+3*cos(2*pi*50*t-pi*30/180)+1.5*cos(2*pi*75*t+pi*90/180) L = 2048; %sampling data mesh Fs = 256; % sampling frequency T = 1/Fs; % sampling time t = (0:L-1)*T; % time series S=2+3*cos(2*pi*50*t-pi*30/180)+1.5*cos(2*pi*75*t+pi*90/180); %plot(t,S) % Corresponding the data points to frequencies. % use L/2+1 to ignore the symmetric part. f= Fs/2*linspace(0,1,L/2+1); % Due to FFT intensity is scales with the data mesh, therefore here should % times 2/N to get correct intensities. % use abs() because of the imaginary part. Y=2*fft(S,L)/L; plot(f,abs(Y(1:L/2+1)), '-k') hold on;