Home My Page Projects MPTK: The Matching Pursuit ToolKit
Summary Activity Forums Tracker Lists Docs News SCM Files

Forum: help

Monitor Forum | Start New Thread Start New Thread
MPTK anywave questions [ Reply ]
By: Roilhi Ibarra on 2016-03-18 20:26
[forum:150394]
I'm trying to implement waveforms in the anywave dictionary, I already have read the user and developer manuals to know how it blocks works. However, I'm having some trouble while creating the raw data in .bin format, first, I tried to create the binary of two sinusoids in MATLAB using this code:

% Generate two sinusoidal waves, each one with 128 samples, the frequency of
% each one is doubled, i.e. f2 = 2f1. Then, save these sinusoids in .bin
% format to be applied in MPTK as an anywave dictionary.
%
clear
close all
clc

N = 126; % Number of samples
fs = 8000; % Sampling frequency
f0 = 80; %
f1 = 160;
sig1 = sin((0:N+1)/fs*2*pi*f0);
sig2 = sin((0:N+1)/fs*2*pi*f1);

A = [sig1; sig2];
fid = fopen('twoSinusoids.bin','w');
fwrite(fid,A,'double');
fclose(fid);

I also created the SinusoidsTable.xml file for the anywavetable as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<table>
<libVersion>0.6.0</libVersion>
<param name="numChans" value="1"/>
<param name="filterLen" value="128"/>
<param name="numFilters" value="2"/>
<param name="data" value="/usr/local/mptk/reference/wavetable/TwoSinusoids.bin"/>
</table>

Then, I made the anywaveSinusoids.xml for the dictionary:
<?xml version="1.0" encoding="iso-8859-1" ?>
<dict>
<libVersion>0.5.4</libVersion>
<block>
<param name="type" value="anywave" />
<param name="tableFileName" value="/usr/local/mptk/reference/wavetable/SinusoidsTable.xml" />
<param name="windowShift" value="1" />
</block>
</dict>

Is this the right way to create the .bin file? I tried to recovered the sinusoids by applying MP with this dictionary and a delta function without success with the following code in MATLAB:

fs = 8000;
dict = dictread('/usr/local/mptk/reference/dictionary/anywaveSinusoids.xml');
sig = zeros(8000,1);
sig(4000) =1;

numIter = 1;

[book, residual , decay] = mpdecomp(sig,fs, dict, numIter);

sigrec = mprecons(book,dict);