Reconstructing signal using the IFFT

21 views (last 30 days)
Opy
Opy on 24 Jan 2025
Commented: William Rose on 2 Feb 2025
Hello, I am using the FFt to convert a time series signal into images by reshaping the matrix (N*N). But i am having hard time to get the original signal back from the images. IS it because in fft i am considering only the magnitude of the signal not the phase of the signal ? Is there any way to solve this proble. May be using STFT ot any kind of other techniques

Answers (2)

Mathieu NOE
Mathieu NOE on 24 Jan 2025
hello
try this (it works for images but also for any 2D numerical array)
output = input with minimal error :
max(abs(outpict - inpict),[],'all') = 1.5543e-15
filename = 'image.png';
inpict = im2double(rgb2gray(imread(filename)));
% take the 2D fft
spec_img = fftshift(fft2(inpict));
% generated backward the output image by inverse fft
outpict = real(ifft2(ifftshift(spec_img)));
figure(1)
subplot(2,1,1),imshow(inpict)
subplot(2,1,2),imshow(outpict)
  13 Comments
Opy
Opy on 31 Jan 2025
@William Rose The main goal is to encode the 1D time series data into images, then evaluate the generation capability of GEN AI models to produce more synthetic images like those. After that, the images will be decoded back into 1D time series data.
This is a rough idea I got from an article, but after starting the work, I am finding it very difficult to decode the data from images. Before training the GEN AI models, I want to ensure that I can successfully decode the images to retrieve the synthetic time series data. Without this, my whole effort would be meaningless.
You might ask why I am converting the time series into images in the first place. The answer is quite simple— I wanted to explore the image generation capability of GEN AI models. Using time series data directly with GEN AI models has not shown promising results.
To the best of your knowledge, do you have any idea how I can encode and decode images in the way I have described? I found a paper that clearly states other techniques are not suitable for my problem, as most of them are not scale-invariant and not invertible.(link)
I only found a single paper where FFT and IFFT have been used, but the authors did not explain the method explicitly. (link)
William Rose
William Rose on 31 Jan 2025
This sounds like a good masters or PhD topic. Too much for a Matlab Answers discussion.
This also illustrates why it is good when asking a question on Matlab Answers to state what you're really after. You kind of did, but not much. I guess I should have pushed you for more info first, before spending time demonstrating stuff which, I now realize, was completely irrelevant.
"This is a rough idea I got from an article, but after starting the work, I am finding it very difficult..."
What article gave you a rough idea?
"I found a paper that clearly states other techniques are not suitable for my problem, as most of them are not scale-invariant and not invertible.(link)"
Is this preprint [Hellerman & Lessmann 2023] the article from which you got a rough idea? Hellerman & Lessmann (2023) describe the novel XIRP method for making an image from a 1D signal (eq. 8). They also describe other methods including GASF. Note that their methods generate an image with size SxS, where the original signal has S samples. That is very different from the stuff we did above, where we rearranged a signal of length S into an image of size sqrt(S) x sqrt(S), or 2*sqrt(S) x sqrt(S). Since invertibility is important to you, you need to udnerstand what the authors mean by "stochastic inversion", which they menton three times in their preprint. And you should implement the IM and IRC methods for inversion, which they discuss.
Hellermann & Lessmann 2023 goal, as stated in the ir introduction, seems very similar to yours. Therefore I reocmmnd that you understand their work fully. If it were me, I would reproduce many aspects of their preprint, to be sure you really understand. Note that XIRP only works on positive sequences. It follows from eq.8 that XIRP images are anti-symmetric.
"I only found a single paper where FFT and IFFT have been used, but the authors did not explain the method explicitly. (link)"
The Science Direct link to Hu et al., (2024) J Energy Storage, does not have the full paper. Have you read the full paper? They don't explain their methods in the full paper?
I have no expertise in this area. I reocmmend that you consult with someone who does.

Sign in to comment.


William Rose
William Rose on 25 Jan 2025
Moved: William Rose on 1 Feb 2025
fs=22050; % sampling rate (Hz)
t=0:1/fs:5;
y1=chirp(t,131,5,1048); % 3 octave chirp signal, 5 seconds long
% sound(y1,fs) % play it
M=round(sqrt(length(y1))); % find approximate square dimensions
N=floor(length(y1)/M);
img1=reshape(y1(1:M*N),M,N); % reshape to approximately square
imshow(img1)
img1fft = fftshift(fft2(img1));
% inverse fft
img2 = real(ifft2(ifftshift(img1fft)));
imshow(img2)
y2=reshape(img2,1,[]);
% sound(y2,fs) % play it
fprintf('max(abs(y2-y1))=%.2e.\n',max(abs(y2-y1(1:M*N))))
max(abs(y2-y1))=2.66e-15.
  4 Comments
Opy
Opy on 1 Feb 2025
@William Rose Thanks for the coversations. One of the problem that i will encounter that in the mentioned paper they have only 20 sample. But in my case there are 1000s of different points. Also the image is quite indistinguishable. I don't know how they have generated these images using GEN AI again. So i may need to rethink my problem again.
William Rose
William Rose on 2 Feb 2025
@Opy, I agree that the method of Hellerman & Lessman may not be practical for signals with thousands of points.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!