Matlab 傅立叶变换 短时傅立叶变换 小波变换

clc;
clear;


%generate signal 
fs = 10; %采样频率
N = 10000;  %数据总长度
n = 0:N-1;
t = n/fs;  %时间序列


for i=1:N
    if t(i)<500
        x(i)=sin(10*t(i));   
    else
        x(i)=sin(20*t(i));
    end   
end
x;
subplot(411)
plot(t,x);
axis([0,1000,-1,1]);


%fourier Transform
y_FFT = fft(x,N);   %对信号快速Fourier变换
mag1 = abs(y_FFT); %Fourier变换后的振幅
f = n*fs/N;  %频率序列
subplot(412)
plot(f,mag1);
axis([0,10,0,3000]);
xlabel('频率/HZ');
ylabel('振幅');
title('Fourier Transform');


%STFT, Hamming windows
h=hanning(N);
[y_STFT,ff,tt,pp] = spectrogram(x,h,100,N,fs);
mag2 = abs(y_STFT);
subplot(413);
n1 = 1:5001;
f1 = n1*fs/N; %频率序列
plot(f1,mag2);
axis([0,10,0,2000]);
xlabel('N');
ylabel('频率/HZ');
title('STFT');


%w

你可能感兴趣的:(其他)