Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- close all;
- clc;
- re_freq = 1/50; %relative frequency of the signal
- len_sig = [0 : 499 ]; %length of the signal
- dig_after = [0 : 10]; % No. of Digits after decimal points to be retained
- %loop through the different values of q
- for num = 1 : length(dig_after)
- sgnx = cos(2*pi*re_freq*len_sig); %our signal equation
- pw_sig = sum(abs( sgnx ).^2)/length( sgnx ); %calculating the power of the signal
- sgnx_q = round(sgnx*10^dig_after(num))/10^dig_after(num); %quantizing the signal
- sgnx_err = sgnx - sgnx_q;
- %calculating the error between the signals
- pw_err = sum(abs(sgnx_err).^2)/length(sgnx_err); %calculating the power of the error signal
- SQNR(num) = 10*log10(pw_sig/pw_err); %calculating SQNR
- end
- figure,
- plot(dig_after,SQNR);
- xlabel('Significant Digits');
- ylabel('SQNR (dB)');
- ylabel('SQNR (dB)');
- xlim([dig_after(1) dig_after(end)]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement