1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| clear all;close;clc;
[x,fm]=audioread("D:/origin.wav"); x=x(:,1); Fs=40e3; x = resample(x,Fs,fm); N=length(x); t=(0:N-1)/Fs; figure(1); subplot(421); plot(t,x); title("原信号音频时域图"); xlabel("t/s"); Y=fft(x,N); df=Fs/length(t); f=t*df; Ys=abs(Y); subplot(422); plot(f.*Fs./1e3,Ys); title("原信号音频频谱图"); xlabel("f/kHz");
i=3; fso=Fs*3/4; fsc=Fs/2; fsu=Fs/4; for n = [3/4, 2, 4] if n==3/4 yso = resample(x,fso,Fs); elseif n==2 ysc = resample(x,fsc,Fs); else ysu = resample(x,fsu,Fs); end subplot(4,2,i); i=i+1; if n==3/4 tso=linspace(t(1),t(end),length(yso)); plot(tso,yso); title("过采样采样信号时域图") xlabel("t/s"); grid on Y=fft(yso,length(yso)); subplot(4,2,i); i=i+1; df=fso/length(tso); fo=tso*df; Ys=abs(Y); plot(fo.*fso./1e3,Ys,'red'); xlabel("f/kHz"); title("过采样音频频谱图"); grid on elseif n==2 tsc=linspace(t(1),t(end),length(ysc)); plot(tsc,ysc); title("临界采样采样信号时域图") xlabel("t/s"); grid on Y=fft(ysc,length(ysc)); subplot(4,2,i); i=i+1; df=fsc/length(tsc); fc=tsc*df; Ys=abs(Y); plot(fc.*fsc./1e3,Ys,'green'); xlabel("f/kHz"); title("临界采样音频频谱图"); grid on elseif n==4 tsu=linspace(t(1),t(end),length(ysu)); plot(tsu,ysu); title("欠采样采样信号时域图") xlabel("t/s"); grid on Y=fft(ysu,length(ysu)); subplot(4,2,i); i=i+1; df=fsu/length(tsu); fu=tsu*df; Ys=abs(Y); plot(fu.*fsu./1e3,Ys,'blue'); xlabel("f/kHz"); title("欠采样音频频谱图"); grid on end end
yo=zeros(1,length(x)); for i = 1 : length(x) a=t(i)-tso; Sa=sinc(fso.*a); g=0; for k = 1:1:length(yso) s = yso(k)*Sa(k); g=g+s; end yo(i) = g; end yc=zeros(1,length(x)); for i = 1 : length(t) b=t(i)-tsc; Sb=sinc(fsc.*b); g=0; for k = 1:1:length(ysc) s = ysc(k)*Sb(k); g=g+s; end yc(i) = g; end yu=zeros(1,length(x)); for i = 1 : length(t) c=t(i)-tsu; Sc=sinc(fsu.*c); g=0; for k = 1:1:length(ysu) s = ysu(k)*Sc(k); g=g+s; end yu(i) = g; end
m=2; figure(2); subplot(421); plot(t,x); title("原信号音频时域图"); xlabel("t/s"); grid on s="原信号音频频谱图"; FFT(x,N,Fs,t,m,s); m=m+2; subplot(423); plot(t,yo); xlabel("t/s") title("过采样恢复信号时域图"); grid on so="过采样信号音频频谱图"; FFT(yo,length(yo),Fs,t,m,so); m=m+2; subplot(425); plot(t,yc); xlabel("t/s") title("临界采样恢复信号时域图"); grid on sc="临界采样信号音频频谱图"; FFT(yc,length(yc),Fs,t,m,sc); m=m+2; subplot(427); plot(t,yu); xlabel("t/s") title("欠采样恢复信号时域图"); grid on su="欠采样信号音频频谱图"; FFT(yu,length(yu),Fs,t,m,su);
name = ["over_sampling.wav","critical_sampling.wav","under_sampling.wav"]; audiowrite(name(1),yo,Fs); audiowrite(name(2),yc,Fs); audiowrite(name(3),yu,Fs);
function FourierTransform = FFT(signal,N,fs,t,m,s) Y=fft(signal,N); df=fs/length(t); f=t*df; Ys=abs(Y); subplot(4,2,m); plot(f.*fs./1e3,Ys); xlabel("f/kHz"); title(s); end
|