Smoothing out values of an array

If I had an array of numbers such as [3, 5, 0, 8, 4, 2, 6], is there a way to “smooth out” the values so they’re closer to each other and display less variance?

I’ve looked into windowing the data using something called the Gaussian function for a 1-dimensional case, which is my array, but am having trouble implementing it. This thread seems to solve exactly what I need but I don’t understand how user naschilling (second post) came up with the Gaussian matrix values.

Context: I’m working on a music waveform generator (borrowing from SoundCloud’s design) that maps the amplitude of the song at time t to a corresponding bar height. Unfortunately there’s a lot of noise, and it looks particularly ugly when the program maps a tiny amplitude which results in a sudden decrease in height. You can see what it looks like here. I basically want to smooth out the bar heights so they aren’t so varied.

read more

Smoothing out values of an array

If I had an array of numbers such as [3, 5, 0, 8, 4, 2, 6], is there a way to “smooth out” the values so they’re closer to each other and display less variance?

I’ve looked into windowing the data using something called the Gaussian function for a 1-dimensional case, which is my array, but am having trouble implementing it. This thread seems to solve exactly what I need but I don’t understand how user naschilling (second post) came up with the Gaussian matrix values.

Context: I’m working on a music waveform generator (borrowing from SoundCloud’s design) that maps the amplitude of the song at time t to a corresponding bar height. Unfortunately there’s a lot of noise, and it looks particularly ugly when the program maps a tiny amplitude which results in a sudden decrease in height. You can see what it looks like here. I basically want to smooth out the bar heights so they aren’t so varied.

read more

How do I get multiple results from a file opened only once using proc_open?

I have a command run using exec() which returns a value from within a very large data file, but it has to run millions of times. In order to avoid having the file opened each time in a loop, I want to move to a proc_open-based solution, where the file pointer is created once for efficiency, but can’t work out how to do this.

Here is the exec-based version, which works but is slow, presumably because it has to open the file in each iteration:

foreach ($locations as $location) {
    $command = "gdallocationinfo -valonly -wgs84 datafile.img {$location['lon']} {$location['lat']}";
    echo exec ($command);
}

My attempt at a proc_open-based code is as follows:

$descriptorspec = array (
    0 => array ('pipe', 'r'),  // stdin - pipe that the child will read from
    1 => array ('pipe', 'w'),  // stdout - pipe that the child will write to
    // 2 => array ('file', '/tmp/errors.txt', 'a'), // stderr - file to write to
);

$command = "gdallocationinfo -valonly -wgs84 datafile.img";
$fp = proc_open ($command, $descriptorspec, $pipes);

foreach ($locations as $location) {
    fwrite ($pipes[0], "{$location['lon']} {$location['lat']}\n");
    fclose ($pipes[0]);
    echo stream_get_contents ($pipes[1]);
    fclose ($pipes[1]);
}

proc_close ($fp);

read more

How do I get multiple results from a file opened only once using proc_open?

I have a command run using exec() which returns a value from within a very large data file, but it has to run millions of times. In order to avoid having the file opened each time in a loop, I want to move to a proc_open-based solution, where the file pointer is created once for efficiency, but can’t work out how to do this.

Here is the exec-based version, which works but is slow, presumably because it has to open the file in each iteration:

foreach ($locations as $location) {
    $command = "gdallocationinfo -valonly -wgs84 datafile.img {$location['lon']} {$location['lat']}";
    echo exec ($command);
}

My attempt at a proc_open-based code is as follows:

$descriptorspec = array (
    0 => array ('pipe', 'r'),  // stdin - pipe that the child will read from
    1 => array ('pipe', 'w'),  // stdout - pipe that the child will write to
    // 2 => array ('file', '/tmp/errors.txt', 'a'), // stderr - file to write to
);

$command = "gdallocationinfo -valonly -wgs84 datafile.img";
$fp = proc_open ($command, $descriptorspec, $pipes);

foreach ($locations as $location) {
    fwrite ($pipes[0], "{$location['lon']} {$location['lat']}\n");
    fclose ($pipes[0]);
    echo stream_get_contents ($pipes[1]);
    fclose ($pipes[1]);
}

proc_close ($fp);

read more

RIAA chief says DMCA is “largely useless” to combat music piracy

(credit: Jeremy Yoder)

RIAA chief Cary Sherman.

Cary Sherman, the chairman and CEO of the Recording Industry Association of America, has some choice words about the current state of US copyright law. He says that under the Digital Millennium Copyright Act, rightsholders must play a game of whack-a-mole with Internet companies to get them to remove infringing content.

But that “never-ending game” has allowed piracy to run amok and has cheapened the legal demand for music. Sure, many Internet companies remove links under the DMCA’s “notice-and-takedown” regime. But the DMCA grants these companies, such as Google, a so-called “safe harbor”—meaning companies only have to remove infringing content upon notice from rightsholders.

read more