MATLAB Answers

# Generate Real Signal With Random Phase and Specified Modulus at 10 Harmonics

29 views (last 30 days)
Jeff on 23 Aug 2011
Hi all,
I want to create a 1 sec duration real signal with 10 harmonics of a specified modulus and randomized phase. Here's what I've done:
phase = [2*rand(1)*pi - pi, ... , 2*rand(1)*pi - pi]; % ... is 8 repetitions
modulus = [1000, ... , 1000]; % ... is 8 repetitions
real = sqrt(modulus.^2./([1,1,1,1,1,1,1,1,1,1]+tan(phase).^2)); % substitute and calculate real part first
imag = sqrt(modulus.^2 - real.^2); % solve for imag part
sigfft = zeros(44100,1);
for i = 1:10
sigfft(1+200*i) = real(i) + j*imag(i); % j = sqrt(-1) previously assigned
sigfft(44100+1-200*i) = real(i) + j*imag(i);
end
sig = ifft(sigfft);
Thus, I assign a random phase in the interval [-pi,pi), and find the imaginary and real parts which correspond to the assigned random phase and the specified modulus of 1000. Then I code these into the 10 harmonic bins of 200Hz, 400Hz, ... , 2000Hz. However, when I execute sig = ifft(sigfft), Matlab returns a complex signal. I want a real signal, what's going on here?

#### 1 Comment

Jeff on 23 Aug 2011
I think I may have figured out the answer. I need to use the complex conjugate for the sigfft(44100+1-200*i) assignment.

Sign in to comment.

### Answers (1)

Jeff on 23 Aug 2011
The answer was to use the complex conjugate for the sigfft(44100+1-200*i) assignment. Now sig is a real signal.

#### 0 Comments

Sign in to comment.

Sign in to answer this question.