フィルターのクリア

Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar.

33 ビュー (過去 30 日間)
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

採用された回答

Star Strider
Star Strider 2014 年 11 月 30 日
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 件のコメント
alladin
alladin 2014 年 11 月 30 日
Thank you for your help; however, I'm trying to implement 1 dimensional dft here without using matlab built-in functions. can you please help me resolve the issue?
Star Strider
Star Strider 2014 年 11 月 30 日
編集済み: Star Strider 2014 年 11 月 30 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Guillaume
Guillaume 2014 年 11 月 30 日
編集済み: Guillaume 2014 年 11 月 30 日
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 件のコメント
Guillaume
Guillaume 2014 年 11 月 30 日
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.
alladin
alladin 2014 年 11 月 30 日
Thank you very much for your help

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by