FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > DSP

DSP comp.dsp newsgroup, mailing list

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2003, 08:32 PM
Roman Katzer
Guest
 
Posts: n/a
Default spectral smoothing in Matlab

I'm trying to write a function for spectral smoothing using the signal's
cepstrum in Matlab.

Here's what I have:

voice - a voice signal, 8192 samples long
win - a right window, 8192 samples long, with a variable cutoff:

1 |_____________
| \
| \
| \
0 |_________________\____________________
1 N 8192


N is set to 1024 for now.
I calculate the real cepstrum of the voice signal:

v_ceps = real(ifft(log(abs(fft(voice)))));

which I then multiply element-wise with my window:

v_ceps = v_ceps .* win;

transforming this back _should_ give me a smoothed spectrum.

smooth_spec = abs(fft(v_ceps));

The problem is, it doesn't work. The output isn't smooth and it doesn't
look similar to the original voice spectrum. Where did I go wrong?
I can't see any error in the algorithm nor the implementation.

Roman


PS: if you know any other good algortithms for spectral smoothing
(constant bandwidth preferred), go right ahead! :-)
Reply With Quote
  #2 (permalink)  
Old 08-07-2003, 12:36 AM
One Usenet Poster
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab

Roman Katzer wrote:
> I'm trying to write a function for spectral smoothing using the signal's
> cepstrum in Matlab.
>
> Here's what I have:
>
> voice - a voice signal, 8192 samples long
> win - a right window, 8192 samples long, with a variable cutoff:
>
> 1 |_____________
> | \
> | \
> | \
> 0 |_________________\____________________
> 1 N 8192
>
>
> N is set to 1024 for now.
> I calculate the real cepstrum of the voice signal:
>
> v_ceps = real(ifft(log(abs(fft(voice)))));
>
> which I then multiply element-wise with my window:
>
> v_ceps = v_ceps .* win;
>
> transforming this back _should_ give me a smoothed spectrum.
>
> smooth_spec = abs(fft(v_ceps));
>
> The problem is, it doesn't work. The output isn't smooth and it doesn't
> look similar to the original voice spectrum. Where did I go wrong?
> I can't see any error in the algorithm nor the implementation.
>
> Roman
>
>
> PS: if you know any other good algortithms for spectral smoothing
> (constant bandwidth preferred), go right ahead! :-)


Roman:

I think the convolution should be something like this:

V = fft(voice);

H = fft(win);

VH = ifft( V .* H );

Good luck,
OUP

Reply With Quote
  #3 (permalink)  
Old 08-07-2003, 06:00 AM
Fred Marshall
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab


"Roman Katzer" <[email protected]> wrote in message
news[email protected]..
> I'm trying to write a function for spectral smoothing using the signal's
> cepstrum in Matlab.
>
> Here's what I have:
>
> voice - a voice signal, 8192 samples long
> win - a right window, 8192 samples long, with a variable cutoff:
>
> 1 |_____________
> | \
> | \
> | \
> 0 |_________________\____________________
> 1 N 8192
>
>
> N is set to 1024 for now.
> I calculate the real cepstrum of the voice signal:
>
> v_ceps = real(ifft(log(abs(fft(voice)))));
>
> which I then multiply element-wise with my window:
>
> v_ceps = v_ceps .* win;
>
> transforming this back _should_ give me a smoothed spectrum.
>
> smooth_spec = abs(fft(v_ceps));
>
> The problem is, it doesn't work. The output isn't smooth and it doesn't
> look similar to the original voice spectrum. Where did I go wrong?
> I can't see any error in the algorithm nor the implementation.
>
> Roman


What is a "right window"?

Fred


Reply With Quote
  #4 (permalink)  
Old 08-07-2003, 08:32 AM
Roman Katzer
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab

Hi OUP,

On Wed, 06 Aug 2003 17:36:25 -0500, One Usenet Poster wrote:
>I think the convolution should be something like this:


.... but I'm not trying to convolute

Roman
Reply With Quote
  #5 (permalink)  
Old 08-07-2003, 07:35 PM
Mahesh Godavarti
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab

Roman Katzer <[email protected]> wrote in message news:<[email protected]>. ..
> I'm trying to write a function for spectral smoothing using the signal's
> cepstrum in Matlab.
>
> Here's what I have:
>
> voice - a voice signal, 8192 samples long
> win - a right window, 8192 samples long, with a variable cutoff:
>
> 1 |_____________
> | \
> | \
> | \
> 0 |_________________\____________________
> 1 N 8192
>
>
> N is set to 1024 for now.
> I calculate the real cepstrum of the voice signal:
>
> v_ceps = real(ifft(log(abs(fft(voice)))));
>
> which I then multiply element-wise with my window:
>
> v_ceps = v_ceps .* win;
>
> transforming this back _should_ give me a smoothed spectrum.
>
> smooth_spec = abs(fft(v_ceps));
>
> The problem is, it doesn't work. The output isn't smooth and it doesn't
> look similar to the original voice spectrum. Where did I go wrong?
> I can't see any error in the algorithm nor the implementation.
>
> Roman
>
>
> PS: if you know any other good algortithms for spectral smoothing
> (constant bandwidth preferred), go right ahead! :-)



The problem is that you are ignoring the negative frequencies in the
spectrum. Your window should be as follows

1 |_____________ ____________
| \ /
| \ /
| \ /
0 |_________________\____/_______________
1 N (8194-N) 8192

Then everything will work.

Do the following with your window.

Assuming your window is a row vector
win(8194-N:8192) = fliplr(win(2:N));

This way you will include the negative frequencies as well.

What you are doing NOW amounts to doing a single sideband filtering.
Reply With Quote
  #6 (permalink)  
Old 08-07-2003, 10:47 PM
Dirk Bell
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab


"Roman Katzer" <[email protected]> wrote in message
news[email protected]..
> I'm trying to write a function for spectral smoothing using the signal's
> cepstrum in Matlab.
>
> Here's what I have:
>
> voice - a voice signal, 8192 samples long
> win - a right window, 8192 samples long, with a variable cutoff:
>
> 1 |_____________
> | \
> | \
> | \
> 0 |_________________\____________________
> 1 N 8192
>
>
> N is set to 1024 for now.
> I calculate the real cepstrum of the voice signal:
>
> v_ceps = real(ifft(log(abs(fft(voice)))));
>
> which I then multiply element-wise with my window:
>
> v_ceps = v_ceps .* win;
>
> transforming this back _should_ give me a smoothed spectrum.
>
> smooth_spec = abs(fft(v_ceps));


This is not the inverse cepstrum.

Dirk

>
> The problem is, it doesn't work. The output isn't smooth and it doesn't
> look similar to the original voice spectrum. Where did I go wrong?
> I can't see any error in the algorithm nor the implementation.
>
> Roman
>
>
> PS: if you know any other good algortithms for spectral smoothing
> (constant bandwidth preferred), go right ahead! :-)



Reply With Quote
  #7 (permalink)  
Old 08-07-2003, 11:04 PM
Fred Marshall
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab


"Roman Katzer" <[email protected]> wrote in message
news:[email protected]..
> Hi Fred,
>
> On Wed, 6 Aug 2003 21:00:44 -0700, Fred Marshall wrote:
> >What is a "right window"?

>
> maybe my terminology is misleading. I mean the right half of a (hann)
> window, appended to a sequence of ones and followed by a sequence of
> zeros. It looks close to something like what I tried to show with ASCII
> characters below:
>
> >> win - a right window, 8192 samples long, with a variable cutoff:
> >>
> >> 1 |_____________
> >> | \
> >> | \
> >> | \
> >> 0 |_________________\____________________
> >> 1 N 8192

>
> Roman


The ifft will produce a complete sequence up to the equivalent sample time
epoch (equivalent to sampling frequency).

It repeats at T/2 (like fs/2). So, the filter need to be symmetric about
T/2 like this:

1 |___________ ___________|_
| \ / |
| \ / |
| \ / |
0 |______________ |__|_______________|_
1 N 8192-N 8192
<4096

T/2=4096



Reply With Quote
  #8 (permalink)  
Old 08-08-2003, 11:28 AM
Roman Katzer
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab

Thank you Mahesh,

I found a solution to my problem. I forgot two things:
a) I need a symmetric window
b) I need to exp(.) the real output of the second fft

Here's the program code:

function smspec = cepsmooth(sig, smoothing, falloff)
% CEPSMOOTH - return spectrally smoothed spectrum using cepstral
% smoothing
%
% usage:
% smspec = cepsmooth(sig, smoothing, falloff)
%
% sig - input time signal
% smoothing - 0..1 - smoothing strength, 0 strongest, 1 none
% falloff - 0..1 - smooth falloff portion, 0 none, 1 all

% created: 2003-08-05, Roman Katzer
% last modified: 2003-08-08

slen = length(sig);
tlen = round(slen*smoothing/2)*2;
hlen = round(tlen*falloff/2);
hwin = hann(2*hlen);
hl = hwin(1:hlen);
hr = hwin(hlen+1:end);

win = [ones(tlen/2-hlen, 1); hr; zeros(slen-tlen, 1); hl;
ones(tlen/2-hlen, 1)];

smspec = real(ifft(log(abs(fft(sig)))));
smspec = exp(real(fft(smspec .* win)));
smspec = 20*log10(abs(smspec(1:ceil(slen/2))));


Roman
Reply With Quote
  #9 (permalink)  
Old 08-08-2003, 07:05 PM
Mahesh Godavarti
Guest
 
Posts: n/a
Default Re: spectral smoothing in Matlab

Roman Katzer <[email protected]> wrote in message news:<[email protected]>. ..
> Thank you Mahesh,
>
> I found a solution to my problem. I forgot two things:
> a) I need a symmetric window
> b) I need to exp(.) the real output of the second fft
>


I just assumed that you were doing exp(.) naturally
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
convolution in matlab robert_dn DSP 4 02-03-2009 05:01 AM
Matlab (.m) to VHDL Vitaliy FPGA 3 01-02-2007 08:14 AM
How to convert Matlab to HDL? Davy FPGA 3 06-14-2005 05:50 AM
Matlab: What do I need for modeling? Kevin Neilson FPGA 0 09-02-2003 12:56 AM
spectral contrast enhancement Guil DSP 0 07-08-2003 03:20 PM


All times are GMT +1. The time now is 01:41 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved