Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar.
34 views (last 30 days)
Show older comments
I'm trying to implement a 1 dimensional DFT without using Matlab built-in functions such as fft(). This is my code:
function [Xk] = dft1(xn)
N=length(xn);
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1j*2*pi/N); % Twiddle factor (w)
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = (WNnk*xn );
when i run the code after using the following commands:
I = imread('sample.jpg')
R = dft1(I)
I get this particular error: *Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar. To compute elementwise TIMES, use TIMES (.*) instead.*
Can someone please help me to figure out how to solve this problem
Note: I am still in the very beginning level of learning Matlab. Thank you very much
0 Comments
Accepted Answer
Star Strider
on 30 Nov 2014
To do an FFT you need to start by converting it to grayscale:
I = imread('sample.jpg');
G = double(rgb2gray(I));
Note that to take the FFT of a matrix M, you need to take the FFT of the transpose of the first FFT, that is
FFT(M) = FFT(FFT(M).').'
The dot operator here (.') takes the simple (not complex conjugate) transpose.
2 Comments
Star Strider
on 30 Nov 2014
Edited: Star Strider
on 30 Nov 2014
My pleasure.
I used ‘FFT’ in the generic sense. I haven’t run your code, but it should produce a matrix as output on the first pass, taking the first Fourier transform of ‘G’. You then need to take the simple transpose of that output matrix and do the Fourier transform on it. That output is the Fourier transform of your image.
More Answers (1)
Guillaume
on 30 Nov 2014
Edited: Guillaume
on 30 Nov 2014
Your jpg image is read as integer ( uint8 most likely) and matlab is not that good at manipulating pure integers as per the error message. The simplest way to solve this is to convert the integers to doubles:
I = double(imread('sample.jpg'));
3 Comments
Guillaume
on 30 Nov 2014
It looks like your code assume a square matrix whereas your image is not square.
The reason I say it looks like you assume a square matrix, is because of this line:
N = length(xn);
length returns the size of the largest dimension, and you then use that to build an N*N matrix. If your input is M*N (M<N) you can't multiply it with your Wnk.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!