Rearrange signal spectrum after a shuffle












0















So i want to create a function/algorithm that takes a shuffled sprectrum and returns the spectrum original form.



The initial spectrum of a wav file is this:
original spectrum



After this i cut the spectrum into 4 parts and shuffle them, then creating a new wave form with those values and then the spectrum,it looks like this:
sprectum after shuffle



So based off the shuffle spectrum i need to get the original spectrum. Most likely i have to split the shuffle spectrum into ... lets say 4 parts and using brute force to check every combination.



But this is my question , when i compare 2 parts of the spectrum , how do i know which one should be first and which to be the second?



This is my Wave and Spectrum class :



class Wave:

def __init__(self,data,ts=None,framerate=None):

# data:wave data values
# ts:array of time where the signal was evaluated/sampled


self.data=data
self.framerate=framerate

if ts is None:
self.ts =np.arange(len(data))/self.framerate
else:
self.ts=ts

def __len__(self):
return len(self.data)


@property
def duration(self):

return len(self.data) / self.framerate

def make_spectrum(self):

n=len(self.data)
d=1/self.framerate

ampArray = np.fft.rfft(self.data)
freqArray = np.fft.rfftfreq(n, d)

return Spectrum(ampArray,freqArray,self.framerate)

def plot(self):

plt.plot(self.ts,self.data)

class Spectrum:

def __init__(self,ampArray,freqArray,framerate):

self.ampArray=ampArray
self.freqArray=freqArray
self.framerate=framerate


def plot(self):

plt.plot(self.freqArray,np.absolute(self.ampArray))

def make_wave(self,dataLength):

data=np.fft.irfft(self.ampArray,dataLength);
return Wave(data,framerate=self.framerate)

def shuffle(self):

listZip=list(zip(self.ampArray,self.freqArray)) # list of tuples ( amplitude value,frequency value)
listToShuffle=list(chunks(listZip,4)) # split the list in 4 list
random.shuffle(listToShuffle) # randomize the 4 lists
flat_list = [item for sublist in listToShuffle for item in sublist]
random_ampArray,random_freqArray= zip(*flat_list)
return Spectrum(random_ampArray,random_freqArray,self.framerate)









share|improve this question

























  • If you shuffle the spectrum while always using the same random sequence, you would know how to rearrange your spectrum after the shuffling operation. Would that be an option for you?

    – Michael C.
    Jan 2 at 22:43











  • Unfortunately it's not, it has to be a different sequence every time, but even if i was using the same sequence , i'm suppose to rearrange the spectrum without knowing anything about the initial spectrum , only that is shuffled.

    – Tenshi
    Jan 3 at 9:32











  • Well, I am afraid this is not possible. You can not revert some randomizing process without any additional information about this process. Maybe somehow encoding the randomization sequence within your spectrum would be an option but I am not sure how to achieve this.

    – Michael C.
    Jan 3 at 19:44
















0















So i want to create a function/algorithm that takes a shuffled sprectrum and returns the spectrum original form.



The initial spectrum of a wav file is this:
original spectrum



After this i cut the spectrum into 4 parts and shuffle them, then creating a new wave form with those values and then the spectrum,it looks like this:
sprectum after shuffle



So based off the shuffle spectrum i need to get the original spectrum. Most likely i have to split the shuffle spectrum into ... lets say 4 parts and using brute force to check every combination.



But this is my question , when i compare 2 parts of the spectrum , how do i know which one should be first and which to be the second?



This is my Wave and Spectrum class :



class Wave:

def __init__(self,data,ts=None,framerate=None):

# data:wave data values
# ts:array of time where the signal was evaluated/sampled


self.data=data
self.framerate=framerate

if ts is None:
self.ts =np.arange(len(data))/self.framerate
else:
self.ts=ts

def __len__(self):
return len(self.data)


@property
def duration(self):

return len(self.data) / self.framerate

def make_spectrum(self):

n=len(self.data)
d=1/self.framerate

ampArray = np.fft.rfft(self.data)
freqArray = np.fft.rfftfreq(n, d)

return Spectrum(ampArray,freqArray,self.framerate)

def plot(self):

plt.plot(self.ts,self.data)

class Spectrum:

def __init__(self,ampArray,freqArray,framerate):

self.ampArray=ampArray
self.freqArray=freqArray
self.framerate=framerate


def plot(self):

plt.plot(self.freqArray,np.absolute(self.ampArray))

def make_wave(self,dataLength):

data=np.fft.irfft(self.ampArray,dataLength);
return Wave(data,framerate=self.framerate)

def shuffle(self):

listZip=list(zip(self.ampArray,self.freqArray)) # list of tuples ( amplitude value,frequency value)
listToShuffle=list(chunks(listZip,4)) # split the list in 4 list
random.shuffle(listToShuffle) # randomize the 4 lists
flat_list = [item for sublist in listToShuffle for item in sublist]
random_ampArray,random_freqArray= zip(*flat_list)
return Spectrum(random_ampArray,random_freqArray,self.framerate)









share|improve this question

























  • If you shuffle the spectrum while always using the same random sequence, you would know how to rearrange your spectrum after the shuffling operation. Would that be an option for you?

    – Michael C.
    Jan 2 at 22:43











  • Unfortunately it's not, it has to be a different sequence every time, but even if i was using the same sequence , i'm suppose to rearrange the spectrum without knowing anything about the initial spectrum , only that is shuffled.

    – Tenshi
    Jan 3 at 9:32











  • Well, I am afraid this is not possible. You can not revert some randomizing process without any additional information about this process. Maybe somehow encoding the randomization sequence within your spectrum would be an option but I am not sure how to achieve this.

    – Michael C.
    Jan 3 at 19:44














0












0








0








So i want to create a function/algorithm that takes a shuffled sprectrum and returns the spectrum original form.



The initial spectrum of a wav file is this:
original spectrum



After this i cut the spectrum into 4 parts and shuffle them, then creating a new wave form with those values and then the spectrum,it looks like this:
sprectum after shuffle



So based off the shuffle spectrum i need to get the original spectrum. Most likely i have to split the shuffle spectrum into ... lets say 4 parts and using brute force to check every combination.



But this is my question , when i compare 2 parts of the spectrum , how do i know which one should be first and which to be the second?



This is my Wave and Spectrum class :



class Wave:

def __init__(self,data,ts=None,framerate=None):

# data:wave data values
# ts:array of time where the signal was evaluated/sampled


self.data=data
self.framerate=framerate

if ts is None:
self.ts =np.arange(len(data))/self.framerate
else:
self.ts=ts

def __len__(self):
return len(self.data)


@property
def duration(self):

return len(self.data) / self.framerate

def make_spectrum(self):

n=len(self.data)
d=1/self.framerate

ampArray = np.fft.rfft(self.data)
freqArray = np.fft.rfftfreq(n, d)

return Spectrum(ampArray,freqArray,self.framerate)

def plot(self):

plt.plot(self.ts,self.data)

class Spectrum:

def __init__(self,ampArray,freqArray,framerate):

self.ampArray=ampArray
self.freqArray=freqArray
self.framerate=framerate


def plot(self):

plt.plot(self.freqArray,np.absolute(self.ampArray))

def make_wave(self,dataLength):

data=np.fft.irfft(self.ampArray,dataLength);
return Wave(data,framerate=self.framerate)

def shuffle(self):

listZip=list(zip(self.ampArray,self.freqArray)) # list of tuples ( amplitude value,frequency value)
listToShuffle=list(chunks(listZip,4)) # split the list in 4 list
random.shuffle(listToShuffle) # randomize the 4 lists
flat_list = [item for sublist in listToShuffle for item in sublist]
random_ampArray,random_freqArray= zip(*flat_list)
return Spectrum(random_ampArray,random_freqArray,self.framerate)









share|improve this question
















So i want to create a function/algorithm that takes a shuffled sprectrum and returns the spectrum original form.



The initial spectrum of a wav file is this:
original spectrum



After this i cut the spectrum into 4 parts and shuffle them, then creating a new wave form with those values and then the spectrum,it looks like this:
sprectum after shuffle



So based off the shuffle spectrum i need to get the original spectrum. Most likely i have to split the shuffle spectrum into ... lets say 4 parts and using brute force to check every combination.



But this is my question , when i compare 2 parts of the spectrum , how do i know which one should be first and which to be the second?



This is my Wave and Spectrum class :



class Wave:

def __init__(self,data,ts=None,framerate=None):

# data:wave data values
# ts:array of time where the signal was evaluated/sampled


self.data=data
self.framerate=framerate

if ts is None:
self.ts =np.arange(len(data))/self.framerate
else:
self.ts=ts

def __len__(self):
return len(self.data)


@property
def duration(self):

return len(self.data) / self.framerate

def make_spectrum(self):

n=len(self.data)
d=1/self.framerate

ampArray = np.fft.rfft(self.data)
freqArray = np.fft.rfftfreq(n, d)

return Spectrum(ampArray,freqArray,self.framerate)

def plot(self):

plt.plot(self.ts,self.data)

class Spectrum:

def __init__(self,ampArray,freqArray,framerate):

self.ampArray=ampArray
self.freqArray=freqArray
self.framerate=framerate


def plot(self):

plt.plot(self.freqArray,np.absolute(self.ampArray))

def make_wave(self,dataLength):

data=np.fft.irfft(self.ampArray,dataLength);
return Wave(data,framerate=self.framerate)

def shuffle(self):

listZip=list(zip(self.ampArray,self.freqArray)) # list of tuples ( amplitude value,frequency value)
listToShuffle=list(chunks(listZip,4)) # split the list in 4 list
random.shuffle(listToShuffle) # randomize the 4 lists
flat_list = [item for sublist in listToShuffle for item in sublist]
random_ampArray,random_freqArray= zip(*flat_list)
return Spectrum(random_ampArray,random_freqArray,self.framerate)






signals signal-processing spectrum






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 16:47







Tenshi

















asked Jan 2 at 15:44









TenshiTenshi

64




64













  • If you shuffle the spectrum while always using the same random sequence, you would know how to rearrange your spectrum after the shuffling operation. Would that be an option for you?

    – Michael C.
    Jan 2 at 22:43











  • Unfortunately it's not, it has to be a different sequence every time, but even if i was using the same sequence , i'm suppose to rearrange the spectrum without knowing anything about the initial spectrum , only that is shuffled.

    – Tenshi
    Jan 3 at 9:32











  • Well, I am afraid this is not possible. You can not revert some randomizing process without any additional information about this process. Maybe somehow encoding the randomization sequence within your spectrum would be an option but I am not sure how to achieve this.

    – Michael C.
    Jan 3 at 19:44



















  • If you shuffle the spectrum while always using the same random sequence, you would know how to rearrange your spectrum after the shuffling operation. Would that be an option for you?

    – Michael C.
    Jan 2 at 22:43











  • Unfortunately it's not, it has to be a different sequence every time, but even if i was using the same sequence , i'm suppose to rearrange the spectrum without knowing anything about the initial spectrum , only that is shuffled.

    – Tenshi
    Jan 3 at 9:32











  • Well, I am afraid this is not possible. You can not revert some randomizing process without any additional information about this process. Maybe somehow encoding the randomization sequence within your spectrum would be an option but I am not sure how to achieve this.

    – Michael C.
    Jan 3 at 19:44

















If you shuffle the spectrum while always using the same random sequence, you would know how to rearrange your spectrum after the shuffling operation. Would that be an option for you?

– Michael C.
Jan 2 at 22:43





If you shuffle the spectrum while always using the same random sequence, you would know how to rearrange your spectrum after the shuffling operation. Would that be an option for you?

– Michael C.
Jan 2 at 22:43













Unfortunately it's not, it has to be a different sequence every time, but even if i was using the same sequence , i'm suppose to rearrange the spectrum without knowing anything about the initial spectrum , only that is shuffled.

– Tenshi
Jan 3 at 9:32





Unfortunately it's not, it has to be a different sequence every time, but even if i was using the same sequence , i'm suppose to rearrange the spectrum without knowing anything about the initial spectrum , only that is shuffled.

– Tenshi
Jan 3 at 9:32













Well, I am afraid this is not possible. You can not revert some randomizing process without any additional information about this process. Maybe somehow encoding the randomization sequence within your spectrum would be an option but I am not sure how to achieve this.

– Michael C.
Jan 3 at 19:44





Well, I am afraid this is not possible. You can not revert some randomizing process without any additional information about this process. Maybe somehow encoding the randomization sequence within your spectrum would be an option but I am not sure how to achieve this.

– Michael C.
Jan 3 at 19:44












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009200%2frearrange-signal-spectrum-after-a-shuffle%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009200%2frearrange-signal-spectrum-after-a-shuffle%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith