MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

# Thread Subject: double to uint8

 Subject: double to uint8 From: user mat Date: 24 Jan, 2011 08:35:04 Message: 1 of 2 Hello ! I am trying to convert a variable X which is of the value range in between -1 to 1 in double format to the uint8 format, i tried to normalized like this var1=a; % double format value range in between [-1 to 1] % normalize to get the range 0 to 1 var1=(var1-min(min(var1)))./(max(max(var1))-min(min(var1))); % multiply with 255 to get the range in between 0 to 255 var2=(var1.*255); i am plotting spectrum in this way fft=fftshift(fft2(uint8(var1))); S1=log10(1+abs(fft)); figure, imshow(S1,[]); fft=fftshift(fft2(uint8(var2))); S2=log10(1+abs(fft)); figure, imshow(S2,[]); The problem is that . I donot get the exact spectrum for the variable var2 , as it was in the case of var1(i.e before normalization). As i am doing only normalization, so the spectrum before and after normalization should be the same Thanks in advance
 Subject: double to uint8 From: Jan Simon Date: 24 Jan, 2011 13:01:04 Message: 2 of 2 Dear user mat, > var1=(var1-min(min(var1)))./(max(max(var1))-min(min(var1))); > fft=fftshift(fft2(uint8(var1))); > > var2=(var1.*255); > fft=fftshift(fft2(uint8(var2))); UINT8(var1) is a vector of 1s and 0s. UINT8(var2) contains the numbers from 0 to 255. Although both represent the same data, the aliasing effect dominates, or at least strongly influences the result of the FFT. I'd suggest not to use 'fft' as name of a variable, because this shadows a built-in function. Kind regards, Jan

## Tags for this Thread

No tags are associated with this thread.

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.