DSPRelated.com
Forums

Signal reconstruction

Started by lamerooze April 3, 2008
Hi guys,

I am writing some code in MATLAB in which you can create a new sound
sample from two sound samples. The program is able to create a sample such
that the sample's envelope will be made up of varying envelope
contributions from the two samples (ie. the envelope will be made up of
60% of the envelope of Sample 1 and 40% of the envelope of sample 2).
Also, the sample's fine structure will be the same fine structure as
Sample 1.

However, I've run into a problem which I cannot find any resources on
Google or somebody who could help. Basically, my new sound sample only has
positive frequency components (this is due to the property of the Hilbert
transform which removes the negative frequency components). 

How do I restore a proper signal [sr(t)] with both positive and negative
frequency components? 

Given that an analytic signal is made up of the real signal and the
hilbert transform of the real signal, where

s(t) = sr(t) + i[sh(t)]

sr(t) = original signal
sh(t) = hilbert transform of the real signal

Below is the essence of my code:

h1a = hilbert(orig1); %orig1 is source file 1
h2a = hilbert(orig2); %orig2 is source file 2

% mag_e1 = magnitude of analytic signal 1

mag_e1a = abs(h1a);
mag_e2a = abs(h2a);

% The fine structure is denoted by arctan(s(t)/sh(t)).

% fs_e1a = fine structure of signal 1

fs_e1a = atan((imag(hilbert(orig1))) ./ orig1));

% changing envelope and fine structure contributions (env1 = %envelope
contribution from sample1, env2 = %envelope contribution from sample2),
and obtaining the new signal
e1_fs2 = (((env1/100) .* mag_e1a + (((env2)/100) .* mag_e2a)) .*
cos(fs_e1a));

% normalize and save
env1_fts2 = e1_fs2./max(abs(e1_fs2());
env2_fts1 = e2_fs1./max(abs(e2_fs1());

All and any help is appreciated. Thanks guys!


On Thu, 03 Apr 2008 17:33:44 -0500, "lamerooze" <lamerooze@gmail.com>
wrote:

>Hi guys, > >I am writing some code in MATLAB in which you can create a new sound >sample from two sound samples. The program is able to create a sample such >that the sample's envelope will be made up of varying envelope >contributions from the two samples (ie. the envelope will be made up of >60% of the envelope of Sample 1 and 40% of the envelope of sample 2). >Also, the sample's fine structure will be the same fine structure as >Sample 1.
Hi lamerooze, Perhaps the reason you're received no replies so far is because it's awfully hard to understand your questions. Just for clarity, you should use different terminology. We typically use the word "sample" to mean a single number in a sequence of numbers. So if Sequence_1 is: Sequence_1 = [0, 2.2, 33, 76.2, 23] then we would say that the 4th "sample" in Sequence_1 is equal to 76.2. As for the word "envelope", I think I know what you mean, but I cannot be sure. When you use the word "envelope" do you mean somethng like the low-frequency modulating signal used in an AM modulation system? As for your phrase "fine structure", I can only make wild guesses at what that phrase might mean. So lamerooze, you've inadvertently made it difficult for someone to help you.
>However, I've run into a problem which I cannot find any resources on >Google or somebody who could help. Basically, my new sound sample only has >positive frequency components (this is due to the property of the Hilbert >transform which removes the negative frequency components). > >How do I restore a proper signal [sr(t)] with both positive and negative >frequency components?
What, exactly, do you mean by "restore"?
>Given that an analytic signal is made up of the real signal and the >hilbert transform of the real signal, where > >s(t) = sr(t) + i[sh(t)] > >sr(t) = original signal >sh(t) = hilbert transform of the real signal
Perhaps I'm missing something here, but if you have an analytic sequence: s(n) = sr(n) + i[sh(n)] then sr(n), the real part of s(n), is your real sequence having both positive and negative frequency components.
>Below is the essence of my code:
lamerooze, what is the following code supposed to do?
>h1a = hilbert(orig1); %orig1 is source file 1 >h2a = hilbert(orig2); %orig2 is source file 2
Your variable names make it a real pain in the neck to understand your code. I respectfully suggest you change the above two lines to: Analytic_1 = hilbert(orig1); %orig1 is source file 1 Analytic_2 = hilbert(orig2); %orig2 is source file 2
>% mag_e1 = magnitude of analytic signal 1 > >mag_e1a = abs(h1a); >mag_e2a = abs(h2a);
I suggest you change the above two lines to: Mag_1 = abs(Analytic_1); Mag_2 = abs(Analytic_2);
>% The fine structure is denoted by arctan(s(t)/sh(t)).
In the above line you have an arctan of "real over imaginary". That's not right, is it?
> >% fs_e1a = fine structure of signal 1 > >fs_e1a = atan((imag(hilbert(orig1))) ./ orig1));
I suggest you change the above line to: FineStruct_1 = atan2(imag(Analytic_1), real(Analytic_1)); I must say, referring to the angle of a complex sequence (Analytic_1) as "fine structure" certainly seems puzzling to me.
>% changing envelope and fine structure contributions (env1 = %envelope >contribution from sample1, env2 = %envelope contribution from sample2), >and obtaining the new signal
What do the above words "changing envelope and fine structure contributions" mean?
>e1_fs2 = (((env1/100) .* mag_e1a + (((env2)/100) .* mag_e2a)) .* >cos(fs_e1a));
lamerooze, the above line of code is difficult (for me at least) to follow. If you can break that line of code up into 3-4 lines of code, using variable names that have some sort of meaning, then it would be easier for us to understand. Commenting each line with a clear, concise, comment would also help. OK I've gotta run. Good Luck, [-Rick-]
> >% normalize and save >env1_fts2 = e1_fs2./max(abs(e1_fs2()); >env2_fts1 = e2_fs1./max(abs(e2_fs1()); > >All and any help is appreciated. Thanks guys! >
Thanks for your help, Rick - after reading a couple of books and generally
busting my brains, I've managed to solve my problem.

You're right on the point about the clarity of the code etc - I should
clean it up!

Thanks!

Joseph

(p.s. that was an awesome book you wrote)

>On Thu, 03 Apr 2008 17:33:44 -0500, "lamerooze" <lamerooze@gmail.com> >wrote: > >>Hi guys, >> >>I am writing some code in MATLAB in which you can create a new sound >>sample from two sound samples. The program is able to create a sample
such
>>that the sample's envelope will be made up of varying envelope >>contributions from the two samples (ie. the envelope will be made up of >>60% of the envelope of Sample 1 and 40% of the envelope of sample 2). >>Also, the sample's fine structure will be the same fine structure as >>Sample 1. > >Hi lamerooze, > > Perhaps the reason you're received no replies so far is >because it's awfully hard to understand your questions. > >Just for clarity, you should use different terminology. >We typically use the word "sample" to mean a single number >in a sequence of numbers. So if Sequence_1 is: > > Sequence_1 = [0, 2.2, 33, 76.2, 23] > >then we would say that the 4th "sample" in Sequence_1 >is equal to 76.2. > >As for the word "envelope", I think I know what you mean, >but I cannot be sure. When you use the word "envelope" do >you mean somethng like the low-frequency modulating signal >used in an AM modulation system? > >As for your phrase "fine structure", I can only make >wild guesses at what that phrase might mean. So lamerooze, >you've inadvertently made it difficult for someone >to help you. > >>However, I've run into a problem which I cannot find any resources on >>Google or somebody who could help. Basically, my new sound sample only
has
>>positive frequency components (this is due to the property of the
Hilbert
>>transform which removes the negative frequency components). >> >>How do I restore a proper signal [sr(t)] with both positive and
negative
>>frequency components? > >What, exactly, do you mean by "restore"? > >>Given that an analytic signal is made up of the real signal and the >>hilbert transform of the real signal, where >> >>s(t) = sr(t) + i[sh(t)] >> >>sr(t) = original signal >>sh(t) = hilbert transform of the real signal > >Perhaps I'm missing something here, but if you >have an analytic sequence: > > s(n) = sr(n) + i[sh(n)] > >then sr(n), the real part of s(n), is your >real sequence having both positive and negative >frequency components. > >>Below is the essence of my code: > >lamerooze, what is the following code supposed to do? > >>h1a = hilbert(orig1); %orig1 is source file 1 >>h2a = hilbert(orig2); %orig2 is source file 2 > >Your variable names make it a real pain in the neck >to understand your code. I respectfully suggest you >change the above two lines to: > > Analytic_1 = hilbert(orig1); %orig1 is source file 1 > Analytic_2 = hilbert(orig2); %orig2 is source file 2 > >>% mag_e1 = magnitude of analytic signal 1 >> >>mag_e1a = abs(h1a); >>mag_e2a = abs(h2a); > >I suggest you change the above two lines to: > > Mag_1 = abs(Analytic_1); > Mag_2 = abs(Analytic_2); > >>% The fine structure is denoted by arctan(s(t)/sh(t)). > >In the above line you have an arctan of "real over imaginary". >That's not right, is it? >> >>% fs_e1a = fine structure of signal 1 >> >>fs_e1a = atan((imag(hilbert(orig1))) ./ orig1)); > >I suggest you change the above line to: > > FineStruct_1 = atan2(imag(Analytic_1), real(Analytic_1)); > >I must say, referring to the angle of a complex >sequence (Analytic_1) as "fine structure" certainly >seems puzzling to me. > >>% changing envelope and fine structure contributions (env1 = %envelope >>contribution from sample1, env2 = %envelope contribution from sample2), >>and obtaining the new signal > >What do the above words "changing envelope and fine >structure contributions" mean? > >>e1_fs2 = (((env1/100) .* mag_e1a + (((env2)/100) .* mag_e2a)) .* >>cos(fs_e1a)); > >lamerooze, the above line of code is difficult >(for me at least) to follow. If you can break that >line of code up into 3-4 lines of code, using >variable names that have some sort of meaning, then >it would be easier for us to understand. Commenting >each line with a clear, concise, comment would also help. > >OK I've gotta run. > >Good Luck, >[-Rick-] > >> >>% normalize and save >>env1_fts2 = e1_fs2./max(abs(e1_fs2()); >>env2_fts1 = e2_fs1./max(abs(e2_fs1()); >> >>All and any help is appreciated. Thanks guys! >> >