matlab - aUnable to find PSNR between an original signal and a reconstructed signal due to matrix dimensions not agreeing -


% ============ % pcm encoding % ============  f = 2;  fs = 20; ts = 1/fs;  fss = 1.e4; tss = 1/fss;  t = 0:tss:2-tss; d = ts/40:ts:2+ts/40;  p = pulstran(t,d,'rectpuls',1/(fs*40));  % ================= % analog msg signal % ================= m = sin(2*pi*f*t)+1.1;  % ================= % sampled signal % ================= ms = m.*p;  % ================= % quantized msg % ================= qm = quant(ms,2/16); em = 8*(qm);  % ================= % encoding msg % =================  j = 1; i=1:length(em)     if ((((i>1)&&(em(i)~=em(i-1)))||(i==1))&&(em(i)~=0))         x(j) = em(i)-1;         j=j+1;     end end  z = dec2bin(x,5); z = z'; z = z(:); z = str2num(z);  s = 2*(z')-1;  tb = 2/length(s); fb = 0.5/tb; bl = tb/tss; y = ones(bl,1); bit = 5*y*s; bit = bit(:); bit = bit';                     % polar nrz bit stream  % ============= % pcm de-coding % =============  rb = bit(ceil(tb/(tss)):(tb/tss):length(bit)); rb = (rb+5)/10; l = length(rb);  = 1:l/5     q = rb((5*i)-4:5*i);     q = num2str(q);     x1(i) = bin2dec(q);     e(i) = x1(i)+1; end  e = e/8;  y1 = ones(1,ceil((ts/40)/tss)); y2 = zeros(1,(ts/tss)-length(y1)); y3 = [y1 y2]; y3 = y3';  ms1 = y3*e;                     % sampled signal encoded signal ms1 = ms1(:);  % filtering sampled signal  [n,w] = buttord(f/fss,(f+1)/fss,.6,4); [a,b] = butter(n,w,'low'); rm = filter(a,b,ms1); rm = rm*50;                     % recieved orignal signal  % ================== % plotting signals % ==================  figure(1); subplot(2,1,1) plot(t,m,'b',t,ms,'r'); legend('analog msg','sampled msg') grid; xlabel('t -->'); ylabel('amplitude'); axis([0 2 0 2.25]);  subplot(2,1,2) plot(t,ms,'k',t,qm,'r'); legend('sampled msg','quantized msg') grid; xlabel('t -->'); ylabel('amplitude'); axis([0 2 0 2.25]);  figure(2); subplot(2,1,1) plot(t,em,'b') xlabel('t -->'); ylabel('amplitude'); title('leveled msg'); grid; axis([0 2 -0.5 16.5]);  subplot(2,1,2) plot(t,bit,'k') xlabel('t -->'); ylabel('amplitude'); title('polar nrz encoded'); grid; axis([0 2 -5.25 5.25]);  figure(3);  subplot(2,1,1) plot(t,ms1,'b'); title('recovered sampled msg') grid; xlabel('t -->'); ylabel('amplitude'); axis([0 2 0 2.25]);  subplot(2,1,2) plot(t,rm,'b'); title('recovered analog msg') grid; xlabel('t -->'); ylabel('amplitude'); axis([0 2 0 2.25]); 

m original signal , rm reconstructed signal.

when add code:

mse=sum((rm-m).^2)/length(m); psnr=10*log10(255*255/mse); 

i error on line mse stating "matrix dimensions must agree."

it true rm = 1x200 , m = 1x20000 dimensions indeed not agree not know how resolve issue. new matlab , i'm not sure of possible ways code working.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -