📄 example8_3a.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% example8_3a.m - quantized FFT with scaling factors
% (continue from example8_3.m)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute FFT using Q.15 format with scaling
Fscale=qfft('length',M,'radix',2);
Fscale.CoefficientFormat = [16 15];
Fscale.InputFormat = [16 15];
Fscale.MultiplicandFormat = [16 15];
Fscale.OutputFormat = [16 15];
Fscale.ProductFormat = [32 31];
Fscale.SumFormat = [32 31];
% Scaling used
% Fscale.ScaleValues = [1/M 1 1 1 1 1 1];
Fscale.ScaleValues = [0.5 0.5 0.5 0.5 0.5 0.5 0.5];
% Fscale.ScaleValues = [1 1 1 1 1 1 1/M];
% Fscale.ScaleValues = [1 1/M 1 1 1 1 1];
Xscale = fft(Fscale,x);
magXscale= (abs(Xscale)).*M;
phaseXscale=phase(Xscale);
figure(1), hold on;
plot(magXscale,'g');
legend('double precision', 'Q.15','Q.15 with scaling');
figure(2), hold on;
plot(phaseXscale,'g');
legend('double precision', 'Q.15','Q.15 with scaling');
qreport(Fscale);
sum_sq_error_mag_scale=sum((magX-magXscale).^2)
sum_sq_error_phase_scale=sum((phaseX-phaseXscale).^2)
Fsingle=qfft('length',M,'radix',2);
Fsingle.quantizer = {'single'};
Xsingle = fft(Fsingle,x);
% Perform Quantized IFFT...using single precision
[y_ifft,S] = ifft(Fsingle,Xsingle);
qreport(S);
err = x-real(y_ifft);
figure(7);
plot(0:127,x,'r',0:127,real(y_ifft),':g'); title('Plot between original signal and the recovered signal using IFFT in single precision');
legend('original','IFFT[FFT(x)]');
figure(8);
plot(err); title('Error between original signal and recovered quantized signal');
% Perform Quantized IFFT...using Q.15
Fscale.ScaleValues = [1 1 1 1 1 1 1]; % rescale the scale value back to normal
% Note that no scaling is required in the IFFT as it has already been taken
% care by the IFFT algorithm.
[y_ifft_s,S_s] = ifft(Fscale,Xscale);
qreport(S_s);
y_ifft_s = y_ifft_s.*M; % since IFFT scale the summation by
err_s = x-real(y_ifft_s);
sum_sq_err_s= sum(err_s.^2)
figure(9);
plot(0:127,x,'r',0:127,real(y_ifft_s),':g'); title('Plot between original signal and the recovered signal using IFFT in Q.15');
legend('original','IFFT[FFT(x)]');
figure(10);
plot(err_s); title('Error between original signal and recovered quantized signal');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -