bpsk image modulaton

6 views (last 30 days)
ahmed alshammari
ahmed alshammari on 27 Feb 2012
Answered: Tasos Giannoulis on 27 Jan 2017
Hi I am trying to use bpsk to transmitt an image in a problem I am working on but I have a problem with reshaping the image back.
my code
clear all close all imag = imread('saina.jpg');
img= imag(:,:,:);
[z zz t] = size( img);
bin = dec2bin(img, 8); [z zz t] = size( img);
bin = dec2bin(img, 8); %de2bi()has lower resolution%
[s ss] = size(bin);
sigg = reshape( bin', 1,s*ss );
sig = str2num(sigg'); % if no transpose then sig will be Inf%
M = modem.pskmod(2);
sig1 = modulate(M,sig);
l=length(sig1);
z=modem.pskdemod(2); %demodulation object
kr= demodulate(z,sig); %demodulating the data kr1 = (sig+1)/2;
newrsig = reshape(kr', ss , s);
newrsigg= newrsig';
final = bin2dec ( num2str(newrsigg) );
final = reshape ( final', z ,zz , t);
figure, imshow (uint8(final(:,:,:))) ,
after running this code i get the following error messge
??? Error using ==> reshape Conversion to double from modem.pskdemod is not possible.
Error in ==> Untitled4 at 41 final = reshape ( final', z ,zz , t);

Answers (1)

Tasos Giannoulis
Tasos Giannoulis on 27 Jan 2017
The problem is that you store the image dimensions in a variable called 'z', but then you overwrite this variable 'z' with the demodulator object (modem.pskdemod). Therefore in the RESHAPE call you do not provide your desired dimensions (that were originally stored in 'z'); instead you pass the demodulator object.
The solution is to use a different variable name. Also a good practice would be to use variable names that do not conflict with existing functions (e.g., 'imag').

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!