What is wrong with this code, please help!

4 visualizzazioni (ultimi 30 giorni)
>> t = [0:.1:2*pi]; % Times at which to sample the sine function
sig = sin(t); % Original signal, a sine wave
partition = [-1:.2:1]; % Length 11, to represent 12 intervals
codebook = [-1.2:.2:1]; % Length 12, one entry for each interval
[index,quants] = quantiz(sig,partition,codebook); % Quantize.
plot(t,sig,'x',t,quants,'.')
legend('Original signal','Quantized signal');
axis([-.2 7 -1.2 1.2])
>>
>> M = 4;
>> y = dpskmod(quants,M,pi / 8 ) ;
but i still keep getting the error
??? Error using ==> dpskmod at 41
Elements of input X must be integers in the range [0, M-1].

Risposta accettata

Walter Roberson
Walter Roberson il 13 Mar 2011
Your codebook needs to be 0:3 (the integers) if you want to use M=4. However, you are quantizing into 12 bins that you presumably want to distinguish, and that implies 0:11 for the codebook and M=12.
  4 Commenti
jessica david
jessica david il 14 Mar 2011
thanks Walter, is there some way I can get my original signal from the quantized one?
Walter Roberson
Walter Roberson il 14 Mar 2011
No, just a quantized version.
You quantized at particular locations. Those are, I suspect (but have not looked), hard edges -- anything up to (and maybe equal to) the value gets put in to that bin (if not already in a previous bin.) So to reconstruct, you could take a representative value of each quantization bin (min, max, value at the half-way point, whatever) and put those in an array. Index the array by 1 plus the symbol number (which starts at 0) to get the representative values approximating the signal.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by