本文的参数变量
信号频率:
本文后续采用Fsign 来表示。
采样频率:
本文后续采用Fsample来表示 必须是Fsign的两倍以上
频率的模:
abs(fft(S)) 也就是 转频率后的 根号下(实数的平方+ 虚数的平方)的绝对值。
频率的幅值:
A=
abs(fft(S))/(N/2)
n点频率= (n-1)*Fsample/2
执行功能:
信号显示:
%step1 clean all window info
clc
clear
close all;
%step2 gener
Fsample =500;
Fsign = 50;%信号1
Tsample =1/Fsample;
L = 42;
t = (0:L-1)*Tsample;
%t2 = (0:Tsample:L-1);
S = sin(pi*Fsign*t);
figure(1)
plot(t,S);
grid on
title('Signal AMP')
xlabel('time (sec)')
figure(2)
plot((0:L-1),S);
grid on
title('Signal AMP')
xlabel('sample')
信号转为频率fft:
%step1 clean all window info
clc
clear
close all;
%step2 gener
Fsample =500;
Fsign = 10;%信号1
Tsample =1/Fsample;
L = 256;
t = (0:L-1)*Tsample;
%t2 = (0:Tsample:L-1);
S = sin(pi*Fsign*t);
figure(1)
plot((0:L-1),S);
grid on
title('Signal AMP')
xlabel('sample')
%step2 fft
NFFT = 2^nextpow2(L); % 1020 =》1024 120=》128
Y = fft(S,FFTN);
f = Fsample/2*linspace(0,1,FFTN/2+1);
A=2*abs(Y(1:FFTN/2+1))/L;
figure(2)
plot(f,A)
grid on
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
时域转换为频率表示幅值。