Ejemplo n.º 1
0
    dtype = torch.cuda.FloatTensor
else:
    dtype = torch.FloatTensor

test_type = "DCT"  #Imputation, CS, DCT, or Denoising

#x0 = np.zeros((LENGTH, 1))
#x0[:,0] = pywt.data.demo_signal(name='twochirp', n=LENGTH)
#x = inverse_utils.normalise(x0)

data_loc = "/home/sravula/AirQualityUCI/AirQuality.csv"  #Location of the air quality CSV data
sample = "O3-1"  #Choice of: O3-1, O3-2, NO2-1, NO2-2, CO-1, or CO-2

x0 = inverse_utils.get_air_data(loc=data_loc, data=sample, length=LENGTH)
x = np.zeros((LENGTH, 1))
x[:, 0] = inverse_utils.normalise(x0)

if test_type == "Imputation" or test_type == "CS" or test_type == "DCT":
    num_measurements = [10, 25, 50, 100, 200]
elif test_type == "Denoising":
    NUM_ITER = 300  #reduce iterations for denoising to prevent overfitting
    num_measurements = [LENGTH]
    std = 0.1  # the standard deviation of AWGN, if denoising
    noise = inverse_utils.get_noise(num_samples=LENGTH, nc=nc, std=std)
    x_orig = x.copy()
    x = x + noise
else:
    print(
        "UNSUPPORTED TEST TYPE. PLEASE CHOOSE: Imputation, CS, DCT, OR Denoising"
    )
    exit(0)
    dtype = torch.FloatTensor

#SIGNAL GENERATION
signal = s.gen_data(LENGTH, 0.5, 1)

target_range = np.array(range(
    400, 430))  #the range in the signal where the target appears
target_range = np.union1d(target_range, np.array(range(
    800, 830)))  #the range in the signal where the target appears
target_len = len(list(target_range))

signal[target_range] += 0.04  #add artificial target to the background signal

signal += np.random.normal(loc=0, scale=0.0075,
                           size=LENGTH)  #add background noise
signal = inverse_utils.normalise(signal)  #normalise signal to range [-1, 1]

x = np.zeros((LENGTH, 1))  #make a holder for the signal with proper shape
x[:, 0] = signal
"""
plt.figure()
plt.plot(range(LENGTH), signal)
plt.title("Original Signal")
plt.show()
"""

#IMPUTATION SETUP
missing1 = range(375, 425)  #Define the ranges of samples to drop
missing2 = range(810, 900)
missing3 = range(200, 230)
Ejemplo n.º 3
0
    noise_str = ""

save_loc = "audio_results/" + filename + "-" + test_type + noise_str + "/"

wave_rate, wave_len, wave_res, nc, x0 = inverse_utils.read_wav(
    "audio_data/" + filename + "_8192hz_2s.wav")
if wave_len != 16384 or nc > 1:
    print("ILL-FORMATTED WAV - TRY AGAIN")
    exit(0)

if test_type == 'Dropout' or test_type == 'CS':
    num_measurements = [100, 500, 1000, 2000, 4000]
else:
    num_measurements = [wave_len]

x = inverse_utils.normalise(x0,
                            wave_res * 8)  #normalise the wave data to [-1,1]

spectrum = np.fft.fft(x[:, 0], norm='ortho')
spectrum = abs(
    spectrum[0:round(len(spectrum) / 2)]
)  # Just first half of the spectrum, as the second is the negative copy

plt.figure()
plt.plot(spectrum, 'r')
plt.xlabel('Frequency (hz)')
plt.title('Original Waveform')
plt.xlim(0, wave_rate / 2)
plt.savefig(save_loc + filename + "_freq.jpg")
plt.close()

mse_list = np.zeros((len(num_measurements), 5))