editing signal in frequency domain and converting back to time domain the code is matlab / open source octave code

Greetings All

I would like to be able to edit different aspects of a signal (frequency, magnitude) in the frequency domain is this possible? I do know about fft and ifft which work great but I'm a little confused as how to edit the data in the frequency domain and properly get it back out in the time domain. I can get it out using ifft but when I try and edit the signal in the frequency domain and plot it in the time domain the values are very different.

Example: I create an array with the variables frequency, magnitude. created from the frequency domain I then want to change the magnitude of one of the frequencies and then convert the signal back to the time domain.

I was reading up on it and it had mentioned using phase some how phase = unwrap(angle(ya)); the problem is that the phase array is twice as long as the array for the frequency and magnitude.

code below:

%signal from frequency domain to time domain
clear all,clf
%addpath("/home/transform/"); %add path to location of functions
%create time domain
Fs = 1000;                    % Sampling frequency

%1a create signal
ya = .5*sin(2*pi*10*t) + 1*sin(2*pi*50*t);
ya_fft = fft(ya);

%Original data in frequency domain
yampa1=(yampa(:,1)/max(abs(yampa(:,1)))*1); %keep at 1, amplitude
levels adjustied
phase = unwrap(angle(ya_fft));

%Create array with Freq,magnitude
freq_mag_phase=[xfreqa yampa]; %can't add phase because length is to

%Edit data in frequency domain
freq_mag_phase(52,2)=[.1] ; %changes amplitude to .1
[xfreqb,yampb]=rtplotfft(ya,Fs); %not sure what to replace ya with?
yampb1=(yampb(:,1)/max(abs(yampb(:,1)))*1); %keep at 1, amplitude
levels adjustied

%3a frequency back to time domain

%1b time domain plot
title('1) Orginal Signal ')
xlabel('time domain')

%2b frequency domain plot.
title('2) Orginal signal in Frequency domain')
xlabel('Frequency (Hz)')

%3b rebuilt time domain from frequency (ifft)
title('3) rebuild time domain using ifft but it hasnt been edited')
xlabel('time domain ')

%4b rebuilt of signal in frequency (ifft)
title('4) rebuild in frequency domain not edited')
xlabel('Frequency (Hz)')


I've also included the function rtplotfft that is used to create the frequency and magnitude plot:

function [x,freq]=rtplotfft(vp_sig_orig,Fs)
       vp_sig_len=length(vp_sig_orig); %get sample rate from vp fs_rate
needs to be an even number?

       % Use next highest power of 2 greater than or equal to length(x) to
calculate FFT.
       nfft= 2^(nextpow2(length(vp_sig_orig)));

       % Take fft, padding with zeros so that length(fftx) is equal to nfft
       fftx = fft(vp_sig_orig,nfft);

       % Calculate the number of unique points
       NumUniquePts = ceil((nfft+1)/2);

       % FFT is symmetric, throw away second half
       fftx = fftx(1:NumUniquePts);

       % Take the magnitude of fft of x and scale the fft so that it is not
a function of the length of x
       mx = abs(fftx)/length(vp_sig_orig);

       % Take the square of the magnitude of fft of x.
       %mx = mx.^2; rem'd out to get amplitude to work

       % Since we dropped half the FFT, we multiply mx by 2 to keep the same
       % The DC component and Nyquist component, if it exists, are unique
and should not be multiplied by 2.
       if rem(nfft, 2) % odd nfft excludes Nyquist point
       mx(2:end) = mx(2:end)*2;
       mx(2:end -1) = mx(2:end -1)*2;


       % This is an evenly spaced frequency vector with NumUniquePts
       freq_vect = (0:NumUniquePts-1)*vp_sig_len/nfft;
  • $\begingroup$ You might want to post this at StackOverflow as well, for more answers (or even avp.stackexchange.com under signal-processing). $\endgroup$
    – Jodles
    Sep 1, 2011 at 23:01
  • 2
    $\begingroup$ This should be on dsp.stackexchange.com $\endgroup$
    – endolith
    Dec 2, 2011 at 21:10
  • $\begingroup$ How come this question has over 1k views?? $\endgroup$
    – user856
    Jul 28, 2013 at 2:50

1 Answer 1


This code can do this

%Voiceprint raise lower freq phase conjugate signal
clear all, clc,clf,tic
%% Sound /beep calculation complete
[ybeep, Fsbeep, nbitsbeep] = wavread(strcat(filerawbeeppathStr,filerawbeepStr));
%addpath(”/home/rat/Documents/octave/eq_research/main/transform/”); %add path to location of functions

%1a voice print import
[vp_sig_orig, fs_rate, nbitsraw] = wavread(strcat(filevoiceprepathStr,'voice8000fs.wav')); 


%2a create frequency domain
ya_fft = fft(vp_sig_orig);
vp_sig_phase_orig = unwrap(angle(ya_fft));

%get Magnitude
ya_fft_mag = abs(ya_fft);

%3a frequency back to time domain

%Back to Time domain

subplot(3,1,1), plot(vp_sig_orig),title('1 original time domain')
subplot(3,1,2), plot(ya_ifft),title('2 rebuild time domain')
subplot(3,1,3), plot(vp_sig_new),title('3 adjusted time')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .