matlabfftifft

Difficulty plotting correct IFFT of 2D function from given data


I am trying to read in a 2D data set into a matrix, plot the matrix, as well as plot the IFFT of the matrix. The data is 128x2 data set, with frequency in the first column (A) vs amplitude in the second column (B)

Unfortunately, plotting the matrix of the data is not plotting the correct waveform. Also, the IFFT seems to be incorrect as well.

waves = csvread('10cm.txt');

A = waves(:,1);
B = abs(waves(:,2));

Matrix = [A B];

waves_transform = abs(ifft2(waves));

figure, plot(waves);
figure, plot(waves_transform)

When I read in each column of the data and plot A vs B, the waveform of the data is correct but the ifft2 of the data is incorrect. I need to properly take the inverse Fourier transform of the two dimensional data that I have read in.

waves = csvread('10cm.txt');

A = waves(:,1);
B = abs(waves(:,2));

Matrix = [A B];

waves_transform = abs(ifft2(Matrix));

figure, plot(A,B);
figure, plot(waves_transform)

waves & waves_transform

Does anyone know why reading in the data and plotting it is different than reading in each of the columns and plotting it results in different graphs? Also, can anyone help me take the IFFT of the 2D data correctly?

10cm.txt DATA FILE HERE: http://pastebin.com/0t0TwVvC


Solution

  • According to MATLAB documentation, if you do plot(Y) and Y is a matrix, then the plot function plots the columns of Y versus their row number. The x-axis scale ranges from 1 to the number of rows in Y.

    So, in your case you have to do:

    plot(waves(:,1), waves(:,2))

    Might I also suggest a free and IMO better numpy package for python