Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Array Manipulation, Signal Processing

Subject: Array Manipulation, Signal Processing

From: John Lenehan

Date: 12 Jul, 2010 14:53:04

Message: 1 of 9

Hey Everybody,

I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.

-John

Subject: Array Manipulation, Signal Processing

From: Garrett

Date: 12 Jul, 2010 16:42:04

Message: 2 of 9

Hey John,

I had to make a code that did much the same thing for my data analysis. The way I went about it was to set a background (user defined is easiest) and then use the 'find' function to search for all points below that limit. I then replace all of these points with 0 or whatever else I wanted to use.

So if you have an array A and you want to make B where the values below limit L are set to zero then this is the code I would use.

below_limit = find(A <= L) %Finds all values below L
A(below_limit) = 0; %Sets all values in A below L to 0

-Garrett

Subject: Array Manipulation, Signal Processing

From: Wayne King

Date: 13 Jul, 2010 07:58:05

Message: 3 of 9

"John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1fa8g$dsv$1@fred.mathworks.com>...
> Hey Everybody,
>
> I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.
>
> -John

Hi John, you can also just use logical indexing.

Say you have a matrix A

A = randn(10,10);

and you want to set all values in A in the interval (-0.5,0.5) to zero

A(abs(A)<0.5) = 0;

However, if you are trying to filter audio data, I really don't think this is the way to filter your data. At any rate, that is another way to select entries from an array based on some criterion.

Wayne

Subject: Array Manipulation, Signal Processing

From: John Lenehan

Date: 13 Jul, 2010 15:31:04

Message: 4 of 9

"Wayne King" <wmkingty@gmail.com> wrote in message <i1h6ad$qqe$1@fred.mathworks.com>...
> "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1fa8g$dsv$1@fred.mathworks.com>...
> > Hey Everybody,
> >
> > I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.
> >
> > -John
>
> Hi John, you can also just use logical indexing.
>
> Say you have a matrix A
>
> A = randn(10,10);
>
> and you want to set all values in A in the interval (-0.5,0.5) to zero
>
> A(abs(A)<0.5) = 0;
>
> However, if you are trying to filter audio data, I really don't think this is the way to filter your data. At any rate, that is another way to select entries from an array based on some criterion.
>
> Wayne

Hey Wayne,
Thanks for the help. I actually tried using logical indexing and it did what I needed it to, but I also found that you're right about this not being the best way to filter audio data. I think I have to use the Signal Processing Toolbox and create a filter (which I have no idea how to use yet) and that should probably be a much more efficient way to filter my data.
-John

Subject: Array Manipulation, Signal Processing

From: John Lenehan

Date: 13 Jul, 2010 15:33:09

Message: 5 of 9

"Garrett " <bantong@onid.orst.edu> wrote in message <i1fgks$kfa$1@fred.mathworks.com>...
> Hey John,
>
> I had to make a code that did much the same thing for my data analysis. The way I went about it was to set a background (user defined is easiest) and then use the 'find' function to search for all points below that limit. I then replace all of these points with 0 or whatever else I wanted to use.
>
> So if you have an array A and you want to make B where the values below limit L are set to zero then this is the code I would use.
>
> below_limit = find(A <= L) %Finds all values below L
> A(below_limit) = 0; %Sets all values in A below L to 0
>
> -Garrett

Hey Garrett,
Thanks for the reply. I actually tried using logical indexing which worked pretty well too.

Subject: Array Manipulation, Signal Processing

From: Wayne King

Date: 13 Jul, 2010 15:58:04

Message: 6 of 9

"John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1i0ro$n8v$1@fred.mathworks.com>...
> "Wayne King" <wmkingty@gmail.com> wrote in message <i1h6ad$qqe$1@fred.mathworks.com>...
> > "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1fa8g$dsv$1@fred.mathworks.com>...
> > > Hey Everybody,
> > >
> > > I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.
> > >
> > > -John
> >
> > Hi John, you can also just use logical indexing.
> >
> > Say you have a matrix A
> >
> > A = randn(10,10);
> >
> > and you want to set all values in A in the interval (-0.5,0.5) to zero
> >
> > A(abs(A)<0.5) = 0;
> >
> > However, if you are trying to filter audio data, I really don't think this is the way to filter your data. At any rate, that is another way to select entries from an array based on some criterion.
> >
> > Wayne
>
> Hey Wayne,
> Thanks for the help. I actually tried using logical indexing and it did what I needed it to, but I also found that you're right about this not being the best way to filter audio data. I think I have to use the Signal Processing Toolbox and create a filter (which I have no idea how to use yet) and that should probably be a much more efficient way to filter my data.
> -John

I think you're right John. You can design a number of useful filters with the Signal Processing Toolbox. Write back if you get stuck with more details about your application and how your data are structured, e.g. do you have matrix of data, or is your audio signal one long vector (Nx1, or 1xN), etc. Make sure to give people adequate details so that they can help you like the sampling frequency.

Wayne

Subject: Array Manipulation, Signal Processing

From: John Lenehan

Date: 13 Jul, 2010 18:50:08

Message: 7 of 9

"Wayne King" <wmkingty@gmail.com> wrote in message <i1i2ec$5ff$1@fred.mathworks.com>...
> "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1i0ro$n8v$1@fred.mathworks.com>...
> > "Wayne King" <wmkingty@gmail.com> wrote in message <i1h6ad$qqe$1@fred.mathworks.com>...
> > > "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1fa8g$dsv$1@fred.mathworks.com>...
> > > > Hey Everybody,
> > > >
> > > > I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.
> > > >
> > > > -John
> > >
> > > Hi John, you can also just use logical indexing.
> > >
> > > Say you have a matrix A
> > >
> > > A = randn(10,10);
> > >
> > > and you want to set all values in A in the interval (-0.5,0.5) to zero
> > >
> > > A(abs(A)<0.5) = 0;
> > >
> > > However, if you are trying to filter audio data, I really don't think this is the way to filter your data. At any rate, that is another way to select entries from an array based on some criterion.
> > >
> > > Wayne
> >
> > Hey Wayne,
> > Thanks for the help. I actually tried using logical indexing and it did what I needed it to, but I also found that you're right about this not being the best way to filter audio data. I think I have to use the Signal Processing Toolbox and create a filter (which I have no idea how to use yet) and that should probably be a much more efficient way to filter my data.
> > -John
>
> I think you're right John. You can design a number of useful filters with the Signal Processing Toolbox. Write back if you get stuck with more details about your application and how your data are structured, e.g. do you have matrix of data, or is your audio signal one long vector (Nx1, or 1xN), etc. Make sure to give people adequate details so that they can help you like the sampling frequency.
>
> Wayne

I haven't had much experience using the Signal Processing Tool (none really) so I wouldn't say I'm stuck, I'm just a little bit confused on where to begin. My data is a WAV file, and its also stereo, so it is a matrix, but I only really need to use one of the columns so I have a single vector of usable data. The sampling frequency is 44,000 since it is a WAV file. My overall goal is to simply remove the static noise from the file. I have some lower sounds that I would like to keep so the filter has to be somewhat precise as to only remove certain sections. What I want to do seems easy and probably is, but the filter design seems like it can do so much that even something simple can be difficult for a beginner like me.

Subject: Array Manipulation, Signal Processing

From: Wayne King

Date: 15 Jul, 2010 15:22:06

Message: 8 of 9

"John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1ich0$j4g$1@fred.mathworks.com>...
> "Wayne King" <wmkingty@gmail.com> wrote in message <i1i2ec$5ff$1@fred.mathworks.com>...
> > "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1i0ro$n8v$1@fred.mathworks.com>...
> > > "Wayne King" <wmkingty@gmail.com> wrote in message <i1h6ad$qqe$1@fred.mathworks.com>...
> > > > "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1fa8g$dsv$1@fred.mathworks.com>...
> > > > > Hey Everybody,
> > > > >
> > > > > I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.
> > > > >
> > > > > -John
> > > >
> > > > Hi John, you can also just use logical indexing.
> > > >
> > > > Say you have a matrix A
> > > >
> > > > A = randn(10,10);
> > > >
> > > > and you want to set all values in A in the interval (-0.5,0.5) to zero
> > > >
> > > > A(abs(A)<0.5) = 0;
> > > >
> > > > However, if you are trying to filter audio data, I really don't think this is the way to filter your data. At any rate, that is another way to select entries from an array based on some criterion.
> > > >
> > > > Wayne
> > >
> > > Hey Wayne,
> > > Thanks for the help. I actually tried using logical indexing and it did what I needed it to, but I also found that you're right about this not being the best way to filter audio data. I think I have to use the Signal Processing Toolbox and create a filter (which I have no idea how to use yet) and that should probably be a much more efficient way to filter my data.
> > > -John
> >
> > I think you're right John. You can design a number of useful filters with the Signal Processing Toolbox. Write back if you get stuck with more details about your application and how your data are structured, e.g. do you have matrix of data, or is your audio signal one long vector (Nx1, or 1xN), etc. Make sure to give people adequate details so that they can help you like the sampling frequency.
> >
> > Wayne
>
> I haven't had much experience using the Signal Processing Tool (none really) so I wouldn't say I'm stuck, I'm just a little bit confused on where to begin. My data is a WAV file, and its also stereo, so it is a matrix, but I only really need to use one of the columns so I have a single vector of usable data. The sampling frequency is 44,000 since it is a WAV file. My overall goal is to simply remove the static noise from the file. I have some lower sounds that I would like to keep so the filter has to be somewhat precise as to only remove certain sections. What I want to do seems easy and probably is, but the filter design seems like it can do so much that even something simple can be difficult for a beginner like me.

Hi John, Here's an example of what you can do.

% assume that x contains your Nx2 matrix from wavread
y = x(:,1); % extract one of the columns
% now start to design your filter
% start by specifying your filter response
h = fdesign.lowpass('Fp,Fst,Ap,Ast',8e3,8.4e3,0.5,60,44.1e3);
% design your filter--Here an FIR equiripple filter, but not your only option
Hd = design(h,'equiripple');
% Look at your filter response
fvtool(Hd)
% apply your filter to your data
yfilt = filter(Hd,y);
% play the audio
soundsc(yfilt,44.1e3);

Because I do not know your signal (whether it's music or speech, etc.) I just took a shot in the dark and designed a lowpass filter that passed everything below 8,000 hertz. If your data is speech, the static will have energy at higher frequencies not present in the speech signal. If it is indeed speech, you can easily move the passband frequency (8,000 hertz) lower, probably down to around 4,000 hertz with no loss of intelligibility.

Hope that helps,
Wayne

Subject: Array Manipulation, Signal Processing

From: John Lenehan

Date: 15 Jul, 2010 19:16:04

Message: 9 of 9

"Wayne King" <wmkingty@gmail.com> wrote in message <i1n92u$em9$1@fred.mathworks.com>...
> "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1ich0$j4g$1@fred.mathworks.com>...
> > "Wayne King" <wmkingty@gmail.com> wrote in message <i1i2ec$5ff$1@fred.mathworks.com>...
> > > "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1i0ro$n8v$1@fred.mathworks.com>...
> > > > "Wayne King" <wmkingty@gmail.com> wrote in message <i1h6ad$qqe$1@fred.mathworks.com>...
> > > > > "John Lenehan" <lenehan2remove.this@tcnj.edu> wrote in message <i1fa8g$dsv$1@fred.mathworks.com>...
> > > > > > Hey Everybody,
> > > > > >
> > > > > > I'm very new to this so the answer may be very simple, but I am dealing with a very large array (several million data points) and I want to be able to create a new array where certain data points from the original would be removed (set to zero). I acquired this array from an audio file and I just want to eliminate any of the static (the lower amplitude data points). I have been trying to create a filter for this but since I am a beginner I am having difficulty with it. My overall goal is very simple, just set a point to zero if it is between say a and b and keep the other points. Whether I remove these points with a filter or through multiplying the data points within the a and b parameter by 0 doesn't matter, I just don't really know how to do it either way. :P Any help would be appreciated.
> > > > > >
> > > > > > -John
> > > > >
> > > > > Hi John, you can also just use logical indexing.
> > > > >
> > > > > Say you have a matrix A
> > > > >
> > > > > A = randn(10,10);
> > > > >
> > > > > and you want to set all values in A in the interval (-0.5,0.5) to zero
> > > > >
> > > > > A(abs(A)<0.5) = 0;
> > > > >
> > > > > However, if you are trying to filter audio data, I really don't think this is the way to filter your data. At any rate, that is another way to select entries from an array based on some criterion.
> > > > >
> > > > > Wayne
> > > >
> > > > Hey Wayne,
> > > > Thanks for the help. I actually tried using logical indexing and it did what I needed it to, but I also found that you're right about this not being the best way to filter audio data. I think I have to use the Signal Processing Toolbox and create a filter (which I have no idea how to use yet) and that should probably be a much more efficient way to filter my data.
> > > > -John
> > >
> > > I think you're right John. You can design a number of useful filters with the Signal Processing Toolbox. Write back if you get stuck with more details about your application and how your data are structured, e.g. do you have matrix of data, or is your audio signal one long vector (Nx1, or 1xN), etc. Make sure to give people adequate details so that they can help you like the sampling frequency.
> > >
> > > Wayne
> >
> > I haven't had much experience using the Signal Processing Tool (none really) so I wouldn't say I'm stuck, I'm just a little bit confused on where to begin. My data is a WAV file, and its also stereo, so it is a matrix, but I only really need to use one of the columns so I have a single vector of usable data. The sampling frequency is 44,000 since it is a WAV file. My overall goal is to simply remove the static noise from the file. I have some lower sounds that I would like to keep so the filter has to be somewhat precise as to only remove certain sections. What I want to do seems easy and probably is, but the filter design seems like it can do so much that even something simple can be difficult for a beginner like me.
>
> Hi John, Here's an example of what you can do.
>
> % assume that x contains your Nx2 matrix from wavread
> y = x(:,1); % extract one of the columns
> % now start to design your filter
> % start by specifying your filter response
> h = fdesign.lowpass('Fp,Fst,Ap,Ast',8e3,8.4e3,0.5,60,44.1e3);
> % design your filter--Here an FIR equiripple filter, but not your only option
> Hd = design(h,'equiripple');
> % Look at your filter response
> fvtool(Hd)
> % apply your filter to your data
> yfilt = filter(Hd,y);
> % play the audio
> soundsc(yfilt,44.1e3);
>
> Because I do not know your signal (whether it's music or speech, etc.) I just took a shot in the dark and designed a lowpass filter that passed everything below 8,000 hertz. If your data is speech, the static will have energy at higher frequencies not present in the speech signal. If it is indeed speech, you can easily move the passband frequency (8,000 hertz) lower, probably down to around 4,000 hertz with no loss of intelligibility.
>
> Hope that helps,
> Wayne

Wow, that does help a lot. You have been an amazing help. Thank you so much, you made my life a lot easier.
John

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us