Experiment 1 Use MATLAB to draw sine wave and white noise signals
1. Experimental requirements
(1) Use MATLAB to generate sine wave signals and white noise signals, and display their respective time-domain waveforms; (
2) Perform FFT transformation to display their respective frequency spectrums;
(3) Make the root mean square spectrum and power spectrum of the two signals , and logarithmic root-mean-square spectrum;
(4) use IFFT inverse Fourier transform to restore the signal and display the time-domain waveform.
2. Experiment source program
1. Generate a sine wave signal
%用MATLAB产生正弦波信号
fs =500; %设定采样频率
N =180; %计算向量的N点傅里叶变换
n =0:N-1; %可以看成采样
t = n/fs;
f0 = 18; %设定正弦信号频率
%生成正弦信号
x = sin(2*pi*f0*t);
figure(1);
subplot(221);
plot(t,x); %作正弦信号的时域波形
xlabel('时间/ s');
ylabel('幅值');
title('时域波形','color','red');
grid;
%进行FFT 变换并做频谱图
y = fft(x,N); %进行FFT 变换
mag = abs(y); %求幅值
%进行对应的频率转换,即频率点(x轴的值或说是点的x坐标)
f = (0:length(y) -1)'*fs/ length(y);
subplot(222);
plot(f,mag); %作频谱图
axis([0,100,0,80]);
xlabel('频率/ Hz');
ylabel('幅值');
title('幅频谱图','color','red');
grid;
%求均方根谱
sq = abs(y);
subplot(223);
plot(f,sq);
xlabel('频率/ Hz');
ylabel('均方根谱');
title('均方根谱','color','red');
grid;
%用IFFT 恢复原始信号
xifft = ifft(y);
magx = real(xifft);
ti = [0:length(xifft)-1] / fs;
subplot(224);
plot(ti,magx);
xlabel('时间/ s');
ylabel('幅值');
title('IFFT 后的信号波形','color','red');
grid;
sgtitle('产生正弦波信号','color','black')
2. Generate white noise signal
%****************2.白噪声****************%
fs=35; %设定采样频率
t = -5:0.1:5;
x = rand(1,100);
figure(2);
subplot(221);
plot(t(1:100),x); %作白噪声的时域波形
xlabel('时间(s)');
ylabel('幅值');
title('时域波形','color','red');
grid;
%进行FFT 变换并做频谱图
y = fft(x); %进行FFT 变换
mag = abs(y); %求幅值
%进行对应的频率转换
f = (0:length(y) -1)'*fs/ length(y);
subplot(222);
plot(f,mag); %作频谱图
xlabel('频率/ Hz');
ylabel('幅值');
title('幅频谱图','color','red');
grid;
%求均方根谱
sq = abs(y);
subplot(223);
plot(f,sq);
xlabel('频率/ Hz');
ylabel('均方根谱');
title('均方根谱','color','red');
grid;
%用IFFT 恢复原始信号
xifft = ifft(y);
magx = real(xifft);
ti = [0:length(xifft)-1] / fs;
subplot(224);
plot(ti,magx);
xlabel('时间/ s');
ylabel('幅值');
title('IFFT 后的信号波形','color','red');
grid;
sgtitle('产生白噪声信号')
3. Running results
1. Generate a sine wave signal
2. Generate white noise