matlab
matlab数据处理
傅里叶变换
fs = 1000;
t = 0:1/fs:1;
f = 50;
x = sin(2*pi*f*t);
X = fft(x);
subplot(2, 1, 1);
plot(t, x);
title('正弦波信号 - 时域');
xlabel('时间 (s)');
ylabel('幅值');
L = length(X);
frequencies = fs*(0:(L/2))/L;
amplitude = abs(X/L);
subplot(2, 1, 2);
stem(frequencies, amplitude(1:L/2+1));
title('正弦波信号 - 频域');
xlabel('频率 (Hz)');
ylabel('振幅');
fs = 1000;
t = 0:1/fs:1;
f = 50;
dutyCycle = 0.5;
x = square(2*pi*f*t, dutyCycle);
X = fft(x);
subplot(2, 1, 1);
plot(t, x);
title('方波信号 - 时域');
xlabel('时间 (s)');
ylabel('幅值');
L = length(X);
frequencies = fs*(0:(L/2))/L;
amplitude = abs(X/L);
subplot(2, 1, 2);
stem(frequencies, amplitude(1:L/2+1));
title('方波信号 - 频域');
xlabel('频率 (Hz)');
ylabel('振幅');
fs = 1000;
t = 0:1/fs:1;
f = 50;
x = sawtooth(2*pi*f*t, 0.5);
X = fft(x);
subplot(2, 1, 1);
plot(t, x);
title('三角波信号 - 时域');
xlabel('时间 (s)');
ylabel('幅值');
L = length(X);
frequencies = fs*(0:(L/2))/L;
amplitude = abs(X/L);
subplot(2, 1, 2);
stem(frequencies, amplitude(1:L/2+1));
title('三角波信号 - 频域');
xlabel('频率 (Hz)');
ylabel('振幅');
fs = 1000;
t = 0:1/fs:1-1/fs;
f1 = 10;
f2 = 50;
x = sin(2*pi*f1*t) + 0.5*sin(2*pi*f2*t);
X = fft(x);
y = ifft(X);
subplot(2,1,1);
plot(t, x);
title('原始信号 - 时域');
xlabel('时间 (s)');
ylabel('幅值');
subplot(2,1,2);
plot(t, y);
title('逆变换后的信号 - 时域');
xlabel('时间 (s)');
ylabel('幅值');
figure;
frequencies = fs*(0:length(X)-1)/length(X);
plot(frequencies, abs(X));
title('信号的频谱');
xlabel('频率 (Hz)');
ylabel('振幅');