Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.84 KB | None | 0 0
  1. clear all;
  2. close all;
  3. clc;
  4. re_freq = 1/50; %relative frequency of the signal
  5. len_sig = [0 : 499 ]; %length of the signal
  6. dig_after = [0 : 10]; % No. of Digits after decimal points to be retained
  7. %loop through the different values of q
  8. for num = 1 : length(dig_after)
  9. sgnx = cos(2*pi*re_freq*len_sig); %our signal equation
  10. pw_sig = sum(abs( sgnx ).^2)/length( sgnx ); %calculating the power of the signal
  11. sgnx_q = round(sgnx*10^dig_after(num))/10^dig_after(num); %quantizing the signal
  12. sgnx_err = sgnx - sgnx_q;
  13. %calculating the error between the signals
  14. pw_err = sum(abs(sgnx_err).^2)/length(sgnx_err); %calculating the power of the error signal
  15. SQNR(num) = 10*log10(pw_sig/pw_err); %calculating SQNR
  16. end
  17. figure,
  18. plot(dig_after,SQNR);
  19. xlabel('Significant Digits');
  20. ylabel('SQNR (dB)');
  21. ylabel('SQNR (dB)');
  22. xlim([dig_after(1) dig_after(end)]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement