2009-08-05 103 views
8

我正試圖將圖像轉換爲音頻信號,將其視爲譜圖as in Aphex Twin's song on Windowlicker。不幸的是,我無法獲得結果。逆向頻譜圖在MATLAB中的La Aphex Twin

這是我目前所面對的:

function signal = imagetosignal(path, format) 

    % Read in the image and make it symmetric. 
    image = imread(path, format); 
    image = [image; flipud(image)]; 
    [row, column] = size(image); 
    signal = []; 

    % Take the ifft of each column of pixels and piece together the real-valued results. 
    for i = 1 : column 

     spectrogramWindow = image(:, i); 
     R = abs(ifft(spectrogramWindow)); 
     % Take only the results for the positive frequencies. 
     signalWindow = R(1 : row/2.0); 
     signal = [signal; signalWindow]; 

    end 

end 

所以,我走我的圖像列逆傅立葉變換,然後把它們放在一起,形成一個信號。此外,此功能使用MATLAB的圖像處理工具箱來讀取圖像。我們的目標是有一些變化

spectrogram(imagetosignal('image', 'bmp')); 

導致東西看起來像原始圖像。我非常感謝任何幫助!我只是在學習信號處理,所以如果存在明顯的誤解,請不要感到驚訝。謝謝!


編輯:感謝戴夫!我得到它的工作!我結束了這一點:

function signal = imagetosignal(path, format) 

    % Read in the image and make it symmetric. 
    image = imread(path, format); 
    image = [image; flipud(image)]; 
    [row, column] = size(image); 
    signal = []; 

    % Take the ifft of each column of pixels and piece together the results. 
    for i = 1 : column 

     spectrogramWindow = image(:, i); 
     signalWindow = real(ifft(spectrogramWindow)); 
     signal = [signal; signalWindow]; 

    end 

end 

alt textalt text

+0

那麼,究竟是什麼問題呢? – gnovice 2009-08-05 03:24:37

+0

在回來的路上,圖像的上半部分被有效地丟失了,並且可怕的東西仍然會留下污跡。 – 2009-08-05 03:33:53

回答

6

還有一些小的誤解在這裏。

我會經歷的問題,以便發生的,而不是嚴重程度:

1)差一錯誤在spectrogramWindow(圖像)的計算

第一陣列條目應該是0Hz的分量,下一個是N Hz。數組的最後一個元素應該是-NHz的組成部分。但是,你已經計算出0Hz。

我不確定matlab語法,但是如果您翻轉圖像,然後在將其添加到原始圖像之前剝下頂部和底部線條,則應該進行設置。

或者,您可以考慮不將圖像附加到自身,並從圖像中提取spectrogramWindow後,應用一些函數使其成爲厄米特對稱。

2)取IFT的絕對值。沒必要。不要這樣做。

如果iFFT獲得正確的輸入,您從iFFT獲得的東西是完全真實的。

您正在看到複雜的值,因爲輸入不是實際的厄米特對稱,如上所述。永遠不要使用Abs()。如果您必須作弊,請提取Real部分,該部分不會從虛構部分摺疊成垃圾。

3)你扔掉信號的後半部分。

從iFFT獲得輸出後,代表您要求的信號。不要在頻率上考慮它,現在它是一個音頻時間序列。保持整個事情。

以下是我看到它:

spectrogramWindow = image(:, i); 
spectrogramWindow = [spectrogramWindow;reverse(spectrogramWindow(skip first and last))] 
signalWindow = ifft(spectrogramWindow); 
signal = [signal; signalWindow];