1

I designed a filter and applied it to a random noise signal using SPTool in MATLAB. My noise signal was x = (1/sqrt(2))*(randn(1024,1)+j*randn(1024,1))

Once I've applied my filter to this noise signal, how can I take that filtered signal and use it as a file source in GNU Radio Companion (which I will connect to QT GUI Frequency Sink)? I tried exporting the signal using SPTool but I'm unsure what file extension I can use for GNU Radio. Thanks in advance.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
BBEng
  • 155
  • 3
  • 17

2 Answers2

2

Use fwrite with the right precision parameter that gives you float 32 binaries.

Or just use the octave/Matlab scripts in GNU Radio that do exactly that: write raw binary data. For more info, see the GNU Radio FAQ entry on the file format. (On https://wiki.gnuradio.org )

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • Thanks, this pointed me in the right direction. But what do I put for the 'A' argument `fwrite(fileID,A,precision)`? I have all my specifications in SPTool, and I can export the filtered noise to my workspace but fwrite doesn't support struct classes. How do I get the information I created in SPTool to something readable by fwrite? Thanks. – BBEng Jun 05 '17 at 14:39
  • just use some form of iterable/vector. – Marcus Müller Jun 05 '17 at 14:47
  • I'm not sure I understand. I know the 'A' argument needs to be some form of vector, but what I don't know is how to take my filtered noise that I made with SPTool and put it in a format that fwrite can use (i.e. a vector). When I export the filtered noise, it is exported in my workspace as a struct, not a vector. I can't just put any random vector as 'A', then I wouldn't be writing anything useful to my file for GNU Radio. – BBEng Jun 05 '17 at 15:07
  • to extract from your struct, whatever it contains, a vector of samples. Docs of SPtool should say what the fields in that struct are, and which one is the sample vector. – Marcus Müller Jun 05 '17 at 15:08
  • Okay so I went into my struct and took the data part out of it. filteredNoise was my struct and data was what I wanted. fwrite(fileID,filteredNoise.data,float32) seemed to work for me. Thanks for the help. – BBEng Jun 05 '17 at 15:19
0

If you have a .mat file, another option is to use a Vector Source block putting in the Vector field:

loadmat('filename')['varname'].flatten()

For this to work you need to:

import numpy
from scipy.io import loadmat

Note this loads the whole file in memory (but you can specify which variables to load from the file if that's a problem). Also if the data is stored as float64 (as is the norm in Matlab) then I think there could be some rounding/truncation since GR Vector Source expects float32 (don't know enough about how SWIG handles that).

David
  • 644
  • 5
  • 4