求解一个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变换”一栏中,讲了一个例子: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程序.](/uploads/image/z/2639257-25-7.jpg?t=%E6%B1%82%E8%A7%A3%E4%B8%80%E4%B8%AAMATLAB%E7%9A%84%E6%9C%89%E5%85%B3%E5%82%85%E9%87%8C%E5%8F%B6%E5%8F%98%E6%8D%A2%E3%80%81FFT%E5%87%BD%E6%95%B0%E7%9A%84%E9%97%AE%E9%A2%98%2C%E6%B1%82%E5%85%B7%E4%BD%93%E7%9A%84MATLAB%E7%A8%8B%E5%BA%8F.)
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;
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;